dib0700: Drop useless check when remote key is pressed
PATCH 1/2 dib0700: Drop useless check when remote key is pressed
struct dvb_usb_device *d can never be NULL so don't waste time checking for this.
Rationale: the urb's context is set when usb_fill_bulk_urb() is called in dib0700_rc_setup(), and never changes after that. d is dereferenced unconditionally in dib0700_rc_setup() so it can't be NULL or the driver would crash right away.
---
Devin, am I missing something?
drivers/media/dvb/dvb-usb/dib0700_core.c | 3 --- 1 file changed, 3 deletions(-)
drivers/media/dvb/dvb-usb/dib0700_core.c +0 -3
@@ -677,9 +677,6 @@ static void dib0700_rc_urb_completion(stu8 toggle;deb_info ("%s()\n" , __func__); -if (d ==NULL ) -return ; -if (d->rc_dev ==NULL ) {/* This will occur if disable_rc_polling=1 */ usb_free_urb (purb);
Signature · 1 line
Jean Delvare
Quoted 8 lines · Jean Delvare
struct
dvb_usb_device*d can never be NULL so don't waste time checking for this.Rationale: the urb's context is set when
usb_fill_bulk_urb()is called indib0700_rc_setup(), and never changes after that. d is dereferenced unconditionally indib0700_rc_setup()so it can't be NULL or the driver would crash right away.
Quoted 5 lines
Signed-off-by Jean Delvare <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Devin Heitmueller <[email protected]>---
Devin, am I missing something?
I think this was just a case of defensive coding where I didn't want to dereference something without validating the pointer first (out of fear that it got called through some other code path that I didn't consider).
Devin
Signature · 2 lines
Devin J. Heitmueller - Kernel Labs http://www.kernellabs.com
Em 13-03-2012 14:57, Devin Heitmueller escreveu:
Quoted 25 lines · Jean Delvare
Quoted 8 lines
struct
dvb_usb_device*d can never be NULL so don't waste time checking for this.Rationale: the urb's context is set when
usb_fill_bulk_urb()is called indib0700_rc_setup(), and never changes after that. d is dereferenced unconditionally indib0700_rc_setup()so it can't be NULL or the driver would crash right away.Quoted 5 lines
Signed-off-by Jean Delvare <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Devin Heitmueller <[email protected]>---
Devin, am I missing something?I think this was just a case of defensive coding where I didn't want to dereference something without validating the pointer first (out of fear that it got called through some other code path that I didn't consider).
Quoted 5 lines
drivers/media/dvb/dvb-usb/dib0700_core.c +0
-0@@ -677,9 +677,6 @@ static void dib0700_rc_urb_completion(stu8 toggle;
Quoted 4 lines
drivers/media/dvb/dvb-usb/dib0700_core.c static void dib0700_rc_urb_completion(st · line 682
Quoted 4 lines
drivers/media/dvb/dvb-usb/dib0700_core.c +0
-3deb_info ("%s()\n" , __func__); -if (d ==NULL ) -return ; -
Well, usb_free_urb() is not called when d == NULL, so, if this condition ever happens, it will keep URB's allocated.
Anyway, if struct dvb_usb_device *d is NULL, the driver has something very wrong happening on it, and nothing will work on it.
I agree with Jean: it is better to just remove this code there.
Yet, I'd be more happy if Jean's patch could check first if the status is below 0, in order to prevent a possible race condition at device disconnect.
Regards,
Mauro
Hi Mauro,
Quoted 14 lines · Mauro Carvalho Chehab
drivers/media/dvb/dvb-usb/dib0700_core.c static void dib0700_rc_urb_completion(st · line 682
Quoted 9 lines · Jean Delvare
drivers/media/dvb/dvb-usb/dib0700_core.c +0
-3@@ -677,9 +677,6 @@ static void dib0700_rc_urb_completion(stu8 toggle;deb_info ("%s()\n" , __func__); -if (d ==NULL ) -return ; -Well,
usb_free_urb()is not called when d == NULL, so, if this condition ever happens, it will keep URB's allocated.
Quoted 7 lines
Anyway, if struct
dvb_usb_device*d is NULL, the driver has something very wrong happening on it, and nothing will work on it.I agree with Jean: it is better to just remove this code there.
Yet, I'd be more happy if Jean's patch could check first if the status is below 0, in order to prevent a possible race condition at device disconnect.
I'm not sure I see the race condition you're seeing. Do you believe purb->context would be NULL (or point to already-freed memory) when dib0700_rc_urb_completion is called as part of device disconnect? Or is it something else? I'll be happy to resubmit my patch series with a fix if you explain where you think there is a race condition.
Signature · 1 line
Jean Delvare
Em 20-03-2012 04:20, Jean Delvare escreveu:
Quoted 22 lines
Hi Mauro,
Quoted 19 lines · Mauro Carvalho Chehab
drivers/media/dvb/dvb-usb/dib0700_core.c static void dib0700_rc_urb_completion(st · line 682
Quoted 9 lines · Jean Delvare
drivers/media/dvb/dvb-usb/dib0700_core.c +0
-3@@ -677,9 +677,6 @@ static void dib0700_rc_urb_completion(stu8 toggle;deb_info ("%s()\n" , __func__); -if (d ==NULL ) -return ; -Well,
usb_free_urb()is not called when d == NULL, so, if this condition ever happens, it will keep URB's allocated.Anyway, if struct
dvb_usb_device*d is NULL, the driver has something very wrong happening on it, and nothing will work on it.I agree with Jean: it is better to just remove this code there.
Quoted 9 lines
Quoted 2 lines
Yet, I'd be more happy if Jean's patch could check first if the status is below 0, in order to prevent a possible race condition at device disconnect.
I'm not sure I see the race condition you're seeing. Do you believe
purb->contextwould be NULL (or point to already-freed memory) whendib0700_rc_urb_completionis called as part of device disconnect? Or is it something else? I'll be happy to resubmit my patch series with a fix if you explain where you think there is a race condition.
What I'm saying is that the only potential chance of having a NULL value for d is at the device disconnect/removal, if is there any bug when waiting for the URB's to be killed.
So, it would be better to invert the error test logic to:
static void dib0700_rc_urb_completion(struct urb *purb)
{
struct dvb_usb_device *d = purb->context;
struct dib0700_rc_response *poll_reply;
u32 uninitialized_var(keycode);
u8 toggle;
poll_reply = purb->transfer_buffer;
if (purb->status < 0) {
deb_info("discontinuing polling\n");
kfree(purb->transfer_buffer);
usb_free_urb(purb);
return;
}
deb_info("%s()\n", __func__);
if (d->rc_dev == NULL) {
/* This will occur if disable_rc_polling=1 */
kfree(purb->transfer_buffer);
usb_free_urb(purb);
return;
}As, at device disconnect/completion, the status will indicate an error, and the function will return before trying to de-referenciate rc_dev.
Regards,
Mauro
Hi Mauro,
Quoted 40 lines · Mauro Carvalho Chehab
Em 20-03-2012 04:20, Jean Delvare escreveu:
Quoted 9 lines · Mauro Carvalho Chehab
Quoted 2 lines
Yet, I'd be more happy if Jean's patch could check first if the status is below 0, in order to prevent a possible race condition at device disconnect.
I'm not sure I see the race condition you're seeing. Do you believe
purb->contextwould be NULL (or point to already-freed memory) whendib0700_rc_urb_completionis called as part of device disconnect? Or is it something else? I'll be happy to resubmit my patch series with a fix if you explain where you think there is a race condition.What I'm saying is that the only potential chance of having a NULL value for d is at the device disconnect/removal, if is there any bug when waiting for the URB's to be killed.
So, it would be better to invert the error test logic to:
static void
dib0700_rc_urb_completion(struct urb *purb){ struct dvb_usb_device *d = purb->context; struct dib0700_rc_response *poll_reply; u32 uninitialized_var(keycode); u8 toggle; poll_reply = purb->transfer_buffer; if (purb->status < 0) { deb_info("discontinuing polling\n"); kfree(purb->transfer_buffer); usb_free_urb(purb); return; } deb_info("%s()\n", __func__); if (d->rc_dev == NULL) { /* This will occur if disable_rc_polling=1 */ kfree(purb->transfer_buffer); usb_free_urb(purb); return; }
Quoted 2 lines
As, at device disconnect/completion, the status will indicate an error, and the function will return before trying to de-referenciate
rc_dev.
Hmm. I couldn't find any code that would reset purb->context. I tested 2000 rmmod dvb-usb-dib0700 on a 3.3.0 kernel with my two patches applied, compiled with CONFIG_DEBUG_SLAB=y and CONFIG_DEBUG_VM=y, and it did not crash nor report any problem. I don't think there is any race here, so I see no point in changing the code. We just got rid of a paranoid check, it is not to apply another paranoid patch.
Signature · 1 line
Jean Delvare