Linux-i2c Archive mirror
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jean Delvare <jdelvare@suse.com>, Wolfram Sang <wsa@kernel.org>,
	 "linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>
Subject: Re: [PATCH v2] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
Date: Mon, 4 Mar 2024 01:30:15 +0100	[thread overview]
Message-ID: <d4it33rkc5rric6v5r4mwefcbvre2wf5iucbcqnkhzlhhj4lwf@3yx2ax7zlfgs> (raw)
In-Reply-To: <5c8f5f27-9d81-46dd-92d3-d13478b4448b@gmail.com>

On Sun, Mar 03, 2024 at 11:41:44AM +0100, Heiner Kallweit wrote:
> If registering the platform device fails, the lookup table is
> removed in the error path. On module removal we would try to
> remove the lookup table again. Fix this by leaving it to
> i801_del_mux() to clean up.
> 
> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
> Cc: stable@vger.kernel.org
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

You might want to Cc also Linus Walleij here as the patch is from
him.

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Just a little thought...

> ---
> v2:
> - cc stable
> - free memory allocated for the lookup table
> ---
>  drivers/i2c/busses/i2c-i801.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 291c609d1..9c624f31c 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -1428,7 +1428,6 @@ static void i801_add_mux(struct i801_priv *priv)
>  		lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip,
>  					       mux_config->gpios[i], "mux", 0);
>  	gpiod_add_lookup_table(lookup);
> -	priv->lookup = lookup;
>  
>  	/*
>  	 * Register the mux device, we use PLATFORM_DEVID_NONE here
> @@ -1442,7 +1441,10 @@ static void i801_add_mux(struct i801_priv *priv)
>  				sizeof(struct i2c_mux_gpio_platform_data));
>  	if (IS_ERR(priv->mux_pdev)) {
>  		gpiod_remove_lookup_table(lookup);
> +		devm_kfree(dev, lookup);

perhaps you also want to set priv->lookup to NULL. It's not
really needed, but it's just some paranoiac thinking.

Andi

>  		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
> +	} else {
> +		priv->lookup = lookup;
>  	}
>  }
>  
> -- 
> 2.44.0
> 

      reply	other threads:[~2024-03-04  0:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03 10:41 [PATCH v2] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table Heiner Kallweit
2024-03-04  0:30 ` Andi Shyti [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=d4it33rkc5rric6v5r4mwefcbvre2wf5iucbcqnkhzlhhj4lwf@3yx2ax7zlfgs \
    --to=andi.shyti@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).