Skip to contentSkip to conversation

n_gsm: Fix write handling for zero bytes written

PATCH In review Tony Lindgren 2 participants 7 messages Aug 17, 2020 – Aug 19, 2020 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 n_gsm: Fix write handling for zero bytes written

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

---
 drivers/tty/n_gsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/n_gsm.c +2 -1
@@ -691,7 +691,8 @@ static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci)
 			print_hex_dump_bytes("gsm_data_kick: ",
 					     DUMP_PREFIX_OFFSET,
 					     gsm->txframe, len);
-		if (gsm->output(gsm, gsm->txframe, len) < 0)
+
+		if (gsm->output(gsm, gsm->txframe, len) <= 0)
 			break;
 		/* FIXME: Can eliminate one SOF in many more cases */
 		gsm->tx_bytes -= msg->len;
Signature · 1 line
2.28.0
maintainer
#1 lore raw
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

Quoted 10 lines
---
 drivers/tty/n_gsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) · line 698

Quoted 9 lines
drivers/tty/n_gsm.c +2 -1
@@ -691,7 +691,8 @@ static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci)
 			print_hex_dump_bytes("gsm_data_kick: ",
 					     DUMP_PREFIX_OFFSET,
 					     gsm->txframe, len);
-		if (gsm->output(gsm, gsm->txframe, len) < 0)
+
+		if (gsm->output(gsm, gsm->txframe, len) <= 0)
 			break;
 		/* FIXME: Can eliminate one SOF in many more cases */
 		gsm->tx_bytes -= msg->len;

thanks,

Signature · 1 line
js
#2 lore raw

Hi,

Quoted 7 lines · Jiri Slaby
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

I ran into this when testing with the WIP serial core PM runtime changes from Andy Shevchenko earlier. If there are also other cases where we have serial drivers return 0, I don't know about them.

Basically with the WIP serial core changes, if the open serial port is in PM runtime suspended state with it's autosuspend_delay_ms expired, we have write return 0 and just wake up the serial device on TX.

I don't think there's much anything else we can currently do there in the PM runtime suspended case as we want to get rid of the remaining pm_runtime_irq_safe() dependencies as it takes a permanent usage count on the parent device.

Regards,

Tony

Quoted 24 lines
Quoted 11 lines
---
 drivers/tty/n_gsm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) · line 698

Quoted 9 lines
drivers/tty/n_gsm.c +2 -1
@@ -691,7 +691,8 @@ static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci)
 			print_hex_dump_bytes("gsm_data_kick: ",
 					     DUMP_PREFIX_OFFSET,
 					     gsm->txframe, len);
-		if (gsm->output(gsm, gsm->txframe, len) < 0)
+
+		if (gsm->output(gsm, gsm->txframe, len) <= 0)
 			break;
 		/* FIXME: Can eliminate one SOF in many more cases */
 		gsm->tx_bytes -= msg->len;

thanks,

Signature · 1 line
js
maintainer
#3 lore raw
Quoted 8 lines · Tony Lindgren

Hi,

Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

Quoted 7 lines
Quoted 2 lines

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

I ran into this when testing with the WIP serial core PM runtime changes from Andy Shevchenko earlier. If there are also other cases where we have serial drivers return 0, I don't know about them.

Sorry, I don't understand: my gsmld_output() ignores the return value from drivers' write and returns something greater than zero or a negative error. What tree/SHA do you run?

Quoted 4 lines

Basically with the WIP serial core changes, if the open serial port is in PM runtime suspended state with it's autosuspend_delay_ms expired, we have write return 0 and just wake up the serial device on TX.

Signature · 1 line
js
#4 lore raw
Quoted 12 lines · Jiri Slaby
Quoted 11 lines · Tony Lindgren

Hi,

Quoted 7 lines · Jiri Slaby
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

Quoted 8 lines
Quoted 4 lines

I ran into this when testing with the WIP serial core PM runtime changes from Andy Shevchenko earlier. If there are also other cases where we have serial drivers return 0, I don't know about them.

Sorry, I don't understand: my gsmld_output() ignores the return value from drivers' write and returns something greater than zero or a negative error. What tree/SHA do you run?

Oh right, good catch. I also had my WIP serdev-ngsm patches applied that uses gsm_serdev_output() and returns the bytes written. Andy's patches do not touch n_gsm.c.

Hmm sounds like we should also start returning value also from gsmld_output()? Any objections to making that change?

For reference, Andy's WIP serial cor PM runtime changes are at:

https://gitlab.com/andy-shev/next.git/ topic/uart/rpm-plus

Regards,

Tony

maintainer
#5 lore raw
Quoted 22 lines · Tony Lindgren
Quoted 12 lines · Jiri Slaby
Quoted 11 lines · Tony Lindgren

Hi,

Quoted 7 lines · Jiri Slaby
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

Quoted 8 lines
Quoted 4 lines

I ran into this when testing with the WIP serial core PM runtime changes from Andy Shevchenko earlier. If there are also other cases where we have serial drivers return 0, I don't know about them.

Sorry, I don't understand: my gsmld_output() ignores the return value from drivers' write and returns something greater than zero or a negative error. What tree/SHA do you run?

Quoted 6 lines

Oh right, good catch. I also had my WIP serdev-ngsm patches applied that uses gsm_serdev_output() and returns the bytes written. Andy's patches do not touch n_gsm.c.

Hmm sounds like we should also start returning value also from gsmld_output()? Any objections to making that change?

No objections here.

thanks,

Signature · 2 lines
js
suse labs
#6 lore raw
Quoted 23 lines · Jiri Slaby
Quoted 22 lines · Tony Lindgren
Quoted 20 lines · Jiri Slaby
Quoted 8 lines · Tony Lindgren

Hi,

Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Tony Lindgren

If write returns zero we currently end up removing the message from the queue. Instead of removing the message, we want to just break out of the loop just like we already do for error codes.

Quoted 7 lines
Quoted 2 lines

When exactly does the only writer (gsmld_output) return zero for non-zero len parameter?

I ran into this when testing with the WIP serial core PM runtime changes from Andy Shevchenko earlier. If there are also other cases where we have serial drivers return 0, I don't know about them.

Sorry, I don't understand: my gsmld_output() ignores the return value from drivers' write and returns something greater than zero or a negative error. What tree/SHA do you run?

Quoted 8 lines
Quoted 6 lines

Oh right, good catch. I also had my WIP serdev-ngsm patches applied that uses gsm_serdev_output() and returns the bytes written. Andy's patches do not touch n_gsm.c.

Hmm sounds like we should also start returning value also from gsmld_output()? Any objections to making that change?

No objections here.

OK thanks, I'll post an updated patch.

Regards,

Tony