Skip to content

Conversation

@kartben
Copy link
Contributor

@kartben kartben commented Apr 7, 2025

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

Update the channel validation logic to avoid using enum constants as
boolean values.

Signed-off-by: Benjamin Cabé <[email protected]>
@kartben kartben added the Hotfix Fix for issues blocking development, i.e. upstream CI issues, tests failing in upstream CI , etc. label Apr 7, 2025
@kartben kartben marked this pull request as ready for review April 7, 2025 16:43
@github-actions github-actions bot added the area: Sensors Sensors label Apr 7, 2025
ubieda
ubieda previously approved these changes Apr 7, 2025
@kartben kartben requested a review from pdgendt April 7, 2025 17:05
pdgendt
pdgendt previously approved these changes Apr 7, 2025
Comment on lines 219 to 222
if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_PRESS &&
chan != SENSOR_CHAN_ALTITUDE) {
return -ENOTSUP;
}
Copy link
Contributor

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;
``

@kartben
Copy link
Contributor Author

kartben commented Apr 7, 2025

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

yperess
yperess previously approved these changes Apr 7, 2025
@kartben
Copy link
Contributor Author

kartben commented Apr 8, 2025

@rbuisson-invn thoughts?

@rbuisson-invn
Copy link
Contributor

rbuisson-invn commented Apr 8, 2025

@rbuisson-invn thoughts?

To be honest I do not even understand the issue here, nor the fix :)
I do not see any conversion from enum to boolean in the expression :

/__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]
if (!(chan == SENSOR_CHAN_AMBIENT_TEMP || chan == SENSOR_CHAN_PRESS ||
----------------------------------------------------------------------------------------------^

== operator should have precedence over || operator.
Sorry but, I would be glad if you could clarify this for me.

Update the channel validation logic to properly check channel against
SENSOR_CHAN_ALTITUDE.

Signed-off-by: Benjamin Cabé <[email protected]>
@kartben kartben dismissed stale reviews from yperess, pdgendt, and ubieda via 1677413 April 8, 2025 08:11
@kartben
Copy link
Contributor Author

kartben commented Apr 8, 2025

@rbuisson-invn the latest push should make the fix more obvious - sorry for causing confusion by inverting the logic in my earlier fix :)

@kartben kartben requested review from pdgendt, ubieda and yperess April 8, 2025 08:14
@rbuisson-invn
Copy link
Contributor

@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 !

@kartben kartben merged commit 39a65c0 into zephyrproject-rtos:main Apr 8, 2025
24 checks passed
@kartben kartben deleted the clang_fix branch October 22, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Sensors Sensors Hotfix Fix for issues blocking development, i.e. upstream CI issues, tests failing in upstream CI , etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants