media: pvrusb2: fix null-ptr-deref in class_unregister()
authorKefeng Wang <wangkefeng.wang@huawei.com>
Wed, 5 Jun 2019 13:08:20 +0000 (09:08 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Wed, 5 Jun 2019 19:57:46 +0000 (15:57 -0400)
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.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/usb/pvrusb2/pvrusb2-sysfs.c

index 7bc6d09..b6c6b31 100644 (file)
@@ -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);
 }