diff mbox series

[6/8] pcwd_usb: memory ordering of interrupt and waiter

Message ID 20230427133350.31064-7-oneukum@suse.com (mailing list archive)
State Rejected
Headers show
Series [1/8] pwcd_usb: fix error handling in probe | expand

Commit Message

Oliver Neukum April 27, 2023, 1:33 p.m. UTC
The driver manually waits in a loop for an atomic flag.
Hence memory ordering must be constrained, so that
the waiters read what the interrupt handler writes
before it touches the flag.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/watchdog/pcwd_usb.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index b99b8fee2873..50ba88019ed6 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -193,6 +193,7 @@  static void usb_pcwd_intr_done(struct urb *urb)
 	usb_pcwd->cmd_command  = data[0];
 	usb_pcwd->cmd_data_msb = data[1];
 	usb_pcwd->cmd_data_lsb = data[2];
+	smp_wmb(); /* make sure waiters read them */
 
 	/* notify anyone waiting that the cmd has finished */
 	atomic_set(&usb_pcwd->cmd_received, 1);
@@ -250,6 +251,7 @@  static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
 			got_response = 1;
 	}
 
+	smp_rmb(); /* ordering with respect to interrupt handler */
 	if ((got_response) && (cmd == usb_pcwd->cmd_command)) {
 		/* read back response */
 		*msb = usb_pcwd->cmd_data_msb;