[PATCH 1/2] leds: menf21bmc: Use brightness_set_blocking instead of brightness_set

Arunachalam <[email protected]> Sat, 25 Jul 2026 23:21:45 +0530
Newsgroups org.kernel.vger.linux-leds,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
menf21bmc_led_set() takes a mutex and performs an I2C transaction, both
of which can sleep. It was assigned to the non-blocking brightness_set
callback, which the LED core may invoke from atomic context (e.g. via
the timer or heartbeat triggers), risking a scheduling-while-atomic bug.

Switch to brightness_set_blocking, which the LED core dispatches from
a workqueue in safe, sleepable context. This also allows propagating
I2C failures via the function's return value instead of silently
discarding them.

Signed-off-by: Arunachalam <[email protected]>
---
 drivers/leds/leds-menf21bmc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-menf21bmc.c b/drivers/leds/leds-menf21bmc.c
index a7e4db487..6b09e433a 100644
--- a/drivers/leds/leds-menf21bmc.c
+++ b/drivers/leds/leds-menf21bmc.c
@@ -49,7 +49,7 @@ static struct menf21bmc_led leds[] = {
 
 static DEFINE_MUTEX(led_lock);
 
-static void
+static int
 menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 {
 	int led_val;
@@ -67,10 +67,11 @@ menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 	else
 		led_val |= led->led_bit;
 
-	i2c_smbus_write_byte_data(led->i2c_client,
+	led_val = i2c_smbus_write_byte_data(led->i2c_client,
 				  BMC_CMD_LED_GET_SET, led_val);
 err_out:
 	mutex_unlock(&led_lock);
+	return led_val;
 }
 
 static int menf21bmc_led_probe(struct platform_device *pdev)
@@ -81,7 +82,7 @@ static int menf21bmc_led_probe(struct platform_device *pdev)
 
 	for (i = 0; i < ARRAY_SIZE(leds); i++) {
 		leds[i].cdev.name = leds[i].name;
-		leds[i].cdev.brightness_set = menf21bmc_led_set;
+		leds[i].cdev.brightness_set_blocking = menf21bmc_led_set;
 		leds[i].i2c_client = i2c_client;
 		ret = devm_led_classdev_register(&pdev->dev, &leds[i].cdev);
 		if (ret < 0)
-- 
2.39.5