Skip to content

Commit

Permalink
V4L/DVB (13537): ir: Prepare the code for dynamic keycode table alloc…
Browse files Browse the repository at this point in the history
…ation

Currently, the IR table is initialized by calling ir_input_init(). However,
this function doesn't return any error code, nor has a function to be called
when de-initializing the IR's.

Change the return argment to integer and make sure that each driver will
handle the error code. Also adds a function to free any resources that may
be allocating there: ir_input_free().

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Mauro Carvalho Chehab committed Dec 5, 2009
1 parent 0278155 commit 055cd55
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 14 deletions.
12 changes: 11 additions & 1 deletion drivers/media/common/ir-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,31 @@ static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)

/* -------------------------------------------------------------------------- */

void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
int ir_type, struct ir_scancode_table *ir_codes)
{
ir->ir_type = ir_type;

/* FIXME: Add the proper code to dynamically allocate IR table */

ir_set_keycode_table(dev, ir_codes);

clear_bit(0, dev->keybit);

set_bit(EV_KEY, dev->evbit);
if (repeat)
set_bit(EV_REP, dev->evbit);

return 0;
}
EXPORT_SYMBOL_GPL(ir_input_init);

void ir_input_free(struct input_dev *input_dev)
{
/* FIXME: Add the proper code to free allocated resources */
}
EXPORT_SYMBOL_GPL(ir_input_free);

void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
{
if (ir->keypressed) {
Expand Down
10 changes: 8 additions & 2 deletions drivers/media/dvb/dm1105/dm1105.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,12 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
"pci-%s/ir0", pci_name(dm1105->pdev));

ir_input_init(input_dev, &dm1105->ir.ir, ir_type, ir_codes);
err = ir_input_init(input_dev, &dm1105->ir.ir, ir_type, ir_codes);
if (err < 0) {
input_free_device(input_dev);
return err;
}

input_dev->name = "DVB on-card IR receiver";
input_dev->phys = dm1105->ir.input_phys;
input_dev->id.bustype = BUS_PCI;
Expand All @@ -608,6 +613,7 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)

err = input_register_device(input_dev);
if (err) {
ir_input_free(input_dev);
input_free_device(input_dev);
return err;
}
Expand All @@ -617,8 +623,8 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)

void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105)
{
ir_input_free(dm1105->ir.input_dev);
input_unregister_device(dm1105->ir.input_dev);

}

static int __devinit dm1105dvb_hw_init(struct dm1105dvb *dm1105dvb)
Expand Down
14 changes: 11 additions & 3 deletions drivers/media/dvb/ttpci/budget-ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
case 0x1011:
case 0x1012:
/* The hauppauge keymap is a superset of these remotes */
ir_input_init(input_dev, &budget_ci->ir.state,
error = ir_input_init(input_dev, &budget_ci->ir.state,
IR_TYPE_RC5, &ir_codes_hauppauge_new_table);
if (error < 0)
goto out2;

if (rc5_device < 0)
budget_ci->ir.rc5_device = 0x1f;
Expand All @@ -236,8 +238,10 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
case 0x1017:
case 0x101a:
/* for the Technotrend 1500 bundled remote */
ir_input_init(input_dev, &budget_ci->ir.state,
error = ir_input_init(input_dev, &budget_ci->ir.state,
IR_TYPE_RC5, &ir_codes_tt_1500_table);
if (error < 0)
goto out2;

if (rc5_device < 0)
budget_ci->ir.rc5_device = IR_DEVICE_ANY;
Expand All @@ -246,8 +250,10 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
break;
default:
/* unknown remote */
ir_input_init(input_dev, &budget_ci->ir.state,
error = ir_input_init(input_dev, &budget_ci->ir.state,
IR_TYPE_RC5, &ir_codes_budget_ci_old_table);
if (error < 0)
goto out2;

if (rc5_device < 0)
budget_ci->ir.rc5_device = IR_DEVICE_ANY;
Expand Down Expand Up @@ -280,6 +286,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
return 0;

out2:
ir_input_free(input_dev);
input_free_device(input_dev);
out1:
return error;
Expand All @@ -297,6 +304,7 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci)
del_timer_sync(&dev->timer);
ir_input_nokey(dev, &budget_ci->ir.state);

ir_input_free(dev);
input_unregister_device(dev);
}

Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/bt8xx/bttv-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ int bttv_input_init(struct bttv *btv)
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
pci_name(btv->c.pci));

ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
err = ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
if (err < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_PCI;
Expand Down Expand Up @@ -400,6 +403,7 @@ int bttv_input_init(struct bttv *btv)
bttv_ir_stop(btv);
btv->remote = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -411,6 +415,7 @@ void bttv_input_fini(struct bttv *btv)
return;

bttv_ir_stop(btv);
ir_input_free(btv->remote->dev);
input_unregister_device(btv->remote->dev);
kfree(btv->remote);
btv->remote = NULL;
Expand Down
8 changes: 7 additions & 1 deletion drivers/media/video/cx231xx/cx231xx-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ int cx231xx_ir_init(struct cx231xx *dev)
usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
strlcat(ir->phys, "/input0", sizeof(ir->phys));

ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER, dev->board.ir_codes);
err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER,
dev->board.ir_codes);
if (err < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_USB;
Expand All @@ -222,6 +226,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
cx231xx_ir_stop(ir);
dev->ir = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -236,6 +241,7 @@ int cx231xx_ir_fini(struct cx231xx *dev)
return 0;

cx231xx_ir_stop(ir);
ir_input_free(ir->input);
input_unregister_device(ir->input);
kfree(ir);

Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/cx23885/cx23885-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ int cx23885_input_init(struct cx23885_dev *dev)
cx23885_boards[dev->board].name);
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(dev->pci));

ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
ret = ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
if (ret < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_PCI;
Expand All @@ -404,6 +407,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
cx23885_input_ir_stop(dev);
dev->ir_input = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return ret;
Expand All @@ -416,6 +420,7 @@ void cx23885_input_fini(struct cx23885_dev *dev)

if (dev->ir_input == NULL)
return;
ir_input_free(dev->ir_input->dev);
input_unregister_device(dev->ir_input->dev);
kfree(dev->ir_input);
dev->ir_input = NULL;
Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/cx88/cx88-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));

ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
err = ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
if (err < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_PCI;
Expand Down Expand Up @@ -390,6 +393,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
cx88_ir_stop(core, ir);
core->ir = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -404,6 +408,7 @@ int cx88_ir_fini(struct cx88_core *core)
return 0;

cx88_ir_stop(core, ir);
ir_input_free(ir->input);
input_unregister_device(ir->input);
kfree(ir);

Expand Down
8 changes: 7 additions & 1 deletion drivers/media/video/em28xx/em28xx-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ int em28xx_ir_init(struct em28xx *dev)
usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
strlcat(ir->phys, "/input0", sizeof(ir->phys));

ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER, dev->board.ir_codes);
err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER,
dev->board.ir_codes);
if (err < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_USB;
Expand All @@ -392,6 +396,7 @@ int em28xx_ir_init(struct em28xx *dev)
em28xx_ir_stop(ir);
dev->ir = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -406,6 +411,7 @@ int em28xx_ir_fini(struct em28xx *dev)
return 0;

em28xx_ir_stop(ir);
ir_input_free(ir->input);
input_unregister_device(ir->input);
kfree(ir);

Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/ir-kbd-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,10 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
dev_name(&client->dev));

/* init + register input device */
ir_input_init(input_dev, &ir->ir, ir_type, ir->ir_codes);
err = ir_input_init(input_dev, &ir->ir, ir_type, ir->ir_codes);
if (err < 0)
goto err_out_free;

input_dev->id.bustype = BUS_I2C;
input_dev->name = ir->name;
input_dev->phys = ir->phys;
Expand All @@ -456,6 +459,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
return 0;

err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -469,6 +473,7 @@ static int ir_remove(struct i2c_client *client)
cancel_delayed_work_sync(&ir->work);

/* unregister device */
ir_input_free(ir->input);
input_unregister_device(ir->input);

/* free memory */
Expand Down
7 changes: 6 additions & 1 deletion drivers/media/video/saa7134/saa7134-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,10 @@ int saa7134_input_init1(struct saa7134_dev *dev)
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
pci_name(dev->pci));

ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
err = ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
if (err < 0)
goto err_out_free;

input_dev->name = ir->name;
input_dev->phys = ir->phys;
input_dev->id.bustype = BUS_PCI;
Expand Down Expand Up @@ -683,6 +686,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
saa7134_ir_stop(dev);
dev->remote = NULL;
err_out_free:
ir_input_free(input_dev);
input_free_device(input_dev);
kfree(ir);
return err;
Expand All @@ -694,6 +698,7 @@ void saa7134_input_fini(struct saa7134_dev *dev)
return;

saa7134_ir_stop(dev);
ir_input_free(dev->remote->dev);
input_unregister_device(dev->remote->dev);
kfree(dev->remote);
dev->remote = NULL;
Expand Down
3 changes: 2 additions & 1 deletion include/media/ir-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct card_ir {

/* Routines from ir-functions.c */

void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
int ir_type, struct ir_scancode_table *ir_codes);
void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir);
void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
Expand All @@ -121,6 +121,7 @@ u32 ir_g_keycode_from_table(struct input_dev *input_dev,

int ir_set_keycode_table(struct input_dev *input_dev,
struct ir_scancode_table *rc_tab);
void ir_input_free(struct input_dev *input_dev);

/* scancode->keycode map tables from ir-keymaps.c */

Expand Down

0 comments on commit 055cd55

Please sign in to comment.