aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-sysfs.c')
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c85
1 files changed, 73 insertions, 12 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 6af55a8b6f05..d1dda5caf406 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -44,12 +44,16 @@ struct pvr2_sysfs {
44 struct kobj_type ktype; 44 struct kobj_type ktype;
45 struct class_device_attribute attr_v4l_minor_number; 45 struct class_device_attribute attr_v4l_minor_number;
46 struct class_device_attribute attr_unit_number; 46 struct class_device_attribute attr_unit_number;
47 int v4l_minor_number_created_ok;
48 int unit_number_created_ok;
47}; 49};
48 50
49#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 51#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
50struct pvr2_sysfs_debugifc { 52struct pvr2_sysfs_debugifc {
51 struct class_device_attribute attr_debugcmd; 53 struct class_device_attribute attr_debugcmd;
52 struct class_device_attribute attr_debuginfo; 54 struct class_device_attribute attr_debuginfo;
55 int debugcmd_created_ok;
56 int debuginfo_created_ok;
53}; 57};
54#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 58#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
55 59
@@ -67,6 +71,7 @@ struct pvr2_sysfs_ctl_item {
67 struct pvr2_sysfs_ctl_item *item_next; 71 struct pvr2_sysfs_ctl_item *item_next;
68 struct attribute *attr_gen[7]; 72 struct attribute *attr_gen[7];
69 struct attribute_group grp; 73 struct attribute_group grp;
74 int created_ok;
70 char name[80]; 75 char name[80];
71}; 76};
72 77
@@ -487,6 +492,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
487 struct pvr2_sysfs_func_set *fp; 492 struct pvr2_sysfs_func_set *fp;
488 struct pvr2_ctrl *cptr; 493 struct pvr2_ctrl *cptr;
489 unsigned int cnt,acnt; 494 unsigned int cnt,acnt;
495 int ret;
490 496
491 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) { 497 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
492 return; 498 return;
@@ -589,7 +595,13 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
589 cip->grp.name = cip->name; 595 cip->grp.name = cip->name;
590 cip->grp.attrs = cip->attr_gen; 596 cip->grp.attrs = cip->attr_gen;
591 597
592 sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); 598 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
599 if (ret) {
600 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n",
601 __FUNCTION__, ret);
602 return;
603 }
604 cip->created_ok = !0;
593} 605}
594 606
595#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 607#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
@@ -600,6 +612,8 @@ static ssize_t debugcmd_store(struct class_device *,const char *,size_t count);
600static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) 612static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
601{ 613{
602 struct pvr2_sysfs_debugifc *dip; 614 struct pvr2_sysfs_debugifc *dip;
615 int ret;
616
603 dip = kmalloc(sizeof(*dip),GFP_KERNEL); 617 dip = kmalloc(sizeof(*dip),GFP_KERNEL);
604 if (!dip) return; 618 if (!dip) return;
605 memset(dip,0,sizeof(*dip)); 619 memset(dip,0,sizeof(*dip));
@@ -613,17 +627,34 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
613 dip->attr_debuginfo.attr.mode = S_IRUGO; 627 dip->attr_debuginfo.attr.mode = S_IRUGO;
614 dip->attr_debuginfo.show = debuginfo_show; 628 dip->attr_debuginfo.show = debuginfo_show;
615 sfp->debugifc = dip; 629 sfp->debugifc = dip;
616 class_device_create_file(sfp->class_dev,&dip->attr_debugcmd); 630 ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd);
617 class_device_create_file(sfp->class_dev,&dip->attr_debuginfo); 631 if (ret < 0) {
632 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
633 __FUNCTION__, ret);
634 } else {
635 dip->debugcmd_created_ok = !0;
636 }
637 ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo);
638 if (ret < 0) {
639 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
640 __FUNCTION__, ret);
641 } else {
642 dip->debuginfo_created_ok = !0;
643 }
618} 644}
619 645
620 646
621static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) 647static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
622{ 648{
623 if (!sfp->debugifc) return; 649 if (!sfp->debugifc) return;
624 class_device_remove_file(sfp->class_dev, 650 if (sfp->debugifc->debuginfo_created_ok) {
625 &sfp->debugifc->attr_debuginfo); 651 class_device_remove_file(sfp->class_dev,
626 class_device_remove_file(sfp->class_dev,&sfp->debugifc->attr_debugcmd); 652 &sfp->debugifc->attr_debuginfo);
653 }
654 if (sfp->debugifc->debugcmd_created_ok) {
655 class_device_remove_file(sfp->class_dev,
656 &sfp->debugifc->attr_debugcmd);
657 }
627 kfree(sfp->debugifc); 658 kfree(sfp->debugifc);
628 sfp->debugifc = NULL; 659 sfp->debugifc = NULL;
629} 660}
@@ -645,7 +676,9 @@ static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
645 struct pvr2_sysfs_ctl_item *cip1,*cip2; 676 struct pvr2_sysfs_ctl_item *cip1,*cip2;
646 for (cip1 = sfp->item_first; cip1; cip1 = cip2) { 677 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
647 cip2 = cip1->item_next; 678 cip2 = cip1->item_next;
648 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); 679 if (cip1->created_ok) {
680 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
681 }
649 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); 682 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
650 kfree(cip1); 683 kfree(cip1);
651 } 684 }
@@ -675,8 +708,14 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
675 pvr2_sysfs_tear_down_debugifc(sfp); 708 pvr2_sysfs_tear_down_debugifc(sfp);
676#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 709#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
677 pvr2_sysfs_tear_down_controls(sfp); 710 pvr2_sysfs_tear_down_controls(sfp);
678 class_device_remove_file(sfp->class_dev,&sfp->attr_v4l_minor_number); 711 if (sfp->v4l_minor_number_created_ok) {
679 class_device_remove_file(sfp->class_dev,&sfp->attr_unit_number); 712 class_device_remove_file(sfp->class_dev,
713 &sfp->attr_v4l_minor_number);
714 }
715 if (sfp->unit_number_created_ok) {
716 class_device_remove_file(sfp->class_dev,
717 &sfp->attr_unit_number);
718 }
680 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); 719 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
681 sfp->class_dev->class_data = NULL; 720 sfp->class_dev->class_data = NULL;
682 class_device_unregister(sfp->class_dev); 721 class_device_unregister(sfp->class_dev);
@@ -709,6 +748,8 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
709{ 748{
710 struct usb_device *usb_dev; 749 struct usb_device *usb_dev;
711 struct class_device *class_dev; 750 struct class_device *class_dev;
751 int ret;
752
712 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); 753 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
713 if (!usb_dev) return; 754 if (!usb_dev) return;
714 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL); 755 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL);
@@ -733,20 +774,40 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
733 774
734 sfp->class_dev = class_dev; 775 sfp->class_dev = class_dev;
735 class_dev->class_data = sfp; 776 class_dev->class_data = sfp;
736 class_device_register(class_dev); 777 ret = class_device_register(class_dev);
778 if (ret) {
779 printk(KERN_ERR "%s: class_device_register failed\n",
780 __FUNCTION__);
781 kfree(class_dev);
782 return;
783 }
737 784
738 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE; 785 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
739 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; 786 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
740 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; 787 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
741 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; 788 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
742 sfp->attr_v4l_minor_number.store = NULL; 789 sfp->attr_v4l_minor_number.store = NULL;
743 class_device_create_file(sfp->class_dev,&sfp->attr_v4l_minor_number); 790 ret = class_device_create_file(sfp->class_dev,
791 &sfp->attr_v4l_minor_number);
792 if (ret < 0) {
793 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
794 __FUNCTION__, ret);
795 } else {
796 sfp->v4l_minor_number_created_ok = !0;
797 }
798
744 sfp->attr_unit_number.attr.owner = THIS_MODULE; 799 sfp->attr_unit_number.attr.owner = THIS_MODULE;
745 sfp->attr_unit_number.attr.name = "unit_number"; 800 sfp->attr_unit_number.attr.name = "unit_number";
746 sfp->attr_unit_number.attr.mode = S_IRUGO; 801 sfp->attr_unit_number.attr.mode = S_IRUGO;
747 sfp->attr_unit_number.show = unit_number_show; 802 sfp->attr_unit_number.show = unit_number_show;
748 sfp->attr_unit_number.store = NULL; 803 sfp->attr_unit_number.store = NULL;
749 class_device_create_file(sfp->class_dev,&sfp->attr_unit_number); 804 ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number);
805 if (ret < 0) {
806 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
807 __FUNCTION__, ret);
808 } else {
809 sfp->unit_number_created_ok = !0;
810 }
750 811
751 pvr2_sysfs_add_controls(sfp); 812 pvr2_sysfs_add_controls(sfp);
752#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 813#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC