]> git.baikalelectronics.ru Git - kernel.git/commit
can: gs_usb: add missing lock to protect struct timecounter::cycle_last
authorMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 19 Sep 2022 07:53:45 +0000 (09:53 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 23 Sep 2022 11:55:00 +0000 (13:55 +0200)
commitfe4f61b524aed496a2f7dc2ca99a8bd06913fe03
tree59bdbfa6cc6071cfd7ace27a16119ec977094404
parent552f7fbddbbf07a9f135db6960f80b7f8144dd05
can: gs_usb: add missing lock to protect struct timecounter::cycle_last

The struct timecounter::cycle_last is a 64 bit variable, read by
timecounter_cyc2time(), and written by timecounter_read(). On 32 bit
architectures this is not atomic.

Add a spinlock to protect access to struct timecounter::cycle_last. In
the gs_usb_timestamp_read() callback the lock is dropped to execute a
sleeping synchronous USB transfer. This is safe, as the variable we
want to protect is accessed during this call.

Fixes: c351fac8f5e8 ("can: gs_usb: add RX and TX hardware timestamp support")
Link: https://lore.kernel.org/all/20220920100416.959226-3-mkl@pengutronix.de
Cc: John Whittington <git@jbrengineering.co.uk>
Tested-by: John Whittington <git@jbrengineering.co.uk>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/gs_usb.c