Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: imon: grab lock earlier in imon_ir_change_protocol()

Move mutex_trylock() in imon_ir_change_protocol() to the beginning,
for memcpy() which modifies ictx->usb_tx_buf should be protected by
ictx->lock.

Also, verify at the beginning of send_packet() that ictx->lock is held
in case send_packet() is by error called from imon_ir_change_protocol()
when mutex_trylock() failed due to concurrent requests.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Tetsuo Handa and committed by
Hans Verkuil
7019553a eecd203a

+3 -3
+3 -3
drivers/media/rc/imon.c
··· 598 598 int retval = 0; 599 599 struct usb_ctrlrequest *control_req = NULL; 600 600 601 + lockdep_assert_held(&ictx->lock); 602 + 601 603 /* Check if we need to use control or interrupt urb */ 602 604 if (!ictx->tx_control) { 603 605 pipe = usb_sndintpipe(ictx->usbdev_intf0, ··· 1126 1124 int retval; 1127 1125 struct imon_context *ictx = rc->priv; 1128 1126 struct device *dev = ictx->dev; 1129 - bool unlock = false; 1127 + const bool unlock = mutex_trylock(&ictx->lock); 1130 1128 unsigned char ir_proto_packet[] = { 1131 1129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 }; 1132 1130 ··· 1152 1150 } 1153 1151 1154 1152 memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet)); 1155 - 1156 - unlock = mutex_trylock(&ictx->lock); 1157 1153 1158 1154 retval = send_packet(ictx); 1159 1155 if (retval)