linux/drivers/leds
Luca Ceresoli 940b27161a Revert "leds: led-core: Fix refcount leak in of_led_get()"
This reverts commit da1afe8e60.

Commit 699a8c7c4b ("leds: Add of_led_get() and led_put()"), introduced in
5.5, added of_led_get() and led_put() but missed a put_device() in
led_put(), thus creating a leak in case the consumer device is removed.

Arguably device removal was not very popular, so this went apparently
unnoticed until 2022. In January 2023 two different patches got merged to
fix the same bug:

 - commit da1afe8e60 ("leds: led-core: Fix refcount leak in of_led_get()")
 - commit 445110941e ("leds: led-class: Add missing put_device() to led_put()")

They fix the bug in two different ways, which creates no patch conflicts,
and both were merged in v6.2. The result is that now there is one more
put_device() than get_device()s, instead of one less.

Arguably device removal is not very popular yet, so this apparently hasn't
been noticed as well up to now. But it blew up here while I'm working with
device tree overlay insertion and removal. The symptom is an apparently
unrelated list of oopses on device removal, with reasons:

  kernfs: can not remove 'uevent', no directory
  kernfs: can not remove 'brightness', no directory
  kernfs: can not remove 'max_brightness', no directory
  ...

Here sysfs fails removing attribute files, which is because the device name
changed and so the sysfs path. This is because the device name string got
corrupted, which is because it got freed too early and its memory reused.

Different symptoms could appear in different use cases.

Fix by removing one of the two fixes.

The choice was to remove commit da1afe8e60 because:

 * it is calling put_device() inside of_led_get() just after getting the
   device, thus it is basically not refcounting the LED device at all
   during its entire lifetime
 * it does not add a corresponding put_device() in led_get(), so it fixes
   only the OF case

The other fix (445110941e) is adding the put_device() in led_put() so it
covers the entire lifetime, and it works even in the non-DT case.

Fixes: da1afe8e60 ("leds: led-core: Fix refcount leak in of_led_get()")
Co-developed-by: Hervé Codina <herve.codina@bootlin.com>
Signed-off-by: Hervé Codina <herve.codina@bootlin.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://lore.kernel.org/r/20240625-led-class-device-leak-v2-1-75fdccf47421@bootlin.com
Signed-off-by: Lee Jones <lee@kernel.org>
2024-06-27 09:08:37 +01:00
..
blink leds: bcm63138: Add MODULE_DESCRIPTION() 2024-06-21 11:57:15 +01:00
flash leds: sy7802: Add support for Silergy SY7802 flash LED controller 2024-06-26 17:04:39 +01:00
rgb leds: rgb: leds-qcom-lpg: Add PPG check for setting/clearing PBS triggers 2024-06-26 16:56:08 +01:00
simple leds: simatic-ipc-leds: Add missing MODULE_DESCRIPTION() macros 2024-06-21 11:57:14 +01:00
trigger leds: trigger: input-events: Rewrite to fix a serious locking issue 2024-06-26 16:56:12 +01:00
Kconfig leds: leds-lp5569: Add support for Texas Instruments LP5569 2024-06-26 17:08:31 +01:00
led-class-flash.c led-class-flash: fix -Wrestrict warning 2021-09-27 16:09:42 +02:00
led-class-multicolor.c Merge branches 'ib-leds-mfd-6.11', 'ib-leds-platform-power-6.11' and 'ib-mfd-leds-platform-6.11' into ibs-for-leds-merged 2024-06-21 11:54:35 +01:00
led-class.c Revert "leds: led-core: Fix refcount leak in of_led_get()" 2024-06-27 09:08:37 +01:00
led-core.c leds: core: Omit set_brightness error message for a LED supporting hw trigger only 2024-06-26 16:55:44 +01:00
led-triggers.c leds: triggers: Flush pending brightness before activating trigger 2024-06-26 16:56:07 +01:00
leds-88pm860x.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-acer-a500.c leds: Add driver for Acer Iconia Tab A500 2020-09-26 21:56:42 +02:00
leds-adp5520.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-an30259a.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-apu.c leds: apu: Remove duplicate DMI lookup data 2024-04-12 09:47:15 +01:00
leds-ariel.c leds: Explicitly include correct DT includes 2023-07-28 10:02:32 +01:00
leds-aw200xx.c leds: aw200xx: Use devm API to cleanup module's resources 2024-04-11 17:34:57 +01:00
leds-aw2013.c leds: aw2013: Use devm API to cleanup module's resources 2024-04-11 17:34:52 +01:00
leds-bcm6328.c leds: bcm6328: Get rid of custom led_init_default_state_get() 2023-01-30 08:03:37 +00:00
leds-bcm6358.c leds: bcm6358: Get rid of custom led_init_default_state_get() 2023-01-30 08:03:38 +00:00
leds-bd2606mvv.c leds: Switch i2c drivers back to use .probe() 2023-05-25 12:16:22 +01:00
leds-bd2802.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-blinkm.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-cht-wcove.c leds: cht-wcove: Remove unneeded semicolon 2023-06-08 18:11:14 +01:00
leds-clevo-mail.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-cobalt-qube.c
leds-cobalt-raq.c
leds-cpcap.c leds: Explicitly include correct DT includes 2023-07-28 10:02:32 +01:00
leds-cr0014114.c leds: cr0014114: Annotate struct cr0014114 with __counted_by 2023-11-01 11:28:26 +00:00
leds-cros_ec.c leds: Add ChromeOS EC driver 2024-06-21 11:41:46 +01:00
leds-da903x.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-da9052.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-dac124s085.c spi: make remove callback a void function 2022-02-09 13:00:45 +00:00
leds-el15203000.c leds: el15203000: Annotate struct el15203000 with __counted_by 2023-11-01 11:28:28 +00:00
leds-expresswire.c leds: expresswire: Don't use "proxy" headers 2024-03-07 08:45:31 +00:00
leds-gpio-register.c leds: leds-gpio-register: Supply description for param 'id' 2021-05-28 11:38:54 +02:00
leds-gpio.c leds: gpio: Add kernel log if devm_fwnode_gpiod_get() fails 2023-12-13 15:45:55 +00:00
leds-hp6xx.c
leds-ip30.c leds: ip30: Convert to devm_platform_ioremap_resource() 2023-07-28 09:26:21 +01:00
leds-ipaq-micro.c
leds-is31fl32xx.c leds: Explicitly include correct DT includes 2023-07-28 10:02:32 +01:00
leds-is31fl319x.c leds: is31fl319x: Constify struct regmap_config 2024-06-21 11:57:08 +01:00
leds-lm355x.c leds: Switch i2c drivers back to use .probe() 2023-05-25 12:16:22 +01:00
leds-lm3530.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lm3532.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lm3533.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-lm3642.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lm3692x.c leds: lm392x: Convert to use maple tree register cache 2023-11-01 11:29:02 +00:00
leds-lm3697.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lm36274.c leds: lm36274: Add missed property.h 2021-05-30 23:03:48 +02:00
leds-locomo.c ARM: pxa: split up mach/hardware.h 2022-04-19 16:27:05 +02:00
leds-lp50xx.c leds: lp50xx: Remove unused field 'num_of_banked_leds' from 'struct lp50xx' 2024-05-02 18:10:56 +01:00
leds-lp55xx-common.c leds: leds-lp55xx: Support ENGINE program up to 128 bytes 2024-06-26 17:08:31 +01:00
leds-lp55xx-common.h leds: leds-lp55xx: Support ENGINE program up to 128 bytes 2024-06-26 17:08:31 +01:00
leds-lp3944.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lp3952.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lp5521.c leds: leds-lp55xx: Drop deprecated defines 2024-06-26 17:08:31 +01:00
leds-lp5523.c leds: leds-lp55xx: Drop deprecated defines 2024-06-26 17:08:31 +01:00
leds-lp5562.c leds: leds-lp55xx: Drop deprecated defines 2024-06-26 17:08:31 +01:00
leds-lp5569.c leds: leds-lp5569: Add support for Texas Instruments LP5569 2024-06-26 17:08:31 +01:00
leds-lp8501.c leds: leds-lp55xx: Drop deprecated defines 2024-06-26 17:08:31 +01:00
leds-lp8788.c
leds-lp8860.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-lt3593.c leds: lt3593: Put fwnode in any case during ->probe() 2021-08-03 23:49:31 +02:00
leds-max5970.c leds: max5970: Add missing headers 2023-12-21 14:42:59 +00:00
leds-max8997.c leds: max8997: Don't error if there is no pdata 2022-10-22 11:55:03 +02:00
leds-max77650.c leds: parse linux,default-trigger DT property in LED core 2020-09-26 21:56:43 +02:00
leds-mc13783.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-menf21bmc.c
leds-mlxcpld.c leds: leds-mlxcpld: Fix struct mlxcpld_led_priv member name 2024-03-07 08:48:16 +00:00
leds-mlxreg.c leds: mlxreg: Use devm_mutex_init() for mutex initialization 2024-04-11 17:35:18 +01:00
leds-mt6323.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-net48xx.c
leds-netxbig.c leds: Use DEVICE_ATTR_{RW, RO, WO} macros 2020-12-30 19:37:13 +01:00
leds-nic78bx.c leds: nic78bx: Use devm API to cleanup module's resources 2024-04-11 17:35:13 +01:00
leds-ns2.c leds: ns2: Slightly simplify a memory allocation 2023-07-28 11:58:04 +01:00
leds-ot200.c
leds-pca955x.c leds: pca955x: Cleanup OF/ID table terminators 2023-11-01 11:28:55 +00:00
leds-pca963x.c leds: pca963x: Add support for suspend and resume 2024-03-07 08:48:06 +00:00
leds-pca995x.c leds: pca995x: Fix MODULE_DEVICE_TABLE for OF 2023-08-15 18:30:07 +01:00
leds-pca9532.c leds: pca9532: Change default blinking frequency to 1Hz 2024-06-26 17:04:37 +01:00
leds-pm8058.c leds: Explicitly include correct DT includes 2023-07-28 10:02:32 +01:00
leds-powernv.c leds: powernv: Replace of_node_put to __free 2024-06-26 16:56:11 +01:00
leds-pwm.c leds: pwm: Disable PWM when going to suspend 2024-05-02 18:02:01 +01:00
leds-rb532.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-regulator.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-sc27xx-bltc.c leds: sc27xx: Move mutex_init() down 2023-11-01 11:29:15 +00:00
leds-spi-byte.c leds: spi-byte: Move OF ID table closer to their user 2024-06-26 16:56:07 +01:00
leds-ss4200.c leds: ss4200: Convert PCIBIOS_* return codes to errnos 2024-06-21 11:57:16 +01:00
leds-sun50i-a100.c leds: sun50i-a100: Use match_string() helper to simplify the code 2024-05-02 18:06:30 +01:00
leds-sunfire.c Normalise "name (ad@dr)" MODULE_AUTHORs to "name <ad@dr>" 2024-03-06 13:07:39 -08:00
leds-syscon.c leds: syscon: Support 'reg' in addition to 'offset' for register address 2023-12-13 11:28:26 +00:00
leds-tca6507.c leds: tca6507: Use devm_led_classdev_register() to simplify remove path 2023-12-13 11:28:41 +00:00
leds-ti-lmu-common.c leds: Explicitly include correct DT includes 2023-07-28 10:02:32 +01:00
leds-tlc591xx.c leds: tlc591xx: Replace of_node_put to __free 2024-06-26 16:56:09 +01:00
leds-tps6105x.c leds: tps6105x: add driver for MFD chip LED mode 2019-12-21 20:10:02 +01:00
leds-turris-omnia.c leds: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-06-21 11:57:11 +01:00
leds-wm831x-status.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-wm8350.c leds: Convert all platform drivers to return void 2023-11-01 11:28:35 +00:00
leds-wrap.c
leds.h leds: core: Unexport led_colors[] array 2024-06-21 11:41:39 +01:00
Makefile leds: leds-lp5569: Add support for Texas Instruments LP5569 2024-06-26 17:08:31 +01:00
TODO leds: TODO: Add documentation about possible subsystem improvements 2020-09-30 19:15:33 +02:00
uleds.c leds: uleds: Use module_misc_device macro to simplify the code 2023-08-18 11:42:54 +01:00