]> www.infradead.org Git - users/jedix/linux-maple.git/commit
hwmon: (adt7475) Fix memory leak in adt7475_fan_pwm_config()
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Thu, 26 Sep 2024 09:38:11 +0000 (11:38 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 7 Oct 2024 15:42:31 +0000 (08:42 -0700)
commit0fb09bf715736acfa7419d52f966aea2c0d57e7a
tree295410fdb7a5cbdfea507775c7e217edd2b072a3
parenta017616fafc6b2a6b3043bf46f6381ef2611c188
hwmon: (adt7475) Fix memory leak in adt7475_fan_pwm_config()

The device_for_each_child_node() loop requires calls to
fwnode_handle_put() upon early returns to decrement the refcount of
the child node and avoid leaking memory.

There are multiple early returns within that loop in
adt7475_fan_pwm_config(), but fwnode_handle_put() is never called.
Instead of adding the missing calls, the scoped version of the loop can
be used to simplify the code and avoid mistakes in the future if new
early returns are added.

This issue was recently introduced and it does not affect old kernels
that do not support the scoped variant.

Fixes: 777c97ff08d0 ("hwmon: (adt7475) Add support for configuring initial PWM state")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Message-ID: <20240926-hwmon_adt7475_memleak-v1-1-89b8ee07507a@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/adt7475.c