[PATCH] firmware: arm_scmi: avoid returning uninialized data

From: Arnd Bergmann
Date: Fri Feb 16 2024 - 11:33:11 EST


From: Arnd Bergmann <arnd@xxxxxxxx>

Clang notices that there is a code path through
scmi_powercap_notify_supported() that returns an
undefined value:

drivers/firmware/arm_scmi/powercap.c:821:11: error: variable 'supported' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
821 | else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/firmware/arm_scmi/powercap.c:824:9: note: uninitialized use occurs here
824 | return supported;
| ^~~~~~~~~
drivers/firmware/arm_scmi/powercap.c:821:7: note: remove the 'if' if its condition is always true
821 | else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
822 | supported = dom_info->notify_powercap_measurement_change;
drivers/firmware/arm_scmi/powercap.c:811:16: note: initialize the variable 'supported' to silence this warning
811 | bool supported;
| ^

Return 'false' here, which is probably what was intended.

Fixes: c92a75fe84ce ("firmware: arm_scmi: Implement Powercap .is_notify_supported callback")
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
drivers/firmware/arm_scmi/powercap.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c
index aae91f47303e..8ee3be8776b0 100644
--- a/drivers/firmware/arm_scmi/powercap.c
+++ b/drivers/firmware/arm_scmi/powercap.c
@@ -820,6 +820,8 @@ scmi_powercap_notify_supported(const struct scmi_protocol_handle *ph,
supported = dom_info->notify_powercap_cap_change;
else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED)
supported = dom_info->notify_powercap_measurement_change;
+ else
+ supported = false;

return supported;
}
--
2.39.2