Skip to contentSkip to conversation

i2c: i801: Avoid potential double call to gpiod_remove_lookup_table

PATCH Superseded Heiner Kallweit 2 participants 2 messages Mar 3, 2024 – Mar 4, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 leaving it to i801_del_mux() to clean up.

Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

---
v2:
- cc stable
- free memory allocated for the lookup table

---
 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 Reviewed-by on v2 1/1
#1 lore raw
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 leaving it to i801_del_mux() to clean up.

Fixes d308dfbf62ef ("i2c: mux/i801: Switch to use descriptor passing")

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

Just a little thought...

Quoted 21 lines

---
v2:
- cc stable
- free memory allocated for the lookup table

---
 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;
 
 	/*
 	 * Register the mux device, we use PLATFORM_DEVID_NONE here

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

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -0
@@ -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

Quoted 9 lines
drivers/i2c/busses/i2c-i801.c +2 -0
 		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
+	} else {
+		priv->lookup = lookup;
 	}
 }
 
Signature · 1 line
2.44.0