Skip to contentSkip to conversation

Staging: winbond: usb_free_urb(NULL) is safe

PATCH In review Harsh Kumar 3 participants 8 messages May 30, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: winbond: usb_free_urb(NULL) is safe

usb_free_urb(NULL) is safe. So, the check was removed. Also, couple of checkpatch.pl fixes

---
 drivers/staging/winbond/phy_calibration.c |    2 +-
 drivers/staging/winbond/wb35reg.c         |   14 +++++---------
 drivers/staging/winbond/wb35rx.c          |    3 +--
 3 files changed, 7 insertions(+), 12 deletions(-)
drivers/staging/winbond/phy_calibration.c +1 -1
diff -uprN a/drivers/staging/winbond/phy_calibration.c b/drivers/staging/winbond/phy_calibration.c
@@ -296,7 +296,7 @@ void _sin_cos(s32 angle, s32 *sin, s32 *
 	}
 }
 
-static unsigned char hal_get_dxx_reg(struct hw_data *pHwData, u16 number, u32 * pValue)
+static unsigned char hal_get_dxx_reg(struct hw_data *pHwData, u16 number, u32 *pValue)
 {
 	if (number < 0x1000)
 		number += 0x1000;
drivers/staging/winbond/wb35reg.c +5 -9
diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
-   return false;
+	return false;
 }
 
 void Wb35Reg_Update(struct hw_data *pHwData,  u16 RegisterNo,  u32 RegisterValue)
@@ -206,8 +205,7 @@ unsigned char Wb35Reg_Write(struct hw_da
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
@@ -270,8 +268,7 @@ unsigned char Wb35Reg_WriteWithCallbackV
 		Wb35Reg_EP0VM_start(pHwData);
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
@@ -374,8 +371,7 @@ unsigned char Wb35Reg_Read(struct hw_dat
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
drivers/staging/winbond/wb35rx.c +1 -2
diff -uprN a/drivers/staging/winbond/wb35rx.c b/drivers/staging/winbond/wb35rx.c
@@ -343,8 +343,7 @@ void Wb35Rx_destroy(struct hw_data *pHwD
 	} while (pWb35Rx->EP3vm_state != VM_STOP);
 	msleep(10); /* Delay for waiting function exit */
 
-	if (pWb35Rx->RxUrb)
-		usb_free_urb(pWb35Rx->RxUrb);
+	usb_free_urb(pWb35Rx->RxUrb);
 	pr_debug("Wb35Rx_destroy OK\n");
 }
 
#1 lore raw

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 10 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

julia

Quoted 56 lines
drivers/staging/winbond/wb35reg.c +4 -7
 		kfree(reg_queue);
 		return false;
 	}
-   return false;
+	return false;
 }
 
 void Wb35Reg_Update(struct hw_data *pHwData,  u16 RegisterNo,  u32 RegisterValue)
@@ -206,8 +205,7 @@ unsigned char Wb35Reg_Write(struct hw_da
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
@@ -270,8 +268,7 @@ unsigned char Wb35Reg_WriteWithCallbackV
 		Wb35Reg_EP0VM_start(pHwData);
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}
@@ -374,8 +371,7 @@ unsigned char Wb35Reg_Read(struct hw_dat
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);
 		kfree(reg_queue);
 		return false;
 	}

diff -uprN a/drivers/staging/winbond/wb35rx.c b/drivers/staging/winbond/wb35rx.c

drivers/staging/winbond/wb35rx.c +1 -3
@@ -343,8 +343,7 @@ void Wb35Rx_destroy(struct hw_data *pHwD
 	} while (pWb35Rx->EP3vm_state != VM_STOP);
 	msleep(10); /* Delay for waiting function exit */
 
-	if (pWb35Rx->RxUrb)
-		usb_free_urb(pWb35Rx->RxUrb);
+	usb_free_urb(pWb35Rx->RxUrb);
 	pr_debug("Wb35Rx_destroy OK\n");
 }
 
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Harsh Kumar
Quoted 15 lines · Julia Lawall

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 10 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Quoted 4 lines

julia

Do you want that values of urb and reg_queue to be checked separately to see which has failed? That will be more logical. But, then what should be done with the knowledge of what has failed? Should there be a print or should the return value change?

Actually, the return values of these functions like Wb35Reg_BurstWrite() have not been used where these functions are called. Maybe, we need to check whether write & read are successful or not. Maybe, that also needs to be changed.

#3 lore raw
In reply to Harsh Kumar
Quoted 6 lines · Harsh Kumar
Quoted 3 lines · Julia Lawall

drivers/staging/winbond/wb35reg.c

Quoted 3 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +0 -0

02:11:35.000000000 +0530

Quoted 12 lines
Quoted 12 lines

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 7 lines
drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Quoted 8 lines
Quoted 4 lines

julia

Do you want that values of urb and reg_queue to be checked separately to see which has failed? That will be more logical. But, then what should be done with the knowledge of what has failed? Should there be a print or should the return value change?

I don't know much about the driver, so a safe thing to do would be just to keep the current semantics. When the kzalloc fails, just return false. When the usb_alloc_urb fails, just kfree and then return false.

Also, currently there is a return false at the end of the function that is dead code. Perhaps things could be reorganized so that that is not necessary. Usually, after an allocation, the if just takes care of the error case, and the fallthrough case continues in the normal way.

Quoted 3 lines

Actually, the return values of these functions like Wb35Reg_BurstWrite() have not been used where these functions are called. Maybe, we need to check whether write & read are successful or not. Maybe, that also needs to be changed.

I don't know.

julia

#4 lore raw
In reply to Harsh Kumar
Quoted 39 lines · Harsh Kumar
Quoted 36 lines · Julia Lawall
Quoted 6 lines · Harsh Kumar
Quoted 3 lines · Julia Lawall

drivers/staging/winbond/wb35reg.c

Quoted 3 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +0 -0

02:11:35.000000000 +0530

Quoted 12 lines
Quoted 12 lines

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 7 lines
drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Quoted 8 lines
Quoted 4 lines

julia

Do you want that values of urb and reg_queue to be checked separately to see which has failed? That will be more logical. But, then what should be done with the knowledge of what has failed? Should there be a print or should the return value change?

I don't know much about the driver, so a safe thing to do would be just to keep the current semantics. When the kzalloc fails, just return false. When the usb_alloc_urb fails, just kfree and then return false.

Quoted 7 lines
Quoted 5 lines

Also, currently there is a return false at the end of the function that is dead code. Perhaps things could be reorganized so that that is not necessary. Usually, after an allocation, the if just takes care of the error case, and the fallthrough case continues in the normal way.

Okay, got it. I will reorganize the stuff here.

I think that some of the other cases should be changed in the same way. It is just in the destroy function that the if was not needed.

julia

#5 lore raw
In reply to Harsh Kumar
Quoted 32 lines · Julia Lawall
Quoted 6 lines · Harsh Kumar
Quoted 3 lines · Julia Lawall

drivers/staging/winbond/wb35reg.c

Quoted 3 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +0 -0

02:11:35.000000000 +0530

Quoted 12 lines
Quoted 12 lines

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 7 lines
drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Quoted 8 lines
Quoted 4 lines

julia

Do you want that values of urb and reg_queue to be checked separately to see which has failed? That will be more logical. But, then what should be done with the knowledge of what has failed? Should there be a print or should the return value change?

Quoted 9 lines

I don't know much about the driver, so a safe thing to do would be just to keep the current semantics. When the kzalloc fails, just return false. When the usb_alloc_urb fails, just kfree and then return false.

Also, currently there is a return false at the end of the function that is dead code. Perhaps things could be reorganized so that that is not necessary. Usually, after an allocation, the if just takes care of the error case, and the fallthrough case continues in the normal way.

Okay, got it. I will reorganize the stuff here.

Quoted 7 lines
Quoted 3 lines

Actually, the return values of these functions like Wb35Reg_BurstWrite() have not been used where these functions are called. Maybe, we need to check whether write & read are successful or not. Maybe, that also needs to be changed.

I don't know.

julia

#6 lore raw
In reply to Harsh Kumar
Quoted 49 lines · Julia Lawall
Quoted 45 lines · Harsh Kumar
Quoted 41 lines · Julia Lawall
Quoted 6 lines · Harsh Kumar
Quoted 3 lines · Julia Lawall

drivers/staging/winbond/wb35reg.c

Quoted 3 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +0 -0

02:11:35.000000000 +0530

Quoted 12 lines
Quoted 12 lines

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 7 lines
drivers/staging/winbond/wb35reg.c +1 -2
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Quoted 8 lines
Quoted 4 lines

julia

Do you want that values of urb and reg_queue to be checked separately to see which has failed? That will be more logical. But, then what should be done with the knowledge of what has failed? Should there be a print or should the return value change?

I don't know much about the driver, so a safe thing to do would be just to keep the current semantics. When the kzalloc fails, just return false. When the usb_alloc_urb fails, just kfree and then return false.

Also, currently there is a return false at the end of the function that is dead code. Perhaps things could be reorganized so that that is not necessary. Usually, after an allocation, the if just takes care of the error case, and the fallthrough case continues in the normal way.

Quoted 6 lines
Quoted 1 line

Okay, got it. I will reorganize the stuff here.

I think that some of the other cases should be changed in the same way. It is just in the destroy function that the if was not needed.

julia

Yes, I understood that. I will change other cases as well. Thanks.

Harsh

Acked-by on v1 1/1
#7 lore raw
In reply to Harsh Kumar
Quoted 5 lines · Julia Lawall
Quoted 5 lines

diff -uprN a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c

drivers/staging/winbond/wb35reg.c +0 -0
@@ -64,12 +64,11 @@ unsigned char Wb35Reg_BurstWrite(struct
 
Quoted 9 lines

drivers/staging/winbond/wb35reg.c unsigned char Wb35Reg_BurstWrite(struct · line 67

Quoted 5 lines
drivers/staging/winbond/wb35reg.c +1 -2
 		return true;
 	} else {
-		if (urb)
-			usb_free_urb(urb);
+		usb_free_urb(urb);

I took a look at this case. Wouldn't it be nicer to check for failures one by one, as done almost everywhere else in the kernel? Then you would know what had been successfully allocated and what has to be freed.

Yeah, that code needs lot of improvements. No, we probably will not make it perfect by single patch.

(Original patch:)

Does someone have the hardware, BTW? I have single instance here, I need to power it up some day. It was apparently sold as an USB card, too... (I have version built-in obscure netbook).

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html