mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] leds: menf21bmc: Use brightness_set_blocking instead of brightness_set
       [not found] <20260725081938.422B11F000E9@smtp.kernel.org>
@ 2026-07-25 17:51 ` Arunachalam
  0 siblings, 0 replies; only message in thread
From: Arunachalam @ 2026-07-25 17:51 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Andreas Werner, linux-leds, linux-kernel, Arunachalam

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 <arun07172003@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-25 17:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260725081938.422B11F000E9@smtp.kernel.org>
2026-07-25 17:51 ` [PATCH 1/2] leds: menf21bmc: Use brightness_set_blocking instead of brightness_set Arunachalam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®