Skip to contentSkip to conversation

i2c: i801: Avoid potential double call to gpiod_remove_lookup_table

PATCH Applied Heiner Kallweit 3 participants 6 messages Mar 4, 2024 – Mar 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c: i801: Avoid potential double call to gpiod_remove_lookup_table

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")

---
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(-)
drivers/i2c/busses/i2c-i801.c +3 -1
index 291c609d1..9c624f31c 100644
@@ -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;
 	}
 }
 
Signature · 1 line
2.44.0
maintainer
#1 lore raw

Hi Heiner,

Quoted 11 lines · Heiner Kallweit

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")
Quoted 6 lines

---
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 static void i801_add_mux(struct i801_priv *priv) · line 1431

Quoted 13 lines
---
 drivers/i2c/busses/i2c-i801.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -1
index 291c609d1..9c624f31c 100644
@@ -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

Quoted 16 lines
drivers/i2c/busses/i2c-i801.c +3 -0
 	/*
 	 * 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;
 	}
 }
 
Signature · 1 line
2.44.0
#2 lore raw
Quoted 21 lines · Andi Shyti

Hi Heiner,

Quoted 11 lines · Heiner Kallweit

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")
Quoted 6 lines

---
v2:
- cc stable
- free memory allocated for the lookup table
v3:
- cc'ed Linus

Quoted 2 lines

this patch is a resend...

Right, it's effectively a resend.

Quoted 36 lines

drivers/i2c/busses/i2c-i801.c static void i801_add_mux(struct i801_priv *priv) · line 1431

Quoted 13 lines
---
 drivers/i2c/busses/i2c-i801.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -1
index 291c609d1..9c624f31c 100644
@@ -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

Quoted 16 lines
drivers/i2c/busses/i2c-i801.c +3 -0
 	/*
 	 * 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;
 	}
 }
 
Signature · 1 line
2.44.0
Reviewed-by on v3 1/1
#3 lore raw
In reply to Heiner Kallweit
Quoted 11 lines · Heiner Kallweit

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")
Quoted 6 lines

---
v2:
- cc stable
- free memory allocated for the lookup table
v3:
- cc'ed Linus

My bug I guess, mea culpa.

Yours,
Linus Walleij

maintainer
#4 lore raw

Hi Linus,

Quoted 18 lines
Quoted 11 lines

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")
Quoted 6 lines

---
v2:
- cc stable
- free memory allocated for the lookup table
v3:
- cc'ed Linus

Quoted 2 lines

My bug I guess, mea culpa.

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

Andi

maintainer Applied
#5 lore raw
In reply to Heiner Kallweit

Hi

Quoted 8 lines · Heiner Kallweit

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