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

authored by Heiner Kallweit and committed by Wolfram Sang ceb013b2 09f02902

Changed files
+3 -1
drivers
i2c
busses
+3 -1
drivers/i2c/busses/i2c-i801.c
··· 1416 1416 lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip, 1417 1417 mux_config->gpios[i], "mux", 0); 1418 1418 gpiod_add_lookup_table(lookup); 1419 - priv->lookup = lookup; 1420 1419 1421 1420 /* 1422 1421 * Register the mux device, we use PLATFORM_DEVID_NONE here ··· 1429 1430 sizeof(struct i2c_mux_gpio_platform_data)); 1430 1431 if (IS_ERR(priv->mux_pdev)) { 1431 1432 gpiod_remove_lookup_table(lookup); 1433 + devm_kfree(dev, lookup); 1432 1434 dev_err(dev, "Failed to register i2c-mux-gpio device\n"); 1435 + } else { 1436 + priv->lookup = lookup; 1433 1437 } 1434 1438 } 1435 1439