mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] auxdisplay: seg-led-gpio: fix work initialization race and convert to devm_add_action_or_reset()
@ 2026-07-24  2:55 kr494167
  2026-07-24  3:26 ` Chris Packham
  2026-08-02  9:28 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: kr494167 @ 2026-07-24  2:55 UTC (permalink / raw)
  To: andy, geert; +Cc: chris.packham, linux-kernel, Surendra Singh Chouhan

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-17 15:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-24  2:55 [PATCH] auxdisplay: seg-led-gpio: fix work initialization race and convert to devm_add_action_or_reset() kr494167
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

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®