llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add()
@ 2022-09-23 15:20 Nathan Chancellor
  2022-09-27  9:36 ` Daniel Lezcano
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2022-09-23 15:20 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano
  Cc: Amit Kucheria, Zhang Rui, Srinivas Pandruvada, Nick Desaulniers,
	Tom Rix, linux-pm, linux-kernel, llvm, Nathan Chancellor,
	kernelci.org bot, Sudip Mukherjee (Codethink)

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.

Fixes: f6f6f9a01374 ("thermal/intel/int340x: Replace parameter to simplify")
Link: https://github.com/ClangBuiltLinux/linux/issues/1717
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Reported-by: "Sudip Mukherjee (Codethink)" <sudipm.mukherjee@gmail.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
index ea05be8c2834..228f44260b27 100644
--- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
+++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
@@ -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
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add()
  2022-09-23 15:20 [PATCH -next] thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add() Nathan Chancellor
@ 2022-09-27  9:36 ` Daniel Lezcano
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2022-09-27  9:36 UTC (permalink / raw)
  To: Nathan Chancellor, Rafael J. Wysocki
  Cc: Amit Kucheria, Zhang Rui, Srinivas Pandruvada, Nick Desaulniers,
	Tom Rix, linux-pm, linux-kernel, llvm, kernelci.org bot,
	Sudip Mukherjee (Codethink)

On 23/09/2022 17:20, Nathan Chancellor wrote:
> 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.
> 
> Fixes: f6f6f9a01374 ("thermal/intel/int340x: Replace parameter to simplify")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1717
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Reported-by: "Sudip Mukherjee (Codethink)" <sudipm.mukherjee@gmail.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---

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

Thanks for the fix


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-27  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 15:20 [PATCH -next] thermal/intel/int340x: Initialized ret in error path in int340x_thermal_zone_add() Nathan Chancellor
2022-09-27  9:36 ` Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).