Skip to contentSkip to conversation

thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add()

PATCH In review Nathan Chancellor 2 participants 2 messages Sep 23, 2022 – Sep 27, 2022 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add()

Clang warns:

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:222:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]

          if (!int34x_thermal_zone->ops)
              ^~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:279:17: note: uninitialized use occurs here
          return ERR_PTR(ret);
                        ^~~
  drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:222:2: note: remove the 'if' if its condition is always false
          if (!int34x_thermal_zone->ops)
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:211:9: note: initialize the variable 'ret' to silence this warning
          int ret;
                ^
                  = 0

1 error generated.

If kmemdup() fails, -ENOMEM should be returned.

---
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +3 -1
index ea05be8c2834..228f44260b27 100644
@@ -219,8 +219,10 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 
 	int34x_thermal_zone->ops = kmemdup(&int340x_thermal_zone_ops,
 					   sizeof(int340x_thermal_zone_ops), GFP_KERNEL);
-	if (!int34x_thermal_zone->ops)
+	if (!int34x_thermal_zone->ops) {
+		ret = -ENOMEM;
 		goto err_ops_alloc;
+	}
 
 	if (get_temp)
 		int34x_thermal_zone->ops->get_temp = get_temp;

base-commit: 2b109cffe6836f0bb464639cdcc59fc537e3ba41

Signature · 1 line
2.37.3
#1 lore raw
Quoted 17 lines · Nathan Chancellor

Clang warns:

   drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:222:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
           if (!int34x_thermal_zone->ops)
               ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:279:17: note: uninitialized use occurs here
           return ERR_PTR(ret);
                         ^~~
   drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:222:2: note: remove the 'if' if its condition is always false
           if (!int34x_thermal_zone->ops)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c:211:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                 ^
                   = 0
   1 error generated.
Quoted 8 lines

If kmemdup() fails, -ENOMEM should be returned.

---

I've folded this patch with the changes introducing the issue

Thanks for the fix

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog