From: Andreas Kemnade <andreas@kemnade.info>
To: Lee Jones <lee@kernel.org>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Myeonghun Pak <mhun512@gmail.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: Re: [PATCH] mfd: twl-core: Reset twl_priv using devm_add_action_or_reset()
Date: Sat, 7 Nov 2026 12:05:59 +0100 [thread overview]
Message-ID: <20261107120559.50c33c09@kemnade.info> (raw)
In-Reply-To: <20261105110332.1874728-1-lee@kernel.org>
On Thu, 5 Nov 2026 11:03:23 +0000
Lee Jones <lee@kernel.org> wrote:
> 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>
> Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Andreas Kemnade <andreas@kemnade.info>
> ---
> drivers/mfd/twl-core.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
> index 21fc0acb827b..6077a87282f5 100644
> --- a/drivers/mfd/twl-core.c
> +++ b/drivers/mfd/twl-core.c
> @@ -711,7 +711,6 @@ static void twl_remove(struct i2c_client *client)
> twl->client = NULL;
> }
> twl_priv->ready = false;
> - twl_priv = NULL;
> }
>
>
> @@ -728,6 +727,11 @@ static const struct mfd_cell twl6032_cells[] = {
> { .name = "twl6032-clk" },
> };
>
> +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)
> @@ -776,6 +780,10 @@ twl_probe(struct i2c_client *client)
> goto free;
> }
>
> + status = devm_add_action_or_reset(&client->dev, twl_reset_priv, NULL);
> + if (status)
> + goto free;
> +
> if ((id->driver_data) & TWL6030_CLASS) {
> twl_priv->twl_id = TWL6030_CLASS_ID;
> twl_priv->twl_map = &twl6030_map[0];
> @@ -906,10 +914,8 @@ twl_probe(struct i2c_client *client)
> if (status < 0)
> twl_remove(client);
> free:
> - if (status < 0) {
> + if (status < 0)
> platform_device_unregister(pdev);
> - twl_priv = NULL;
> - }
>
> return status;
> }
prev parent reply other threads:[~2026-11-07 11:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 11:03 Lee Jones
2026-11-07 11:05 ` Andreas Kemnade [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=20261107120559.50c33c09@kemnade.info \
--to=andreas@kemnade.info \
--cc=aaro.koskinen@iki.fi \
--cc=kai.svahn@nokia.com \
--cc=khilman@baylibre.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=mhun512@gmail.com \
--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 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®