Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: exar: use devm action for freeing the IDA and drop remove()

We can simplify the error path in probe() and drop remove() entirely if
we provide a devm action for freeing the device ID.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

+12 -15
+12 -15
drivers/gpio/gpio-exar.c
··· 111 111 return 0; 112 112 } 113 113 114 + static void exar_devm_ida_free(void *data) 115 + { 116 + struct exar_gpio_chip *exar_gpio = data; 117 + 118 + ida_free(&ida_index, exar_gpio->index); 119 + } 120 + 114 121 static const struct regmap_config exar_regmap_config = { 115 122 .name = "exar-gpio", 116 123 .reg_bits = 16, ··· 165 158 if (index < 0) 166 159 return index; 167 160 161 + ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio); 162 + if (ret) 163 + return ret; 164 + 168 165 sprintf(exar_gpio->name, "exar_gpio%d", index); 169 166 exar_gpio->gpio_chip.label = exar_gpio->name; 170 167 exar_gpio->gpio_chip.parent = dev; ··· 184 173 185 174 ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio); 186 175 if (ret) 187 - goto err_destroy; 176 + return ret; 188 177 189 178 platform_set_drvdata(pdev, exar_gpio); 190 - 191 - return 0; 192 - 193 - err_destroy: 194 - ida_free(&ida_index, index); 195 - return ret; 196 - } 197 - 198 - static int gpio_exar_remove(struct platform_device *pdev) 199 - { 200 - struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev); 201 - 202 - ida_free(&ida_index, exar_gpio->index); 203 179 204 180 return 0; 205 181 } 206 182 207 183 static struct platform_driver gpio_exar_driver = { 208 184 .probe = gpio_exar_probe, 209 - .remove = gpio_exar_remove, 210 185 .driver = { 211 186 .name = DRIVER_NAME, 212 187 },