From: kr494167@gmail.com
To: andy@kernel.org, geert@linux-m68k.org
Cc: chris.packham@alliedtelesis.co.nz, linux-kernel@vger.kernel.org,
Surendra Singh Chouhan <kr494167@gmail.com>
Subject: [PATCH] auxdisplay: seg-led-gpio: fix work initialization race and convert to devm_add_action_or_reset()
Date: Fri, 24 Jul 2026 08:25:24 +0530 [thread overview]
Message-ID: <20260724025524.12726-1-kr494167@gmail.com> (raw)
From: Surendra Singh Chouhan <kr494167@gmail.com>
INIT_DELAYED_WORK(&priv->work, seg_led_update) was previously called inside
seg_led_linedisp_get_map_type(), which is invoked during/after
linedisp_register(). Initializing a delayed_work structure inside a map
query callback can re-initialize an active work item or race with
seg_led_linedisp_update().
In addition, seg_led_remove() called cancel_delayed_work_sync(&priv->work)
before linedisp_unregister(&priv->linedisp), allowing sysfs updates to
reschedule work after cancel_delayed_work_sync() completed.
Fix these by moving INIT_DELAYED_WORK() to probe() and using
devm_add_action_or_reset() for devm-managed cleanup. Registering
seg_led_unregister_linedisp after seg_led_cancel_work ensures proper LIFO
teardown order (sysfs interface unregistered first, followed by work
cancellation), allowing seg_led_remove() to be removed entirely.
Fixes: 899383f9ecf5 ("auxdisplay: Add 7-segment LED display driver")
Signed-off-by: Surendra Singh Chouhan <kr494167@gmail.com>
---
drivers/auxdisplay/seg-led-gpio.c | 35 +++++++++++++++++++++----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/drivers/auxdisplay/seg-led-gpio.c b/drivers/auxdisplay/seg-led-gpio.c
index bc463118fe51..c83246309701 100644
--- a/drivers/auxdisplay/seg-led-gpio.c
+++ b/drivers/auxdisplay/seg-led-gpio.c
@@ -40,9 +40,6 @@ static void seg_led_update(struct work_struct *work)
static int seg_led_linedisp_get_map_type(struct linedisp *linedisp)
{
- struct seg_led_priv *priv = container_of(linedisp, struct seg_led_priv, linedisp);
-
- INIT_DELAYED_WORK(&priv->work, seg_led_update);
return LINEDISP_MAP_SEG7;
}
@@ -58,10 +55,25 @@ static const struct linedisp_ops seg_led_linedisp_ops = {
.update = seg_led_linedisp_update,
};
+static void seg_led_cancel_work(void *data)
+{
+ struct seg_led_priv *priv = data;
+
+ cancel_delayed_work_sync(&priv->work);
+}
+
+static void seg_led_unregister_linedisp(void *data)
+{
+ struct seg_led_priv *priv = data;
+
+ linedisp_unregister(&priv->linedisp);
+}
+
static int seg_led_probe(struct platform_device *pdev)
{
struct seg_led_priv *priv;
struct device *dev = &pdev->dev;
+ int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -76,15 +88,17 @@ static int seg_led_probe(struct platform_device *pdev)
if (priv->segment_gpios->ndescs < 7 || priv->segment_gpios->ndescs > 8)
return -EINVAL;
- return linedisp_register(&priv->linedisp, dev, 1, &seg_led_linedisp_ops);
-}
+ INIT_DELAYED_WORK(&priv->work, seg_led_update);
-static void seg_led_remove(struct platform_device *pdev)
-{
- struct seg_led_priv *priv = platform_get_drvdata(pdev);
+ ret = devm_add_action_or_reset(dev, seg_led_cancel_work, priv);
+ if (ret)
+ return ret;
- cancel_delayed_work_sync(&priv->work);
- linedisp_unregister(&priv->linedisp);
+ ret = linedisp_register(&priv->linedisp, dev, 1, &seg_led_linedisp_ops);
+ if (ret)
+ return ret;
+
+ return devm_add_action_or_reset(dev, seg_led_unregister_linedisp, priv);
}
static const struct of_device_id seg_led_of_match[] = {
@@ -95,7 +109,6 @@ MODULE_DEVICE_TABLE(of, seg_led_of_match);
static struct platform_driver seg_led_driver = {
.probe = seg_led_probe,
- .remove = seg_led_remove,
.driver = {
.name = "seg-led-gpio",
.of_match_table = seg_led_of_match,
--
2.55.0
next reply other threads:[~2026-07-24 2:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 2:55 kr494167 [this message]
2026-07-24 3:26 ` Chris Packham
2026-08-02 9:28 ` Andy Shevchenko
2026-08-02 11:00 ` Surendra Singh
2026-08-17 15:44 ` Andy Shevchenko
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=20260724025524.12726-1-kr494167@gmail.com \
--to=kr494167@gmail.com \
--cc=andy@kernel.org \
--cc=chris.packham@alliedtelesis.co.nz \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.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®