Commit 8cc532ef authored by David Hardeman's avatar David Hardeman Committed by Mauro Carvalho Chehab

V4L/DVB (4877): budget-ci IR: improve error checking in init and deinit functions

Improve the error checking in the IR init and deinit functions.
Based on Darren Salt's dvb-ir patchset.
Signed-off-by: default avatarDavid Hardeman <david@hardeman.nu>
Signed-off-by: default avatarAndrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 5cc8ae00
...@@ -198,11 +198,13 @@ static int msp430_ir_init(struct budget_ci *budget_ci) ...@@ -198,11 +198,13 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
struct saa7146_dev *saa = budget_ci->budget.dev; struct saa7146_dev *saa = budget_ci->budget.dev;
struct input_dev *input_dev = budget_ci->ir.dev; struct input_dev *input_dev = budget_ci->ir.dev;
int i; int i;
int err; int error;
budget_ci->ir.dev = input_dev = input_allocate_device(); budget_ci->ir.dev = input_dev = input_allocate_device();
if (!input_dev) if (!input_dev) {
return -ENOMEM; error = -ENOMEM;
goto out1;
}
snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name), snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
"Budget-CI dvb ir receiver %s", saa->name); "Budget-CI dvb ir receiver %s", saa->name);
...@@ -232,20 +234,26 @@ static int msp430_ir_init(struct budget_ci *budget_ci) ...@@ -232,20 +234,26 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
if (key_map[i]) if (key_map[i])
set_bit(key_map[i], input_dev->keybit); set_bit(key_map[i], input_dev->keybit);
err = input_register_device(input_dev); error = input_register_device(input_dev);
if (err) { if (error) {
input_free_device(input_dev); printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
return err; goto out2;
} }
input_register_device(budget_ci->ir.dev);
input_dev->timer.function = msp430_ir_debounce; input_dev->timer.function = msp430_ir_debounce;
tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
(unsigned long) budget_ci);
saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06); saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI); saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
return 0; return 0;
out2:
input_free_device(input_dev);
out1:
return error;
} }
static void msp430_ir_deinit(struct budget_ci *budget_ci) static void msp430_ir_deinit(struct budget_ci *budget_ci)
...@@ -255,6 +263,7 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci) ...@@ -255,6 +263,7 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci)
saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06); saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
if (del_timer(&dev->timer)) { if (del_timer(&dev->timer)) {
input_event(dev, EV_KEY, key_map[dev->repeat_key], 0); input_event(dev, EV_KEY, key_map[dev->repeat_key], 0);
...@@ -1115,8 +1124,11 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio ...@@ -1115,8 +1124,11 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
struct budget_ci *budget_ci; struct budget_ci *budget_ci;
int err; int err;
if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL))) budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL);
return -ENOMEM; if (!budget_ci) {
err = -ENOMEM;
goto out1;
}
dprintk(2, "budget_ci: %p\n", budget_ci); dprintk(2, "budget_ci: %p\n", budget_ci);
...@@ -1124,15 +1136,13 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio ...@@ -1124,15 +1136,13 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
dev->ext_priv = budget_ci; dev->ext_priv = budget_ci;
if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) { err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE);
kfree(budget_ci); if (err)
return err; goto out2;
}
tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt, err = msp430_ir_init(budget_ci);
(unsigned long) budget_ci); if (err)
goto out3;
msp430_ir_init(budget_ci);
ciintf_init(budget_ci); ciintf_init(budget_ci);
...@@ -1142,6 +1152,13 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio ...@@ -1142,6 +1152,13 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
ttpci_budget_init_hooks(&budget_ci->budget); ttpci_budget_init_hooks(&budget_ci->budget);
return 0; return 0;
out3:
ttpci_budget_deinit(&budget_ci->budget);
out2:
kfree(budget_ci);
out1:
return err;
} }
static int budget_ci_detach(struct saa7146_dev *dev) static int budget_ci_detach(struct saa7146_dev *dev)
...@@ -1152,16 +1169,13 @@ static int budget_ci_detach(struct saa7146_dev *dev) ...@@ -1152,16 +1169,13 @@ static int budget_ci_detach(struct saa7146_dev *dev)
if (budget_ci->budget.ci_present) if (budget_ci->budget.ci_present)
ciintf_deinit(budget_ci); ciintf_deinit(budget_ci);
msp430_ir_deinit(budget_ci);
if (budget_ci->budget.dvb_frontend) { if (budget_ci->budget.dvb_frontend) {
dvb_unregister_frontend(budget_ci->budget.dvb_frontend); dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
dvb_frontend_detach(budget_ci->budget.dvb_frontend); dvb_frontend_detach(budget_ci->budget.dvb_frontend);
} }
err = ttpci_budget_deinit(&budget_ci->budget); err = ttpci_budget_deinit(&budget_ci->budget);
tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
msp430_ir_deinit(budget_ci);
// disable frontend and CI interface // disable frontend and CI interface
saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT); saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment