Clang warning in drivers/hwmon/scmi-hwmon.c
Hi Sundeep and others,
A group of us are trying to clean up all the warnings we see with an 'allyesconfig' arm64 build done with Clang and this one came up:
drivers/hwmon/scmi-hwmon.c:59:24: warning: address of array 'sensor->name' will always evaluate to 'true' [-Wpointer-bool-conversion]
if (sensor && sensor->name)
~~ ~~~~~~~~^~~~1 warning generated.
Would it be appropriate to just delete that check or does the check need to be adjusted in some way (such as checking for the first value 'sensor->name[0]')? Either option technically solves the warning but I don't have the hardware to check if this breaks the driver.
Thanks,
Nathan
Guenter Roeck
maintainerQuoted 6 lines · Nathan Chancellor
Hi Sundeep and others,
A group of us are trying to clean up all the warnings we see with an 'allyesconfig' arm64 build done with Clang and this one came up:
drivers/hwmon/scmi-hwmon.c:59:24: warning: address of array 'sensor->name' will always evaluate to 'true' [-Wpointer-bool-conversion]
Quoted 9 lines
if (sensor && sensor->name) ~~ ~~~~~~~~^~~~1 warning generated.
Would it be appropriate to just delete that check or does the check need to be adjusted in some way (such as checking for the first value 'sensor->name[0]')? Either option technically solves the warning but I don't have the hardware to check if this breaks the driver.
Presumably the check is supposed to validate the content of the data structure, so dropping the test doesn't seem to make sense. However, one could argue that, if the _content_ is to be checked, it should be checked earlier, before the data pointer is stored (ie in scmi_hwmon_probe()).
Given that, I'll be happy to accept a patch to just drop the check; it does not change the behavior of the driver, after all. If a real validation is desirable, it can be added (into the probe function) with a separate patch.
Thanks,
Guenter
Quoted 22 lines · Guenter Roeck
Quoted 6 lines · Nathan Chancellor
Hi Sundeep and others,
A group of us are trying to clean up all the warnings we see with an 'allyesconfig' arm64 build done with Clang and this one came up:
drivers/hwmon/scmi-hwmon.c:59:24: warning: address of array 'sensor->name' will always evaluate to 'true' [-Wpointer-bool-conversion]Quoted 9 lines
if (sensor && sensor->name) ~~ ~~~~~~~~^~~~1 warning generated.
Would it be appropriate to just delete that check or does the check need to be adjusted in some way (such as checking for the first value 'sensor->name[0]')? Either option technically solves the warning but I don't have the hardware to check if this breaks the driver.
Presumably the check is supposed to validate the content of the data structure, so dropping the test doesn't seem to make sense. However, one could argue that, if the _content_ is to be checked, it should be checked earlier, before the data pointer is stored (ie in
scmi_hwmon_probe()).
Quoted 7 lines
Given that, I'll be happy to accept a patch to just drop the check; it does not change the behavior of the driver, after all. If a real validation is desirable, it can be added (into the probe function) with a separate patch.
Thanks,
Guenter
Thank you for the quick response and clarification, patch sent.
Nathan