-
Notifications
You must be signed in to change notification settings - Fork 8.4k
drivers: sensor: icp201xx: fix channel check logic #88266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Update the channel validation logic to avoid using enum constants as boolean values. Signed-off-by: Benjamin Cabé <[email protected]>
| if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_PRESS && | ||
| chan != SENSOR_CHAN_ALTITUDE) { | ||
| return -ENOTSUP; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this, the chan is checked again, maybe the body should just be changed to
if (chan == SENSOR_CHAN_PRESS) {
icp201xx_mutex_lock(dev);
icp201xx_convert_pressure(val, data->raw_pressure);
icp201xx_mutex_unlock(dev);
} else if (chan == SENSOR_CHAN_AMBIENT_TEMP) {
icp201xx_mutex_lock(dev);
icp201xx_convert_temperature(val, data->raw_temperature);
icp201xx_mutex_unlock(dev);
#ifdef CONFIG_FPU
} else if (chan == SENSOR_CHAN_ALTITUDE) {
struct sensor_value pressure_val, temp_val;
float pressure, temperature, altitude;
icp201xx_mutex_lock(dev);
icp201xx_convert_pressure(&pressure_val, data->raw_pressure);
icp201xx_convert_temperature(&temp_val, data->raw_pressure);
pressure = pressure_val.val1 + ((float)pressure_val.val2 / 1000000);
temperature = temp_val.val1 + ((float)temp_val.val2 / 1000000);
altitude = convertToHeight(pressure, temperature);
sensor_value_from_float(val, altitude);
icp201xx_mutex_unlock(dev);
#endif
} else {
return -ENOTSUP;
}
return 0;
``|
I agree with @pdgendt that this might be a better fix but will let others chime in. The "hot" aspect of the fix is relative as it's a clang failure which doesn't directly impact PRs so given we know of a fix either way, I'm fine giving it another day or so to line up what folks see as the best solution |
|
@rbuisson-invn thoughts? |
To be honest I do not even understand the issue here, nor the fix :) /__w/zephyr/zephyr/drivers/sensor/tdk/icp201xx/icp201xx_drv.c:219:70: error: converting the enum constant to a boolean [-Werror,-Wint-in-bool-context] == operator should have precedence over || operator. |
Update the channel validation logic to properly check channel against SENSOR_CHAN_ALTITUDE. Signed-off-by: Benjamin Cabé <[email protected]>
|
@rbuisson-invn the latest push should make the fix more obvious - sorry for causing confusion by inverting the logic in my earlier fix :) |
Far more clearer now, thanks ! |
Update the channel validation logic to avoid using enum constants as boolean values.
Fixes clang warning "converting the enum constant to a boolean" observed in main https://github.com/zephyrproject-rtos/zephyr/actions/runs/14310267206/job/40103313166