All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Aaro Koskinen <aaro.koskinen@iki.fi>,
	Andreas Kemnade <andreas@kemnade.info>,
	Kevin Hilman <khilman@baylibre.com>,
	Roger Quadros <rogerq@kernel.org>,
	Tony Lindgren <tony@atomide.com>, Kai Svahn <kai.svahn@nokia.com>,
	syed khasim <x0khasim@ti.com>,
	linux-omap@vger.kernel.org, mfd@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] mfd: twl-core: Reset twl_priv using devm_add_action_or_reset()
Date: Thu, 19 Nov 2026 19:49:30 +0000	[thread overview]
Message-ID: <20261119194939.2436337-3-lee@kernel.org> (raw)
In-Reply-To: <20261119194939.2436337-1-lee@kernel.org>

Register a devres cleanup action immediately after allocating twl_priv
with devm_kzalloc() so that twl_priv is automatically reset to NULL just
before its underlying memory is released on probe failure or driver
unbind.  This removes the need to manually clear twl_priv in both
twl_remove() and the probe error unwind path.

Suggested-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: Andreas Kemnade <andreas@kemnade.info>
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v3: Previously sent standalone - now rebased onto patch 1

 drivers/mfd/twl-core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 7784e000b995..cef729109126 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -713,7 +713,6 @@ static void twl_remove(struct i2c_client *client)
 		twl->client = NULL;
 	}
 	twl_priv->ready = false;
-	twl_priv = NULL;
 }
 
 
@@ -735,6 +734,11 @@ static void twl_unregister_device(void *data)
 	platform_device_unregister(data);
 }
 
+static void twl_reset_priv(void *data)
+{
+	twl_priv = NULL;
+}
+
 /* NOTE: This driver only handles a single twl4030/tps659x0 chip */
 static int
 twl_probe(struct i2c_client *client)
@@ -788,6 +792,10 @@ twl_probe(struct i2c_client *client)
 		goto out;
 	}
 
+	status = devm_add_action_or_reset(&client->dev, twl_reset_priv, NULL);
+	if (status)
+		goto out;
+
 	if ((id->driver_data) & TWL6030_CLASS) {
 		twl_priv->twl_id = TWL6030_CLASS_ID;
 		twl_priv->twl_map = &twl6030_map[0];
@@ -909,9 +917,6 @@ twl_probe(struct i2c_client *client)
 	if (status < 0)
 		twl_remove(client);
 out:
-	if (status < 0)
-		twl_priv = NULL;
-
 	return status;
 }
 
-- 
2.56.1.750.gf70dc682cf-goog


      parent reply	other threads:[~2026-11-19 19:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:49 [PATCH v3 0/2] mfd: twl-core: Fix dangling twl_priv on teardown and probe failure Lee Jones
2026-11-19 19:49 ` [PATCH v3 1/2] mfd: twl-core: Clear twl_priv pointer " Lee Jones
2026-11-19 19:49 ` Lee Jones [this message]

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=20261119194939.2436337-3-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=aaro.koskinen@iki.fi \
    --cc=andreas@kemnade.info \
    --cc=kai.svahn@nokia.com \
    --cc=khilman@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --cc=rogerq@kernel.org \
    --cc=tony@atomide.com \
    --cc=x0khasim@ti.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.