History

staging: lirc: fix for "lirc_dev: lirc_register_driver: driver pointer must be not NULL!"

Unable to load the module lirc_parallel without the attached patch.

Thomas Viehweger committed 15 years ago

Commit 5d884b91 parent 8590a031 file · +68 −4Browse files

Showing the changes to drivers/staging/lirc/lirc_parallel.c (1 of 1 file). Show all

Unified · Split

drivers/staging/lirc/lirc_parallel.c+68−4
@@ -42,6 +42,7 @@ · 41 unmodified lines
4242
4343 #include <linux/poll.h>
4444 #include <linux/parport.h>
45+#include <linux/platform_device.h>
4546
4647 #include <media/lirc.h>
4748 #include <media/lirc_dev.h>
@@ -580,6 +581,40 @@ static struct lirc_driver driver = { · 532 unmodified lines
580581 .owner = THIS_MODULE,
581582 };
582583
584+static struct platform_device *lirc_parallel_dev;
585+
586+static int __devinit lirc_parallel_probe(struct platform_device *dev)
587+{
588+ return 0;
589+}
590+
591+static int __devexit lirc_parallel_remove(struct platform_device *dev)
592+{
593+ return 0;
594+}
595+
596+static int lirc_parallel_suspend(struct platform_device *dev,
597+ pm_message_t state)
598+{
599+ return 0;
600+}
601+
602+static int lirc_parallel_resume(struct platform_device *dev)
603+{
604+ return 0;
605+}
606+
607+static struct platform_driver lirc_parallel_driver = {
608+ .probe = lirc_parallel_probe,
609+ .remove = __devexit_p(lirc_parallel_remove),
610+ .suspend = lirc_parallel_suspend,
611+ .resume = lirc_parallel_resume,
612+ .driver = {
613+ .name = LIRC_DRIVER_NAME,
614+ .owner = THIS_MODULE,
615+ },
616+};
617+
583618 static int pf(void *handle);
584619 static void kf(void *handle);
585620
@@ -608,11 +643,30 @@ static void kf(void *handle) · 22 unmodified lines
608643
609644 static int __init lirc_parallel_init(void)
610645 {
646+ int result;
647+
648+ result = platform_driver_register(&lirc_parallel_driver);
649+ if (result) {
650+ printk("platform_driver_register returned %d\n", result);
651+ return result;
652+ }
653+
654+ lirc_parallel_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
655+ if (!lirc_parallel_dev) {
656+ result = -ENOMEM;
657+ goto exit_driver_unregister;
658+ }
659+
660+ result = platform_device_add(lirc_parallel_dev);
661+ if (result)
662+ goto exit_device_put;
663+
611664 pport = parport_find_base(io);
612665 if (pport == NULL) {
613666 printk(KERN_NOTICE "%s: no port at %x found\n",
614667 LIRC_DRIVER_NAME, io);
615− return -ENXIO;
668+ result = -ENXIO;
669+ goto exit_device_put;
616670 }
617671 ppdevice = parport_register_device(pport, LIRC_DRIVER_NAME,
618672 pf, kf, irq_handler, 0, NULL);
@@ -620,7 +674,8 @@ static int __init lirc_parallel_init(void) · 1 unmodified line
620674 if (ppdevice == NULL) {
621675 printk(KERN_NOTICE "%s: parport_register_device() failed\n",
622676 LIRC_DRIVER_NAME);
623− return -ENXIO;
677+ result = -ENXIO;
678+ goto exit_device_put;
624679 }
625680 if (parport_claim(ppdevice) != 0)
626681 goto skip_init;
@@ -638,7 +693,8 @@ static int __init lirc_parallel_init(void) · 11 unmodified lines
638693 is_claimed = 0;
639694 parport_release(pport);
640695 parport_unregister_device(ppdevice);
641− return -EIO;
696+ result = -EIO;
697+ goto exit_device_put;
642698 }
643699
644700 #endif
@@ -649,16 +705,24 @@ static int __init lirc_parallel_init(void) · 4 unmodified lines
649705 is_claimed = 0;
650706 parport_release(ppdevice);
651707 skip_init:
708+ driver.dev = &lirc_parallel_dev->dev;
652709 driver.minor = lirc_register_driver(&driver);
653710 if (driver.minor < 0) {
654711 printk(KERN_NOTICE "%s: register_chrdev() failed\n",
655712 LIRC_DRIVER_NAME);
656713 parport_unregister_device(ppdevice);
657− return -EIO;
714+ result = -EIO;
715+ goto exit_device_put;
658716 }
659717 printk(KERN_INFO "%s: installed using port 0x%04x irq %d\n",
660718 LIRC_DRIVER_NAME, io, irq);
661719 return 0;
720+
721+exit_device_put:
722+ platform_device_put(lirc_parallel_dev);
723+exit_driver_unregister:
724+ platform_driver_unregister(&lirc_parallel_driver);
725+ return result;
662726 }
663727
664728 static void __exit lirc_parallel_exit(void)