diff options
-rw-r--r-- | drivers/media/rc/lirc_dev.c | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 9f20f94a31ae..59f4c93cccc4 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c | |||
@@ -19,6 +19,8 @@ | |||
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
23 | |||
22 | #include <linux/module.h> | 24 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
24 | #include <linux/sched.h> | 26 | #include <linux/sched.h> |
@@ -240,59 +242,51 @@ static int lirc_allocate_driver(struct lirc_driver *d) | |||
240 | int err; | 242 | int err; |
241 | 243 | ||
242 | if (!d) { | 244 | if (!d) { |
243 | printk(KERN_ERR "lirc_dev: lirc_register_driver: " | 245 | pr_err("driver pointer must be not NULL!\n"); |
244 | "driver pointer must be not NULL!\n"); | ||
245 | err = -EBADRQC; | 246 | err = -EBADRQC; |
246 | goto out; | 247 | goto out; |
247 | } | 248 | } |
248 | 249 | ||
249 | if (!d->dev) { | 250 | if (!d->dev) { |
250 | printk(KERN_ERR "%s: dev pointer not filled in!\n", __func__); | 251 | pr_err("dev pointer not filled in!\n"); |
251 | err = -EINVAL; | 252 | err = -EINVAL; |
252 | goto out; | 253 | goto out; |
253 | } | 254 | } |
254 | 255 | ||
255 | if (MAX_IRCTL_DEVICES <= d->minor) { | 256 | if (MAX_IRCTL_DEVICES <= d->minor) { |
256 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 257 | dev_err(d->dev, "minor must be between 0 and %d!\n", |
257 | "\"minor\" must be between 0 and %d (%d)!\n", | 258 | MAX_IRCTL_DEVICES - 1); |
258 | MAX_IRCTL_DEVICES - 1, d->minor); | ||
259 | err = -EBADRQC; | 259 | err = -EBADRQC; |
260 | goto out; | 260 | goto out; |
261 | } | 261 | } |
262 | 262 | ||
263 | if (1 > d->code_length || (BUFLEN * 8) < d->code_length) { | 263 | if (1 > d->code_length || (BUFLEN * 8) < d->code_length) { |
264 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 264 | dev_err(d->dev, "code length must be less than %d bits\n", |
265 | "code length in bits for minor (%d) " | 265 | BUFLEN * 8); |
266 | "must be less than %d!\n", | ||
267 | d->minor, BUFLEN * 8); | ||
268 | err = -EBADRQC; | 266 | err = -EBADRQC; |
269 | goto out; | 267 | goto out; |
270 | } | 268 | } |
271 | 269 | ||
272 | if (d->sample_rate) { | 270 | if (d->sample_rate) { |
273 | if (2 > d->sample_rate || HZ < d->sample_rate) { | 271 | if (2 > d->sample_rate || HZ < d->sample_rate) { |
274 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 272 | dev_err(d->dev, "invalid %d sample rate\n", |
275 | "sample_rate must be between 2 and %d!\n", HZ); | 273 | d->sample_rate); |
276 | err = -EBADRQC; | 274 | err = -EBADRQC; |
277 | goto out; | 275 | goto out; |
278 | } | 276 | } |
279 | if (!d->add_to_buf) { | 277 | if (!d->add_to_buf) { |
280 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 278 | dev_err(d->dev, "add_to_buf not set\n"); |
281 | "add_to_buf cannot be NULL when " | ||
282 | "sample_rate is set\n"); | ||
283 | err = -EBADRQC; | 279 | err = -EBADRQC; |
284 | goto out; | 280 | goto out; |
285 | } | 281 | } |
286 | } else if (!(d->fops && d->fops->read) && !d->rbuf) { | 282 | } else if (!(d->fops && d->fops->read) && !d->rbuf) { |
287 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 283 | dev_err(d->dev, "fops->read and rbuf are NULL!\n"); |
288 | "fops->read and rbuf cannot all be NULL!\n"); | ||
289 | err = -EBADRQC; | 284 | err = -EBADRQC; |
290 | goto out; | 285 | goto out; |
291 | } else if (!d->rbuf) { | 286 | } else if (!d->rbuf) { |
292 | if (!(d->fops && d->fops->read && d->fops->poll && | 287 | if (!(d->fops && d->fops->read && d->fops->poll && |
293 | d->fops->unlocked_ioctl)) { | 288 | d->fops->unlocked_ioctl)) { |
294 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 289 | dev_err(d->dev, "undefined read, poll, ioctl\n"); |
295 | "neither read, poll nor unlocked_ioctl can be NULL!\n"); | ||
296 | err = -EBADRQC; | 290 | err = -EBADRQC; |
297 | goto out; | 291 | goto out; |
298 | } | 292 | } |
@@ -308,14 +302,12 @@ static int lirc_allocate_driver(struct lirc_driver *d) | |||
308 | if (!irctls[minor]) | 302 | if (!irctls[minor]) |
309 | break; | 303 | break; |
310 | if (MAX_IRCTL_DEVICES == minor) { | 304 | if (MAX_IRCTL_DEVICES == minor) { |
311 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 305 | dev_err(d->dev, "no free slots for drivers!\n"); |
312 | "no free slots for drivers!\n"); | ||
313 | err = -ENOMEM; | 306 | err = -ENOMEM; |
314 | goto out_lock; | 307 | goto out_lock; |
315 | } | 308 | } |
316 | } else if (irctls[minor]) { | 309 | } else if (irctls[minor]) { |
317 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 310 | dev_err(d->dev, "minor (%d) just registered!\n", minor); |
318 | "minor (%d) just registered!\n", minor); | ||
319 | err = -EBUSY; | 311 | err = -EBUSY; |
320 | goto out_lock; | 312 | goto out_lock; |
321 | } | 313 | } |
@@ -352,9 +344,8 @@ static int lirc_allocate_driver(struct lirc_driver *d) | |||
352 | /* try to fire up polling thread */ | 344 | /* try to fire up polling thread */ |
353 | ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev"); | 345 | ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev"); |
354 | if (IS_ERR(ir->task)) { | 346 | if (IS_ERR(ir->task)) { |
355 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 347 | dev_err(d->dev, "cannot run thread for minor = %d\n", |
356 | "cannot run poll thread for minor = %d\n", | 348 | d->minor); |
357 | d->minor); | ||
358 | err = -ECHILD; | 349 | err = -ECHILD; |
359 | goto out_sysfs; | 350 | goto out_sysfs; |
360 | } | 351 | } |
@@ -403,15 +394,14 @@ int lirc_unregister_driver(int minor) | |||
403 | struct cdev *cdev; | 394 | struct cdev *cdev; |
404 | 395 | ||
405 | if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { | 396 | if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { |
406 | printk(KERN_ERR "lirc_dev: %s: minor (%d) must be between " | 397 | pr_err("minor (%d) must be between 0 and %d!\n", |
407 | "0 and %d!\n", __func__, minor, MAX_IRCTL_DEVICES - 1); | 398 | minor, MAX_IRCTL_DEVICES - 1); |
408 | return -EBADRQC; | 399 | return -EBADRQC; |
409 | } | 400 | } |
410 | 401 | ||
411 | ir = irctls[minor]; | 402 | ir = irctls[minor]; |
412 | if (!ir) { | 403 | if (!ir) { |
413 | printk(KERN_ERR "lirc_dev: %s: failed to get irctl struct " | 404 | pr_err("failed to get irctl\n"); |
414 | "for minor %d!\n", __func__, minor); | ||
415 | return -ENOENT; | 405 | return -ENOENT; |
416 | } | 406 | } |
417 | 407 | ||
@@ -420,8 +410,8 @@ int lirc_unregister_driver(int minor) | |||
420 | mutex_lock(&lirc_dev_lock); | 410 | mutex_lock(&lirc_dev_lock); |
421 | 411 | ||
422 | if (ir->d.minor != minor) { | 412 | if (ir->d.minor != minor) { |
423 | printk(KERN_ERR "lirc_dev: %s: minor (%d) device not " | 413 | dev_err(ir->d.dev, "lirc_dev: minor %d device not registered\n", |
424 | "registered!\n", __func__, minor); | 414 | minor); |
425 | mutex_unlock(&lirc_dev_lock); | 415 | mutex_unlock(&lirc_dev_lock); |
426 | return -ENOENT; | 416 | return -ENOENT; |
427 | } | 417 | } |
@@ -463,8 +453,7 @@ int lirc_dev_fop_open(struct inode *inode, struct file *file) | |||
463 | int retval = 0; | 453 | int retval = 0; |
464 | 454 | ||
465 | if (iminor(inode) >= MAX_IRCTL_DEVICES) { | 455 | if (iminor(inode) >= MAX_IRCTL_DEVICES) { |
466 | printk(KERN_WARNING "lirc_dev [%d]: open result = -ENODEV\n", | 456 | pr_err("open result for %d is -ENODEV\n", iminor(inode)); |
467 | iminor(inode)); | ||
468 | return -ENODEV; | 457 | return -ENODEV; |
469 | } | 458 | } |
470 | 459 | ||
@@ -526,7 +515,7 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file) | |||
526 | int ret; | 515 | int ret; |
527 | 516 | ||
528 | if (!ir) { | 517 | if (!ir) { |
529 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); | 518 | pr_err("called with invalid irctl\n"); |
530 | return -EINVAL; | 519 | return -EINVAL; |
531 | } | 520 | } |
532 | 521 | ||
@@ -562,7 +551,7 @@ unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait) | |||
562 | unsigned int ret; | 551 | unsigned int ret; |
563 | 552 | ||
564 | if (!ir) { | 553 | if (!ir) { |
565 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); | 554 | pr_err("called with invalid irctl\n"); |
566 | return POLLERR; | 555 | return POLLERR; |
567 | } | 556 | } |
568 | 557 | ||
@@ -593,7 +582,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
593 | struct irctl *ir = irctls[iminor(file_inode(file))]; | 582 | struct irctl *ir = irctls[iminor(file_inode(file))]; |
594 | 583 | ||
595 | if (!ir) { | 584 | if (!ir) { |
596 | printk(KERN_ERR "lirc_dev: %s: no irctl found!\n", __func__); | 585 | pr_err("no irctl found!\n"); |
597 | return -ENODEV; | 586 | return -ENODEV; |
598 | } | 587 | } |
599 | 588 | ||
@@ -601,7 +590,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
601 | ir->d.name, ir->d.minor, cmd); | 590 | ir->d.name, ir->d.minor, cmd); |
602 | 591 | ||
603 | if (ir->d.minor == NOPLUG || !ir->attached) { | 592 | if (ir->d.minor == NOPLUG || !ir->attached) { |
604 | dev_dbg(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n", | 593 | dev_err(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n", |
605 | ir->d.name, ir->d.minor); | 594 | ir->d.name, ir->d.minor); |
606 | return -ENODEV; | 595 | return -ENODEV; |
607 | } | 596 | } |
@@ -678,7 +667,7 @@ ssize_t lirc_dev_fop_read(struct file *file, | |||
678 | DECLARE_WAITQUEUE(wait, current); | 667 | DECLARE_WAITQUEUE(wait, current); |
679 | 668 | ||
680 | if (!ir) { | 669 | if (!ir) { |
681 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); | 670 | pr_err("called with invalid irctl\n"); |
682 | return -ENODEV; | 671 | return -ENODEV; |
683 | } | 672 | } |
684 | 673 | ||
@@ -783,7 +772,7 @@ ssize_t lirc_dev_fop_write(struct file *file, const char __user *buffer, | |||
783 | struct irctl *ir = irctls[iminor(file_inode(file))]; | 772 | struct irctl *ir = irctls[iminor(file_inode(file))]; |
784 | 773 | ||
785 | if (!ir) { | 774 | if (!ir) { |
786 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); | 775 | pr_err("called with invalid irctl\n"); |
787 | return -ENODEV; | 776 | return -ENODEV; |
788 | } | 777 | } |
789 | 778 | ||
@@ -802,7 +791,7 @@ static int __init lirc_dev_init(void) | |||
802 | lirc_class = class_create(THIS_MODULE, "lirc"); | 791 | lirc_class = class_create(THIS_MODULE, "lirc"); |
803 | if (IS_ERR(lirc_class)) { | 792 | if (IS_ERR(lirc_class)) { |
804 | retval = PTR_ERR(lirc_class); | 793 | retval = PTR_ERR(lirc_class); |
805 | printk(KERN_ERR "lirc_dev: class_create failed\n"); | 794 | pr_err("class_create failed\n"); |
806 | goto error; | 795 | goto error; |
807 | } | 796 | } |
808 | 797 | ||
@@ -810,13 +799,13 @@ static int __init lirc_dev_init(void) | |||
810 | IRCTL_DEV_NAME); | 799 | IRCTL_DEV_NAME); |
811 | if (retval) { | 800 | if (retval) { |
812 | class_destroy(lirc_class); | 801 | class_destroy(lirc_class); |
813 | printk(KERN_ERR "lirc_dev: alloc_chrdev_region failed\n"); | 802 | pr_err("alloc_chrdev_region failed\n"); |
814 | goto error; | 803 | goto error; |
815 | } | 804 | } |
816 | 805 | ||
817 | 806 | ||
818 | printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, " | 807 | pr_info("IR Remote Control driver registered, major %d\n", |
819 | "major %d \n", MAJOR(lirc_base_dev)); | 808 | MAJOR(lirc_base_dev)); |
820 | 809 | ||
821 | error: | 810 | error: |
822 | return retval; | 811 | return retval; |
@@ -828,7 +817,7 @@ static void __exit lirc_dev_exit(void) | |||
828 | { | 817 | { |
829 | class_destroy(lirc_class); | 818 | class_destroy(lirc_class); |
830 | unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES); | 819 | unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES); |
831 | printk(KERN_INFO "lirc_dev: module unloaded\n"); | 820 | pr_info("module unloaded\n"); |
832 | } | 821 | } |
833 | 822 | ||
834 | module_init(lirc_dev_init); | 823 | module_init(lirc_dev_init); |