media: usb: fix memory leak in stk_camera_probe
PATCH 1/1 media: usb: fix memory leak in stk_camera_probe
stk_camera_probe mistakenly execute usb_get_intf and increase the refcount of interface->dev.
Fix this by removing the execution of usb_get_intf.
--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/usb/stkwebcam/stk-webcam.c +0 -1
@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface, dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);if (hflip !=-1 ) dev->vsettings.hflip = hflip;
Signature · 1 line
2.25.1
Quoted 5 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.
Any idea about this patch?
Quoted 23 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-2@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface, dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);if (hflip !=-1 ) dev->vsettings.hflip = hflip; --2.25.1
Quoted 9 lines · Dongliang Mu
Quoted 5 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
Quoted 24 lines
Quoted 24 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-2@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface, dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);if (hflip !=-1 ) dev->vsettings.hflip = hflip; --2.25.1
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
thanks,
greg k-h
Mauro Carvalho Chehab
maintainerEm Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:
Quoted 10 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 8 lines · Dongliang Mu
Quoted 5 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
It should be properly tracked, and likely handled after the end of the merge window.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>
If you're the author of the patch, it doesn't make much sense to add a "Reported-by:" tag there. We only use it in order to give someone's else credit to report an issue.
Thanks,
Mauro
Quoted 31 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 10 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 8 lines · Dongliang Mu
Quoted 5 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>If you're the author of the patch, it doesn't make much sense to add a "Reported-by:" tag there. We only use it in order to give someone's else credit to report an issue.
I see. Someone told me this rule in another thread. I will update this in the next version.
Quoted 3 lines
Thanks,
Mauro
Quoted 25 lines · Dongliang Mu
Quoted 23 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 18 lines · Dongliang Mu
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
Quoted 7 lines
Quoted 7 lines
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Hi Mauro,
I found there is another fix [1] for the same memory leak from Pavel Skripkin (already cc-ed in this thread).
[1] https://www.spinics.net/lists/stable/msg479628.html
Quoted 15 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>If you're the author of the patch, it doesn't make much sense to add a "Reported-by:" tag there. We only use it in order to give someone's else credit to report an issue.
I see. Someone told me this rule in another thread. I will update this in the next version.
Quoted 3 lines
Thanks,
Mauro
Quoted 34 lines · Dongliang Mu
Quoted 25 lines · Dongliang Mu
Quoted 23 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 18 lines · Dongliang Mu
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
Quoted 7 lines
Quoted 7 lines
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Quoted 6 lines
Hi Mauro,
I found there is another fix [1] for the same memory leak from Pavel Skripkin (already cc-ed in this thread).
Ah, that's why I marked it as Obsoleted :-)
Regards,
Hans
Quoted 16 lines
Quoted 16 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>If you're the author of the patch, it doesn't make much sense to add a "Reported-by:" tag there. We only use it in order to give someone's else credit to report an issue.
I see. Someone told me this rule in another thread. I will update this in the next version.
Quoted 3 lines
Thanks,
Mauro
Quoted 36 lines · Hans Verkuil
Quoted 34 lines · Dongliang Mu
Quoted 32 lines · Dongliang Mu
Quoted 30 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 10 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 8 lines · Dongliang Mu
Quoted 5 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Quoted 8 lines
Quoted 6 lines
Hi Mauro,
I found there is another fix [1] for the same memory leak from Pavel Skripkin (already cc-ed in this thread).
Ah, that's why I marked it as Obsoleted :-)
Oh, I see. If that patch is already merged, please remark my patch as Obsoleted.
Curiously, I did not get an email notification to mark my patch as Obsoleted before. Why?
Quoted 22 lines
Regards,
Hans
Quoted 16 lines
Quoted 16 lines
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>If you're the author of the patch, it doesn't make much sense to add a "Reported-by:" tag there. We only use it in order to give someone's else credit to report an issue.
I see. Someone told me this rule in another thread. I will update this in the next version.
Quoted 3 lines
Thanks,
Mauro
Quoted 42 lines · Dongliang Mu
Quoted 41 lines · Hans Verkuil
Quoted 39 lines · Dongliang Mu
Quoted 25 lines · Dongliang Mu
Quoted 23 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 18 lines · Dongliang Mu
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
Quoted 7 lines
Quoted 7 lines
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Hi Mauro,
I found there is another fix [1] for the same memory leak from Pavel Skripkin (already cc-ed in this thread).
Quoted 10 lines
Quoted 3 lines
Quoted 1 line
Ah, that's why I marked it as Obsoleted :-)
Oh, I see. If that patch is already merged, please remark my patch as Obsoleted.
Curiously, I did not get an email notification to mark my patch as Obsoleted before. Why?
Quoted 1 line
Hi, Dongliang!
Yep my patch has been merged already (1 month ago, I guess).
With regards,
Pavel Skripkin
Quoted 50 lines · Pavel Skripkin
Quoted 48 lines · Dongliang Mu
Quoted 36 lines · Hans Verkuil
Quoted 34 lines · Dongliang Mu
Quoted 32 lines · Dongliang Mu
Quoted 30 lines · Mauro Carvalho Chehab
Em Thu, 2 Sep 2021 12:39:37 +0200
Greg KH <[email protected]> escreveu:Quoted 10 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 8 lines · Dongliang Mu
Quoted 5 lines
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
This is the media developers domain, not much I can do here.
There is a high volume of patches for the media subsystem. Anyway, as your patch is at our patchwork instance:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/It should be properly tracked, and likely handled after the end of the merge window.
Quoted 8 lines
Quoted 6 lines
Hi Mauro,
I found there is another fix [1] for the same memory leak from Pavel Skripkin (already cc-ed in this thread).
Ah, that's why I marked it as Obsoleted :-)
Oh, I see. If that patch is already merged, please remark my patch as Obsoleted.
Quoted 8 lines
Quoted 4 lines
Curiously, I did not get an email notification to mark my patch as Obsoleted before. Why?
Quoted 1 line
Hi, Dongliang!
Yep my patch has been merged already (1 month ago, I guess).
Yes. When I submit this patch, your patch is still pending. I did not know someone is already sending a patch with good quality.
So I am curious if there are any methods to notify people there are already some similar patches in the patchwork or some other resources.
Quoted 6 lines
With regards,
Pavel Skripkin
Hi Dongliang,
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
I saw that it was marked as Obsoleted in patchwork, but I might have confused this patch with similar, but not identical, patches for this driver.
I've moved the state back to New.
Comments follow below:
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-0@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface,
Quoted 3 lines
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c static int stk_camera_probe(struct usb_interface *interface, · line 1314
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);
Even though this increments the refcount (which might well be unnecessary), it is also decremented with usb_put_intf. So is there actually a bug here?
And if this is changed, then I expect that both get_intf and put_intf should be removed, and not just the get.
Regards,
Hans
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1if (hflip !=-1 ) dev->vsettings.hflip = hflip; --2.25.1
Quoted 43 lines · Hans Verkuil
Hi Dongliang,
Quoted 7 lines · Dongliang Mu
Quoted 6 lines · Dongliang Mu
Quoted 4 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
I saw that it was marked as Obsoleted in patchwork, but I might have confused this patch with similar, but not identical, patches for this driver.
I've moved the state back to New.
Comments follow below:
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-0@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface,
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c static int stk_camera_probe(struct usb_interface *interface, · line 1314
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);Even though this increments the refcount (which might well be unnecessary), it is also decremented with
usb_put_intf. So is there actually a bug here?
Yes, if the increment and decrement of refcount are balanced, it's fine.
But this probe function only increases the refcount, but forgets to decrease the refcount.
Quoted 14 lines
And if this is changed, then I expect that both
get_intfandput_intfshould be removed, and not just the get.Regards,
Hans
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1if (hflip !=-1 ) dev->vsettings.hflip = hflip; --2.25.1
Quoted 31 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 5 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
Quoted 15 lines
Quoted 15 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-0@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface,
Quoted 3 lines
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c static int stk_camera_probe(struct usb_interface *interface, · line 1314
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);
The patch is wrong. We're storing a reference to "interface".
dev->interface = interface;
So we need to boost the refcount of interface. Pavel Skripkin was on the right patch but you need to add a:
usb_put_intf(interface);
to the stk_camera_disconnect() function as you sort of mentioned. That's the correct fix.
regards,
dan carpenter
Quoted 42 lines · Dan Carpenter
Quoted 31 lines · Dongliang Mu
Quoted 9 lines · Dongliang Mu
Quoted 5 lines · Dongliang Mu
stk_camera_probemistakenly executeusb_get_intfand increase the refcount ofinterface->dev.Fix this by removing the execution of
usb_get_intf.Any idea about this patch?
+cc Dan Carpenter, gregkh
There is no reply in this thread in one month. Can someone give some feedback on this patch?
Quoted 15 lines
Quoted 15 lines
Reported-by Dongliang Mu <[email protected]>Fixes 0aa77f6c2954 ("[media] move the remaining USB drivers to drivers/media/usb")Signed-off-by Dongliang Mu <[email protected]>--- drivers/media/usb/stkwebcam/stk-webcam.c | 1 - 1 file changed, 1 deletion(-)drivers/media/usb/stkwebcam/stk-webcam.c +0
-0@@ -1311,7 +1311,6 @@ static int stk_camera_probe(struct usb_interface *interface,Quoted 3 lines
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c static int stk_camera_probe(struct usb_interface *interface, · line 1314
Quoted 3 lines
drivers/media/usb/stkwebcam/stk-webcam.c +0
-1dev->udev = udev; dev->interface = interface; -usb_get_intf (interface);The patch is wrong. We're storing a reference to "interface".
dev->interface = interface;
Quoted 7 lines
So we need to boost the refcount of interface. Pavel Skripkin was on the right patch but you need to add a:
usb_put_intf(interface);to the
stk_camera_disconnect()function as you sort of mentioned. That's the correct fix.
Thanks for your explanation, Dan. It's really helpful.
I sent the inquiry email in this thread because I did not receive the notification of patchwork to mark my patch as obsolete and did not notice Pavel had sent one patch before.
Now, this patch is marked as obsolete. Let's ignore it now.
Quoted 3 lines
regards,
dan carpenter