public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
@ 2024-03-04 20:31 Heiner Kallweit
  2024-03-04 23:04 ` Andi Shyti
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Heiner Kallweit @ 2024-03-04 20:31 UTC (permalink / raw)
  To: Andi Shyti, Jean Delvare, Wolfram Sang
  Cc: linux-i2c@vger.kernel.org, Linus Walleij

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 setting priv->lookup
only if registering the platform device was successful.
In addition free the memory allocated for the lookup table in
the error path.

Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
Cc: stable@vger.kernel.org
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v2:
- cc stable
- free memory allocated for the lookup table
v3:
- cc'ed Linus
---
 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);
 		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
+	} else {
+		priv->lookup = lookup;
 	}
 }
 
-- 
2.44.0


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

* Re: [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
  2024-03-04 20:31 [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table Heiner Kallweit
@ 2024-03-04 23:04 ` Andi Shyti
  2024-03-05  7:06   ` Heiner Kallweit
  2024-03-05  8:54 ` Linus Walleij
  2024-03-06 11:55 ` Andi Shyti
  2 siblings, 1 reply; 6+ messages in thread
From: Andi Shyti @ 2024-03-04 23:04 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Jean Delvare, Wolfram Sang, linux-i2c@vger.kernel.org,
	Linus Walleij

Hi Heiner,

On Mon, Mar 04, 2024 at 09:31:06PM +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 setting priv->lookup
> only if registering the platform device was successful.
> In addition free the memory allocated for the lookup table in
> the error path.
> 
> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
> Cc: stable@vger.kernel.org
> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - cc stable
> - free memory allocated for the lookup table
> v3:
> - cc'ed Linus

this patch is a resend...

> ---
>  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;

if I miss something obvious in my reviews, please let me know...
I spend most of my time reviewing patches and it happens quite
often :-)

Andi

>  	/*
>  	 * 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);
>  		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
> +	} else {
> +		priv->lookup = lookup;
>  	}
>  }
>  
> -- 
> 2.44.0
> 

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

* Re: [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
  2024-03-04 23:04 ` Andi Shyti
@ 2024-03-05  7:06   ` Heiner Kallweit
  0 siblings, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2024-03-05  7:06 UTC (permalink / raw)
  To: Andi Shyti
  Cc: Jean Delvare, Wolfram Sang, linux-i2c@vger.kernel.org,
	Linus Walleij

On 05.03.2024 00:04, Andi Shyti wrote:
> Hi Heiner,
> 
> On Mon, Mar 04, 2024 at 09:31:06PM +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 setting priv->lookup
>> only if registering the platform device was successful.
>> In addition free the memory allocated for the lookup table in
>> the error path.
>>
>> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
>> Cc: stable@vger.kernel.org
>> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> v2:
>> - cc stable
>> - free memory allocated for the lookup table
>> v3:
>> - cc'ed Linus
> 
> this patch is a resend...
> 
Right, it's effectively a resend.

>> ---
>>  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;
> 
> if I miss something obvious in my reviews, please let me know...
> I spend most of my time reviewing patches and it happens quite
> often :-)
> 
> Andi
> 
>>  	/*
>>  	 * 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);
>>  		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
>> +	} else {
>> +		priv->lookup = lookup;
>>  	}
>>  }
>>  
>> -- 
>> 2.44.0
>>


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

* Re: [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
  2024-03-04 20:31 [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table Heiner Kallweit
  2024-03-04 23:04 ` Andi Shyti
@ 2024-03-05  8:54 ` Linus Walleij
  2024-03-05  9:48   ` [SPAM] " Andi Shyti
  2024-03-06 11:55 ` Andi Shyti
  2 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2024-03-05  8:54 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Andi Shyti, Jean Delvare, Wolfram Sang, linux-i2c@vger.kernel.org

On Mon, Mar 4, 2024 at 9:31 PM Heiner Kallweit <hkallweit1@gmail.com> 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 setting priv->lookup
> only if registering the platform device was successful.
> In addition free the memory allocated for the lookup table in
> the error path.
>
> Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
> Cc: stable@vger.kernel.org
> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - cc stable
> - free memory allocated for the lookup table
> v3:
> - cc'ed Linus

My bug I guess, mea culpa.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [SPAM] Re: [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
  2024-03-05  8:54 ` Linus Walleij
@ 2024-03-05  9:48   ` Andi Shyti
  0 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-03-05  9:48 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Heiner Kallweit, Jean Delvare, Wolfram Sang,
	linux-i2c@vger.kernel.org

Hi Linus,

> > 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 setting priv->lookup
> > only if registering the platform device was successful.
> > In addition free the memory allocated for the lookup table in
> > the error path.
> >
> > Fixes: d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")
> > Cc: stable@vger.kernel.org
> > Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> > ---
> > v2:
> > - cc stable
> > - free memory allocated for the lookup table
> > v3:
> > - cc'ed Linus
> 
> My bug I guess, mea culpa.
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Thanks for your review! I have pushed this patch only in my
testing branch so that i can still add your r-b.

Andi

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

* Re: [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
  2024-03-04 20:31 [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table Heiner Kallweit
  2024-03-04 23:04 ` Andi Shyti
  2024-03-05  8:54 ` Linus Walleij
@ 2024-03-06 11:55 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-03-06 11:55 UTC (permalink / raw)
  To: Jean Delvare, Wolfram Sang, Heiner Kallweit; +Cc: linux-i2c, Linus Walleij

Hi

On Mon, 04 Mar 2024 21:31:06 +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 setting priv->lookup
> only if registering the platform device was successful.
> In addition free the memory allocated for the lookup table in
> the error path.
> 
> [...]

Applied to i2c/i2c-host-fixes on

git://git.kernel.org/pub/scm/linux/kernel/git/andi.shyti/linux.git

Thank you,
Andi

Patches applied
===============
[1/1] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
      commit: 7c16cfd69d519ba14c9e9d474facd22d075ad14d


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

end of thread, other threads:[~2024-03-06 12:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04 20:31 [PATCH v3] i2c: i801: Avoid potential double call to gpiod_remove_lookup_table Heiner Kallweit
2024-03-04 23:04 ` Andi Shyti
2024-03-05  7:06   ` Heiner Kallweit
2024-03-05  8:54 ` Linus Walleij
2024-03-05  9:48   ` [SPAM] " Andi Shyti
2024-03-06 11:55 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox