Skip to contentSkip to conversation

tty: ipwireless: fix error handling

PATCH Superseded Tong Zhang 3 participants 6 messages Aug 16, 2020 – Aug 21, 2020 TTY layer and serial drivers

lore
Share & tools
lore

Tong Zhang

author
#0 lore raw

PATCH 1/1 tty: ipwireless: fix error handling

ipwireless_send_packet() can only return 0 on success and -ENOMEM on error, the caller should check non zero for error condition

---
 drivers/tty/ipwireless/network.c | 4 ++--
 drivers/tty/ipwireless/tty.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/ipwireless/network.c +2 -2
index cf20616340a1..b6f677f4004c 100644
@@ -117,7 +117,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       skb->len,
 					       notify_packet_sent,
 					       network);
-			if (ret == -1) {
+			if (ret != 0) {
 				skb_pull(skb, 2);
 				return 0;
 			}
@@ -134,7 +134,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       notify_packet_sent,
 					       network);
 			kfree(buf);
-			if (ret == -1)
+			if (ret != 0)
 				return 0;
 		}
 		kfree_skb(skb);
drivers/tty/ipwireless/tty.c +1 -1
index fad3401e604d..0230e0fd3937 100644
@@ -218,7 +218,7 @@ static int ipw_write(struct tty_struct *linux_tty,
 	ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
 			       buf, count,
 			       ipw_write_packet_sent_callback, tty);
-	if (ret == -1) {
+	if (ret != 0) {
 		mutex_unlock(&tty->ipw_tty_mutex);
 		return 0;
 	}
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 14 lines · Tong Zhang

ipwireless_send_packet() can only return 0 on success and -ENOMEM on error, the caller should check non zero for error condition

---
 drivers/tty/ipwireless/network.c | 4 ++--
 drivers/tty/ipwireless/tty.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/ipwireless/network.c +0 -0
index cf20616340a1..b6f677f4004c 100644

drivers/tty/ipwireless/network.c static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel, · line 120

Quoted 5 lines
drivers/tty/ipwireless/network.c +1 -1
@@ -117,7 +117,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       skb->len,
 					       notify_packet_sent,
 					       network);
-			if (ret == -1) {
+			if (ret != 0) {

More consistent (with the rest of the kernel), would be to check "< 0" in all the places.

Quoted 26 lines
drivers/tty/ipwireless/network.c +1 -1
 				skb_pull(skb, 2);
 				return 0;
 			}
@@ -134,7 +134,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       notify_packet_sent,
 					       network);
 			kfree(buf);
-			if (ret == -1)
+			if (ret != 0)
 				return 0;
 		}
 		kfree_skb(skb);
drivers/tty/ipwireless/tty.c +1 -1
index fad3401e604d..0230e0fd3937 100644
@@ -218,7 +218,7 @@ static int ipw_write(struct tty_struct *linux_tty,
 	ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
 			       buf, count,
 			       ipw_write_packet_sent_callback, tty);
-	if (ret == -1) {
+	if (ret != 0) {
 		mutex_unlock(&tty->ipw_tty_mutex);
 		return 0;
 	}
Signature · 2 lines
js
suse labs
author
#2 lore raw

PATCH v2 1/1 tty: ipwireless: fix error handling

ipwireless_send_packet() can only return 0 on success and -ENOMEM on error, the caller should check non zero for error condition

v2: - According to Jiri's comment, I made the checking consistent with the rest of the kernel. I also rebased the code using f684668a24ec. Thank you Jiri!

---
 drivers/tty/ipwireless/network.c | 4 ++--
 drivers/tty/ipwireless/tty.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/ipwireless/network.c +2 -2
index cf20616340a1..fe569f6294a2 100644
@@ -117,7 +117,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       skb->len,
 					       notify_packet_sent,
 					       network);
-			if (ret == -1) {
+			if (ret < 0) {
 				skb_pull(skb, 2);
 				return 0;
 			}
@@ -134,7 +134,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       notify_packet_sent,
 					       network);
 			kfree(buf);
-			if (ret == -1)
+			if (ret < 0)
 				return 0;
 		}
 		kfree_skb(skb);
drivers/tty/ipwireless/tty.c +1 -1
index fad3401e604d..23584769fc29 100644
@@ -218,7 +218,7 @@ static int ipw_write(struct tty_struct *linux_tty,
 	ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
 			       buf, count,
 			       ipw_write_packet_sent_callback, tty);
-	if (ret == -1) {
+	if (ret < 0) {
 		mutex_unlock(&tty->ipw_tty_mutex);
 		return 0;
 	}
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#3 lore raw
Quoted 2 lines · Tong Zhang

ipwireless_send_packet() can only return 0 on success and -ENOMEM on error, the caller should check non zero for error condition

Thanks.

---

Quoted 3 lines

v2: - According to Jiri's comment, I made the checking consistent with the rest of the kernel. I also rebased the code using f684668a24ec. Thank you Jiri!

---

This paragraph should not be in the changelog. The patches to ipwireless go via Greg's tree, please send an updated v3 so he can just apply that without further edits. Thanks.

author
#4 lore raw
Quoted 3 lines · David Sterba

This paragraph should not be in the changelog. The patches to ipwireless go via Greg's tree, please send an updated v3 so he can just apply that without further edits. Thanks.

Thanks David! I've made another patch - hope this one works.

author
#5 lore raw

PATCH v3 1/1 tty: ipwireless: fix error handling

In reply to David Sterba

ipwireless_send_packet() can only return 0 on success and -ENOMEM on error, the caller should check non zero for error condition

---

v2: - According to Jiri's comment, I made the checking consistent with the rest of the kernel. I also rebased the code using f684668a24ec. Thank you Jiri!
v3: fix commit log according to David's comment, and rebased using Greg's tty-testing tree. Thank you David!

 drivers/tty/ipwireless/network.c | 4 ++--
 drivers/tty/ipwireless/tty.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/ipwireless/network.c +2 -2
index cf20616340a1..fe569f6294a2 100644
@@ -117,7 +117,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       skb->len,
 					       notify_packet_sent,
 					       network);
-			if (ret == -1) {
+			if (ret < 0) {
 				skb_pull(skb, 2);
 				return 0;
 			}
@@ -134,7 +134,7 @@ static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
 					       notify_packet_sent,
 					       network);
 			kfree(buf);
-			if (ret == -1)
+			if (ret < 0)
 				return 0;
 		}
 		kfree_skb(skb);
drivers/tty/ipwireless/tty.c +1 -1
index fad3401e604d..23584769fc29 100644
@@ -218,7 +218,7 @@ static int ipw_write(struct tty_struct *linux_tty,
 	ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
 			       buf, count,
 			       ipw_write_packet_sent_callback, tty);
-	if (ret == -1) {
+	if (ret < 0) {
 		mutex_unlock(&tty->ipw_tty_mutex);
 		return 0;
 	}
Signature · 1 line
2.25.1