Skip to contentSkip to conversation

media: pvrusb2: fix null-ptr-deref in class_unregister()

PATCH In review Kefeng Wang 2 participants 2 messages Jun 5, 2019 – Jun 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: pvrusb2: fix null-ptr-deref in class_unregister()

The class_ptr will be NULL if pvr2_sysfs_class_create() fails in pvr_init(), when call pvr2_sysfs_class_destroy(), it will lead to null-ptr-deref, fix it.

---
 drivers/media/usb/pvrusb2/pvrusb2-sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-sysfs.c +2 -1
index 7bc6d090358e..b6c6b314fadc 100644
@@ -802,7 +802,8 @@ struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
 {
 	pvr2_sysfs_trace("Unregistering pvr2_sysfs_class id=%p", clp);
-	class_unregister(&clp->class);
+	if (clp)
+		class_unregister(&clp->class);
 }
 
 
Signature · 1 line
2.20.1
Acked-by Mike Isely on v1 1/1
#1 lore raw
Quoted 25 lines · Kefeng Wang

The class_ptr will be NULL if pvr2_sysfs_class_create() fails in pvr_init(), when call pvr2_sysfs_class_destroy(), it will lead to null-ptr-deref, fix it.

---
 drivers/media/usb/pvrusb2/pvrusb2-sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/pvrusb2/pvrusb2-sysfs.c +2 -1
index 7bc6d090358e..b6c6b314fadc 100644
@@ -802,7 +802,8 @@ struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
 {
 	pvr2_sysfs_trace("Unregistering pvr2_sysfs_class id=%p", clp);
-	class_unregister(&clp->class);
+	if (clp)
+		class_unregister(&clp->class);
 }
 
 
Signature · 3 lines
Mike Isely
isely @ isely (dot) net
PGP: 03 54 43 4D 75 E5 CC 92 71 16 01 E2 B5 F5 C1 E8