From: Arunachalam <arun07172003@gmail.com>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Andreas Werner <andreas.werner@men.de>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
Arunachalam <arun07172003@gmail.com>
Subject: [PATCH 1/2] leds: menf21bmc: Use brightness_set_blocking instead of brightness_set
Date: Sat, 25 Jul 2026 23:21:45 +0530 [thread overview]
Message-ID: <20260725175145.31984-1-arun07172003@gmail.com> (raw)
In-Reply-To: <20260725081938.422B11F000E9@smtp.kernel.org>
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
parent reply other threads:[~2026-07-25 17:52 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20260725081938.422B11F000E9@smtp.kernel.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260725175145.31984-1-arun07172003@gmail.com \
--to=arun07172003@gmail.com \
--cc=andreas.werner@men.de \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®