Skip to contentSkip to conversation

serial: 8250: Store to lsr_save_flags after lsr read

PATCH Superseded Ilpo Järvinen 2 participants 3 messages May 20, 2022 TTY layer and serial drivers

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: 8250: Store to lsr_save_flags after lsr read

Not all LSR register flags are preserved across reads. Therefore, LSR readers must store the non-preserved bits into lsr_save_flags.

This fix was initially mixed into feature commit f6f586102add ("serial:
8250: Handle UART without interrupt on TEMT using em485"). However, that feature change had a flaw and it was reverted to make room for simpler approach providing the same feature. The embedded fix got reverted with the feature change.

Re-add the lsr_save_flags fix and properly mark it's a fix.

---
Since Uwe didn't follow up with this fix in an isolated patch, I'm sending it now so that it doesn't end up falling through cracks.

 drivers/tty/serial/8250/8250_port.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_port.c +2 -0
index 5591f18f2ea9..25f3dff9fe25 100644
@@ -1517,6 +1517,8 @@ static inline void __stop_tx(struct uart_8250_port *p)
 		unsigned char lsr = serial_in(p, UART_LSR);
 		u64 stop_delay = 0;
 
+		p->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
+
 		if (!(lsr & UART_LSR_THRE))
 			return;
 		/*
Signature · 1 line
tg: (4419da5d5d4b..) fix/lsr-save-flags (depends on: tty-next)
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ilpo Järvinen

Not all LSR register flags are preserved across reads. Therefore, LSR readers must store the non-preserved bits into lsr_save_flags.

This fix was initially mixed into feature commit f6f586102add ("serial:
8250: Handle UART without interrupt on TEMT using em485"). However, that feature change had a flaw and it was reverted to make room for simpler approach providing the same feature. The embedded fix got reverted with the feature change.

Re-add the lsr_save_flags fix and properly mark it's a fix.

Quoted 8 lines

---
Since Uwe didn't follow up with this fix in an isolated patch, I'm sending it now so that it doesn't end up falling through cracks.

Great, thanks. I completely obliterate that one.

Maybe it would be sensible to wrap reading + updating saved_flags in an inline helper?

Other than that:

Quoted 1 line

tg: (4419da5d5d4b..) fix/lsr-save-flags (depends on: tty-next)

Oh wow, you're using topgit? I would be interested in your pain points and what made you choose topgit anyhow. Since a longer time I have a few ideas for a git helper that uses the good ideas in topgit, but never came around to implement it.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#2 lore raw
Quoted 17 lines · Uwe Kleine-König
Quoted 16 lines · Ilpo Järvinen

Not all LSR register flags are preserved across reads. Therefore, LSR readers must store the non-preserved bits into lsr_save_flags.

This fix was initially mixed into feature commit f6f586102add ("serial:
8250: Handle UART without interrupt on TEMT using em485"). However, that feature change had a flaw and it was reverted to make room for simpler approach providing the same feature. The embedded fix got reverted with the feature change.

Re-add the lsr_save_flags fix and properly mark it's a fix.

Quoted 8 lines
Quoted 3 lines

---
Since Uwe didn't follow up with this fix in an isolated patch, I'm sending it now so that it doesn't end up falling through cracks.

Great, thanks. I completely obliterate that one.

Maybe it would be sensible to wrap reading + updating saved_flags in an inline helper?

It's my plan. I just wanted to get the obvious fix out of the way first.

Quoted 10 lines

Other than that:

Quoted 1 line

tg: (4419da5d5d4b..) fix/lsr-save-flags (depends on: tty-next)

Oh wow, you're using topgit? I would be interested in your pain points and what made you choose topgit anyhow. Since a longer time I have a few ideas for a git helper that uses the good ideas in topgit, but never came around to implement it.

Yes, I am. The most problematic case is when I'd want to reorder/relocate a patch towards root. I usually end up just creating another one with a different name. I've learned to cope most of what I'd assume many people would find pain points with manual tg patch | patch -p1 -R trickery (possibly combined with git add -i) and reapplying afterwards, it gets me quite far already.

Signature · 1 line
 i.