Skip to content

Commit 3d37ef4

Browse files
Hans Verkuilmchehab
authored andcommitted
media: cobalt: fix race condition in setting HPD
The cobalt_s_bit_sysctrl reads the old register value over PCI, then changes a bit and sets writes the new value to the register. This is used among other things for setting the HPD output pin. But if the HPD is changed for multiple inputs at the same time, then this causes a race condition where a stale value is read. Serialize this function with a mutex. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent b2cd0b3 commit 3d37ef4

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/media/pci/cobalt/cobalt-driver.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ static int cobalt_probe(struct pci_dev *pci_dev,
667667
return -ENOMEM;
668668
cobalt->pci_dev = pci_dev;
669669
cobalt->instance = i;
670+
mutex_init(&cobalt->pci_lock);
670671

671672
retval = v4l2_device_register(&pci_dev->dev, &cobalt->v4l2_dev);
672673
if (retval) {

‎drivers/media/pci/cobalt/cobalt-driver.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ struct cobalt {
251251
int instance;
252252
struct pci_dev *pci_dev;
253253
struct v4l2_device v4l2_dev;
254+
/* serialize PCI access in cobalt_s_bit_sysctrl() */
255+
struct mutex pci_lock;
254256

255257
void __iomem *bar0, *bar1;
256258

@@ -320,10 +322,13 @@ static inline u32 cobalt_g_sysctrl(struct cobalt *cobalt)
320322
static inline void cobalt_s_bit_sysctrl(struct cobalt *cobalt,
321323
int bit, int val)
322324
{
323-
u32 ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
325+
u32 ctrl;
324326

327+
mutex_lock(&cobalt->pci_lock);
328+
ctrl = cobalt_read_bar1(cobalt, COBALT_SYS_CTRL_BASE);
325329
cobalt_write_bar1(cobalt, COBALT_SYS_CTRL_BASE,
326330
(ctrl & ~(1UL << bit)) | (val << bit));
331+
mutex_unlock(&cobalt->pci_lock);
327332
}
328333

329334
static inline u32 cobalt_g_sysstat(struct cobalt *cobalt)

0 commit comments

Comments
 (0)