Skip to contentSkip to conversation

Expected video_unregister_device behavior.

DISCUSSION David Ellingsworth 1 participant 2 messages Jun 26, 2008 – Jun 27, 2008 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

It is my understanding that video_unregister_device is responsible for removing the /dev/video* device from the system. To this regard, I have seen a lot of usb camera drivers calling video_unregister_device in the usb disconnect callback to ensure that no one subsequently tries to open the device again. Mimicking the existing drivers, I did the same. What I found was that calling video_unregister_device resulted in calling the release function of the video_device structure despite the fact the device was still open. The log from my tests showed the following:

usb_probe_callback
- video_register_device called
video_open_callback - This seem to happen automatically upon video_register_device
video_close_callback - same as above
video_open_callback - caused by application open usb_disconnect_callback
- device physically disconnected
- calls video_unregister_device to prevent future opens
video_release_callback
- called as a result of video_unregister_device but the device is
still open!
video_close_callback
- application noticed read error and closed device

I have not yet looked to see why the video_release_callback is being called after video_unregister_device is called, but I would have expected it not to have been called until after the final video_close_callback has been issued. My question, is therefore, is this the desired behavior? Should a call to video_unregister_device immediately cause the video_release_callback to be called?

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#1 lore raw
Quoted 25 lines · David Ellingsworth

It is my understanding that video_unregister_device is responsible for removing the /dev/video* device from the system. To this regard, I have seen a lot of usb camera drivers calling video_unregister_device in the usb disconnect callback to ensure that no one subsequently tries to open the device again. Mimicking the existing drivers, I did the same. What I found was that calling video_unregister_device resulted in calling the release function of the video_device structure despite the fact the device was still open. The log from my tests showed the following:

usb_probe_callback
- video_register_device called
video_open_callback - This seem to happen automatically upon video_register_device
video_close_callback - same as above
video_open_callback - caused by application open usb_disconnect_callback
- device physically disconnected
- calls video_unregister_device to prevent future opens
video_release_callback
- called as a result of video_unregister_device but the device is
still open!
video_close_callback
- application noticed read error and closed device

Quoted 7 lines

I have not yet looked to see why the video_release_callback is being called after video_unregister_device is called, but I would have expected it not to have been called until after the final video_close_callback has been issued. My question, is therefore, is this the desired behavior? Should a call to video_unregister_device immediately cause the video_release_callback to be called?

I just wanted to follow up on this as I've found a work-around for the issue I was experiencing.

I had been using video_devdata(file) inside of close to retrieve the video device data from the file as I thought this was the preferred method. In the case above the return value of video_devdata in the final close is NULL. To overcome this limitation I set file->private_data in the open callback to my internal struct so I could retrieve it during the final close. Thus, giving the opportunity to properly free the struct. I suspect other drivers may have the same issue, but I have not investigated them as of yet.

Regards,

David Ellingsworth

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list