Commit 56481f00 authored by David Härdeman's avatar David Härdeman Committed by Mauro Carvalho Chehab

[media] lirc_dev: merge lirc_register_driver() and lirc_allocate_driver()

Merging the two means that lirc_allocate_buffer() is called before
device_add() and cdev_add() which makes more sense. This also
simplifies the locking slightly because lirc_allocate_buffer() will
always be called with lirc_dev_lock held.
Signed-off-by: default avatarDavid Härdeman <david@hardeman.nu>
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent e0e3c77c
...@@ -120,8 +120,6 @@ static int lirc_allocate_buffer(struct irctl *ir) ...@@ -120,8 +120,6 @@ static int lirc_allocate_buffer(struct irctl *ir)
unsigned int buffer_size; unsigned int buffer_size;
struct lirc_driver *d = &ir->d; struct lirc_driver *d = &ir->d;
mutex_lock(&lirc_dev_lock);
bytes_in_key = BITS_TO_LONGS(d->code_length) + bytes_in_key = BITS_TO_LONGS(d->code_length) +
(d->code_length % 8 ? 1 : 0); (d->code_length % 8 ? 1 : 0);
buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key; buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
...@@ -145,16 +143,15 @@ static int lirc_allocate_buffer(struct irctl *ir) ...@@ -145,16 +143,15 @@ static int lirc_allocate_buffer(struct irctl *ir)
} }
ir->buf_internal = true; ir->buf_internal = true;
d->rbuf = ir->buf;
} }
ir->chunk_size = ir->buf->chunk_size; ir->chunk_size = ir->buf->chunk_size;
out: out:
mutex_unlock(&lirc_dev_lock);
return err; return err;
} }
static int lirc_allocate_driver(struct lirc_driver *d) int lirc_register_driver(struct lirc_driver *d)
{ {
struct irctl *ir; struct irctl *ir;
int minor; int minor;
...@@ -225,6 +222,15 @@ static int lirc_allocate_driver(struct lirc_driver *d) ...@@ -225,6 +222,15 @@ static int lirc_allocate_driver(struct lirc_driver *d)
ir->d = *d; ir->d = *d;
if (LIRC_CAN_REC(d->features)) {
err = lirc_allocate_buffer(irctls[minor]);
if (err) {
kfree(ir);
goto out_lock;
}
d->rbuf = ir->buf;
}
device_initialize(&ir->dev); device_initialize(&ir->dev);
ir->dev.devt = MKDEV(MAJOR(lirc_base_dev), ir->d.minor); ir->dev.devt = MKDEV(MAJOR(lirc_base_dev), ir->d.minor);
ir->dev.class = lirc_class; ir->dev.class = lirc_class;
...@@ -248,7 +254,9 @@ static int lirc_allocate_driver(struct lirc_driver *d) ...@@ -248,7 +254,9 @@ static int lirc_allocate_driver(struct lirc_driver *d)
dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n", dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n",
ir->d.name, ir->d.minor); ir->d.name, ir->d.minor);
return minor; return minor;
out_cdev: out_cdev:
cdev_del(&ir->cdev); cdev_del(&ir->cdev);
out_free_dev: out_free_dev:
...@@ -258,29 +266,6 @@ static int lirc_allocate_driver(struct lirc_driver *d) ...@@ -258,29 +266,6 @@ static int lirc_allocate_driver(struct lirc_driver *d)
return err; return err;
} }
int lirc_register_driver(struct lirc_driver *d)
{
int minor, err = 0;
minor = lirc_allocate_driver(d);
if (minor < 0)
return minor;
if (LIRC_CAN_REC(d->features)) {
err = lirc_allocate_buffer(irctls[minor]);
if (err)
lirc_unregister_driver(minor);
else
/*
* This is kind of a hack but ir-lirc-codec needs
* access to the buffer that lirc_dev allocated.
*/
d->rbuf = irctls[minor]->buf;
}
return err ? err : minor;
}
EXPORT_SYMBOL(lirc_register_driver); EXPORT_SYMBOL(lirc_register_driver);
int lirc_unregister_driver(int minor) int lirc_unregister_driver(int minor)
......
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