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

From: Arunachalam

Date: Sat Jul 25 2026 - 13:52:11 EST


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