Skip to contentSkip to conversation

net: usb: hso: use swap macro in hso_kick_transmit

PATCH Superseded Gustavo A. R. Silva 2 participants 3 messages Jul 9, 2018 – Jul 12, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: usb: hso: use swap macro in hso_kick_transmit

Make use of the swap macro and remove unnecessary variable *temp*. This makes the code easier to read and maintain. Also, slightly refactor some code due to the removal of *temp*.

This code was detected with the help of Coccinelle.

---
 drivers/net/usb/hso.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/usb/hso.c +2 -6
index de305ea..78d128e 100644
@@ -1732,7 +1732,6 @@ static int hso_serial_ioctl(struct tty_struct *tty,
 /* starts a transmit */
 static void hso_kick_transmit(struct hso_serial *serial)
 {
-	u8 *temp;
 	unsigned long flags;
 	int res;
 
@@ -1748,14 +1747,11 @@ static void hso_kick_transmit(struct hso_serial *serial)
 		goto out;
 
 	/* Switch pointers around to avoid memcpy */
-	temp = serial->tx_buffer;
-	serial->tx_buffer = serial->tx_data;
-	serial->tx_data = temp;
+	swap(serial->tx_buffer, serial->tx_data);
 	serial->tx_data_count = serial->tx_buffer_count;
 	serial->tx_buffer_count = 0;
 
-	/* If temp is set, it means we switched buffers */
-	if (temp && serial->write_data) {
+	if (serial->write_data) {
 		res = serial->write_data(serial);
 		if (res >= 0)
 			serial->tx_urb_used = 1;
maintainer
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 9 Jul 2018 10:40:48 -0500

Quoted 4 lines
drivers/net/usb/hso.c +0 -0
@@ -1748,14 +1747,11 @@ static void hso_kick_transmit(struct hso_serial *serial)
 		goto out;
 
 	/* Switch pointers around to avoid memcpy */

drivers/net/usb/hso.c static void hso_kick_transmit(struct hso_serial *serial) · line 1754

Quoted 10 lines
drivers/net/usb/hso.c +2 -5
-	temp = serial->tx_buffer;
-	serial->tx_buffer = serial->tx_data;
-	serial->tx_data = temp;
+	swap(serial->tx_buffer, serial->tx_data);
 	serial->tx_data_count = serial->tx_buffer_count;
 	serial->tx_buffer_count = 0;
 
-	/* If temp is set, it means we switched buffers */
-	if (temp && serial->write_data) {
+	if (serial->write_data) {

I think temp can be NULL here, you have to retain this check.
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Hi David,

Quoted 14 lines · David Miller

From: "Gustavo A. R. Silva" <[email protected]>
Date: Mon, 9 Jul 2018 10:40:48 -0500

Quoted 11 lines
drivers/net/usb/hso.c +1 -3
@@ -1748,14 +1747,11 @@ static void hso_kick_transmit(struct hso_serial *serial)
 		goto out;
 
 	/* Switch pointers around to avoid memcpy */
-	temp = serial->tx_buffer;
-	serial->tx_buffer = serial->tx_data;
-	serial->tx_data = temp;
+	swap(serial->tx_buffer, serial->tx_data);
 	serial->tx_data_count = serial->tx_buffer_count;
 	serial->tx_buffer_count = 0;
 
Quoted 6 lines

drivers/net/usb/hso.c static void hso_kick_transmit(struct hso_serial *serial) · line 1754

Quoted 3 lines
drivers/net/usb/hso.c +1 -2
-	/* If temp is set, it means we switched buffers */
-	if (temp && serial->write_data) {
+	if (serial->write_data) {

I think temp can be NULL here, you have to retain this check.

I see. Well, in that case I will check serial->tx_data instead.

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