channel type: Improve code readability for channel type#1404
channel type: Improve code readability for channel type#1404RubenNatanael wants to merge 1 commit intomainfrom
Conversation
Currently, the channel type is stored as enum iio_chan_type, even when it represents a hwmon_chan_type. By changing this field to int, we improve code readability and flexibility. This change also enables the implementation of validation checks, such as in hwmon_channel_get_type(), which now issues a warning if a hwmon function is incorrectly called for a non-hwmon channel and vice versa. Signed-off-by: Ruben Mujdei <ruben.mujdei@analog.com>
a1bcdd7 to
c1611e0
Compare
nunojsa
left a comment
There was a problem hiding this comment.
I'm not sure I agree with this change, It seems like unneeded churn to me. It is fair to assume that users will call hwmon_channel_get_type() on an hwmon device. If not, they need to fix their app anyways! So I would either:
- Leave as-is;
- Or be strict about it. Meaning, return an error in case we try to get an IIO channel from an hwmon device or vice-versa.
Honestly I would probably go with 1. For 2, we might need to change the API a bit...
Having said the above, we should have introduced different types for hwmon devices. Yeah, it would have been more complicated but we would not have these discussions.
| if (!iio_device_is_hwmon(iio_channel_get_device(chn))) { | ||
| chn_warn(chn, "hwmon_channel_get_type() called on non-hwmon channel\n"); | ||
| } | ||
| return (enum hwmon_chan_type)chn->type; |
There was a problem hiding this comment.
well, we give a warning but prevent nothing... IOW, we continue to do as before.
There was a problem hiding this comment.
I agree. Like I said in the issue, this doesn't stop the error from happening, it's just a 'hint' for developers who assume that the member enum iio_chan_type type in struct iio_channel can't be an hwmon_chan_type. That said, I'm not entirely sure about this change either, so I'd like to hear other opinions.
Ack and agree - it's not only unneeded - but also will break things. We want to have people treat |
|
Hi all and thanks for all responses. I didn't expect the #1401 will lead to so quick reactions. It doesn't happen so often in Open Source community. I believe we all agree that actually there is nothing wrong in the current implementation, if you use it correctly it works as expected. The only problem is about confusion faced to developers who are based on reading the code and not documentation. And the fact is that the code is the best documentation. Unfortunately, if you see The fact is that in existing implementation developer is confused when seeing Anyway, whatever decision will be made, I am glad of having such quick responds, thank you. |
PR Description
Currently, the channel type is stored as enum iio_chan_type, even when it represents a hwmon_chan_type. By changing this field to int, we improve code readability and flexibility. This change also enables the implementation of validation checks, such as in hwmon_channel_get_type(), which now issues a warning if a hwmon function is incorrectly called for a non-hwmon channel and vice versa.
PR Type
PR Checklist