Skip to contentSkip to conversation

media: pvrusb2: fix warning in pvr2_i2c_core_done

PATCH Superseded Anirudh Rayabharam 3 participants 5 messages Apr 1, 2021 – Apr 7, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: pvrusb2: fix warning in pvr2_i2c_core_done

syzbot has reported the following warning in pvr2_i2c_done:

sysfs group 'power' not found for kobject '1-0043'

When the device is disconnected (pvr_hdw_disconnect), the i2c adapter is not unregistered along with the USB and vl42 teardown. As part of the USB device disconnect, the sysfs files of the subdevices are also deleted. So, by the time pvr_i2c_core_done is called by pvr_context_destroy, the sysfs files have been deleted.

To fix this, unregister the i2c adapter too in pvr_hdw_disconnect. Make the device deregistration code shared by calling pvr_hdw_disconnect from pvr2_hdw_destory.

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -3
index f4a727918e35..791227787ff5 100644
@@ -2676,9 +2676,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 		pvr2_stream_destroy(hdw->vid_stream);
 		hdw->vid_stream = NULL;
 	}
-	pvr2_i2c_core_done(hdw);
-	v4l2_device_unregister(&hdw->v4l2_dev);
-	pvr2_hdw_remove_usb_stuff(hdw);
+	pvr2_hdw_disconnect(hdw);
 	mutex_lock(&pvr2_unit_mtx);
 	do {
 		if ((hdw->unit_number >= 0) &&
@@ -2705,6 +2703,7 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw)
 {
 	pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_disconnect(hdw=%p)",hdw);
 	LOCK_TAKE(hdw->big_lock);
+	pvr2_i2c_core_done(hdw);
 	LOCK_TAKE(hdw->ctl_lock);
 	pvr2_hdw_remove_usb_stuff(hdw);
 	LOCK_GIVE(hdw->ctl_lock);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 45 lines · Anirudh Rayabharam

syzbot has reported the following warning in pvr2_i2c_done:

sysfs group 'power' not found for kobject '1-0043'

When the device is disconnected (pvr_hdw_disconnect), the i2c adapter is not unregistered along with the USB and vl42 teardown. As part of the USB device disconnect, the sysfs files of the subdevices are also deleted. So, by the time pvr_i2c_core_done is called by pvr_context_destroy, the sysfs files have been deleted.

To fix this, unregister the i2c adapter too in pvr_hdw_disconnect. Make the device deregistration code shared by calling pvr_hdw_disconnect from pvr2_hdw_destory.

---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -3
index f4a727918e35..791227787ff5 100644
@@ -2676,9 +2676,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 		pvr2_stream_destroy(hdw->vid_stream);
 		hdw->vid_stream = NULL;
 	}
-	pvr2_i2c_core_done(hdw);
-	v4l2_device_unregister(&hdw->v4l2_dev);
-	pvr2_hdw_remove_usb_stuff(hdw);
+	pvr2_hdw_disconnect(hdw);
 	mutex_lock(&pvr2_unit_mtx);
 	do {
 		if ((hdw->unit_number >= 0) &&
@@ -2705,6 +2703,7 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw)
 {
 	pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_disconnect(hdw=%p)",hdw);
 	LOCK_TAKE(hdw->big_lock);
+	pvr2_i2c_core_done(hdw);
 	LOCK_TAKE(hdw->ctl_lock);
 	pvr2_hdw_remove_usb_stuff(hdw);
 	LOCK_GIVE(hdw->ctl_lock);
Signature · 1 line
2.26.2

Looks sane to me, nice work tracking this down.

#2 lore raw
In reply to Anirudh Rayabharam
Quoted 6 lines · Anirudh Rayabharam

syzbot has reported the following warning in pvr2_i2c_done:

sysfs group 'power' not found for kobject '1-0043'

When the device is disconnected (pvr_hdw_disconnect), the i2c adapter is not unregistered along with the USB and vl42 teardown. As part of the

vl42 -> v4l2

Quoted 7 lines

USB device disconnect, the sysfs files of the subdevices are also deleted. So, by the time pvr_i2c_core_done is called by pvr_context_destroy, the sysfs files have been deleted.

To fix this, unregister the i2c adapter too in pvr_hdw_disconnect. Make the device deregistration code shared by calling pvr_hdw_disconnect from pvr2_hdw_destory.

destory -> destroy

Quoted 12 lines
---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index f4a727918e35..791227787ff5 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c void pvr2_hdw_destroy(struct pvr2_hdw *hdw) · line 2680

Quoted 5 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -2
@@ -2676,9 +2676,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 		pvr2_stream_destroy(hdw->vid_stream);
 		hdw->vid_stream = NULL;
 	}
-	pvr2_i2c_core_done(hdw);
-	v4l2_device_unregister(&hdw->v4l2_dev);

I think this should still remain since pvr2_hdw_disconnect() doesn't call v4l2_device_unregister().

Can you test that with syzbot?

Regards,

Hans

Quoted 14 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
-	pvr2_hdw_remove_usb_stuff(hdw);
+	pvr2_hdw_disconnect(hdw);
 	mutex_lock(&pvr2_unit_mtx);
 	do {
 		if ((hdw->unit_number >= 0) &&
@@ -2705,6 +2703,7 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw)
 {
 	pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_disconnect(hdw=%p)",hdw);
 	LOCK_TAKE(hdw->big_lock);
+	pvr2_i2c_core_done(hdw);
 	LOCK_TAKE(hdw->ctl_lock);
 	pvr2_hdw_remove_usb_stuff(hdw);
 	LOCK_GIVE(hdw->ctl_lock);
#3 lore raw
Quoted 14 lines · Hans Verkuil
Quoted 6 lines · Anirudh Rayabharam

syzbot has reported the following warning in pvr2_i2c_done:

sysfs group 'power' not found for kobject '1-0043'

When the device is disconnected (pvr_hdw_disconnect), the i2c adapter is not unregistered along with the USB and vl42 teardown. As part of the

vl42 -> v4l2

Quoted 4 lines

USB device disconnect, the sysfs files of the subdevices are also deleted. So, by the time pvr_i2c_core_done is called by pvr_context_destroy, the sysfs files have been deleted.

Quoted 6 lines
Quoted 3 lines

To fix this, unregister the i2c adapter too in pvr_hdw_disconnect. Make the device deregistration code shared by calling pvr_hdw_disconnect from pvr2_hdw_destory.

destory -> destroy

Ack, will fix these typos in v2.

Quoted 7 lines
Quoted 7 lines
---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 13 lines

drivers/media/usb/pvrusb2/pvrusb2-hdw.c void pvr2_hdw_destroy(struct pvr2_hdw *hdw) · line 2680

Quoted 10 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -2
index f4a727918e35..791227787ff5 100644
@@ -2676,9 +2676,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 		pvr2_stream_destroy(hdw->vid_stream);
 		hdw->vid_stream = NULL;
 	}
-	pvr2_i2c_core_done(hdw);
-	v4l2_device_unregister(&hdw->v4l2_dev);

I think this should still remain since pvr2_hdw_disconnect() doesn't call v4l2_device_unregister().

Then we might run into the same warning again. pvr2_hdw_disconnect() calls pvr2_hdw_remove_usb_stuff() which calls v4l2_device_disconnect(). Perhaps there we should call v4l2_device_unregister() instead?

Quoted 2 lines

Can you test that with syzbot?

Will do.

Thanks!

- Anirudh.

Quoted 20 lines

Regards,

Hans

Quoted 14 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +2 -1
-	pvr2_hdw_remove_usb_stuff(hdw);
+	pvr2_hdw_disconnect(hdw);
 	mutex_lock(&pvr2_unit_mtx);
 	do {
 		if ((hdw->unit_number >= 0) &&
@@ -2705,6 +2703,7 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw)
 {
 	pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_disconnect(hdw=%p)",hdw);
 	LOCK_TAKE(hdw->big_lock);
+	pvr2_i2c_core_done(hdw);
 	LOCK_TAKE(hdw->ctl_lock);
 	pvr2_hdw_remove_usb_stuff(hdw);
 	LOCK_GIVE(hdw->ctl_lock);
#4 lore raw
In reply to Hans Verkuil
Quoted 41 lines · Hans Verkuil
Quoted 6 lines · Anirudh Rayabharam

syzbot has reported the following warning in pvr2_i2c_done:

sysfs group 'power' not found for kobject '1-0043'

When the device is disconnected (pvr_hdw_disconnect), the i2c adapter is not unregistered along with the USB and vl42 teardown. As part of the

vl42 -> v4l2

Quoted 7 lines

USB device disconnect, the sysfs files of the subdevices are also deleted. So, by the time pvr_i2c_core_done is called by pvr_context_destroy, the sysfs files have been deleted.

To fix this, unregister the i2c adapter too in pvr_hdw_disconnect. Make the device deregistration code shared by calling pvr_hdw_disconnect from pvr2_hdw_destory.

destory -> destroy

Quoted 12 lines
---
 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -0
index f4a727918e35..791227787ff5 100644

drivers/media/usb/pvrusb2/pvrusb2-hdw.c void pvr2_hdw_destroy(struct pvr2_hdw *hdw) · line 2680

Quoted 5 lines
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +0 -2
@@ -2676,9 +2676,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
 		pvr2_stream_destroy(hdw->vid_stream);
 		hdw->vid_stream = NULL;
 	}
-	pvr2_i2c_core_done(hdw);
-	v4l2_device_unregister(&hdw->v4l2_dev);

I think this should still remain since pvr2_hdw_disconnect() doesn't call v4l2_device_unregister().

Quoted 1 line

Can you test that with syzbot?

Sent v2 with this change. Tested it with syzbot and didn't find any problems.

Thanks.

- Anirudh.