Skip to content

Commit

Permalink
i2c: i801: Avoid potential double call to gpiod_remove_lookup_table
Browse files Browse the repository at this point in the history
commit ceb013b upstream.

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: d308dfb ("i2c: mux/i801: Switch to use descriptor passing")
Cc: stable@vger.kernel.org
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Heiner Kallweit authored and Greg Kroah-Hartman committed Apr 10, 2024
1 parent 4b12ff5 commit b3914fe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/i2c/busses/i2c-i801.c
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,6 @@ static int i801_add_mux(struct i801_priv *priv)
mux_config->gpios[i], "mux", 0);
}
gpiod_add_lookup_table(lookup);
priv->lookup = lookup;

/*
* Register the mux device, we use PLATFORM_DEVID_NONE here
Expand All @@ -1430,7 +1429,10 @@ static int 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;
}

return PTR_ERR_OR_ZERO(priv->mux_pdev);
Expand Down

0 comments on commit b3914fe

Please sign in to comment.