if (n_buttons[i] > 6) {
printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
err = -EINVAL;
- goto err_free_devs;
+ goto err_unreg_devs;
}
tgfx->dev[i] = input_dev = input_allocate_device();
if (!input_dev) {
printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
err = -ENOMEM;
- goto err_free_devs;
+ goto err_unreg_devs;
}
tgfx->sticks |= (1 << i);
for (j = 0; j < n_buttons[i]; j++)
set_bit(tgfx_buttons[j], input_dev->keybit);
- input_register_device(tgfx->dev[i]);
+ err = input_register_device(tgfx->dev[i]);
+ if (err)
+ goto err_free_dev;
}
if (!tgfx->sticks) {
return tgfx;
- err_free_devs:
+ err_free_dev:
+ input_free_device(tgfx->dev[i]);
+ err_unreg_devs:
while (--i >= 0)
- input_unregister_device(tgfx->dev[i]);
+ if (tgfx->dev[i])
+ input_unregister_device(tgfx->dev[i]);
err_free_tgfx:
kfree(tgfx);
err_unreg_pardev:
return ERR_PTR(err);
}
-static void __exit tgfx_remove(struct tgfx *tgfx)
+static void tgfx_remove(struct tgfx *tgfx)
{
int i;
if (err) {
while (--i >= 0)
- tgfx_remove(tgfx_base[i]);
+ if (tgfx_base[i])
+ tgfx_remove(tgfx_base[i]);
return err;
}