]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: imon: grab lock earlier in imon_ir_change_protocol()
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Thu, 17 Jul 2025 16:04:00 +0000 (01:04 +0900)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Fri, 15 Aug 2025 07:47:13 +0000 (09:47 +0200)
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>
drivers/media/rc/imon.c

index b914dd39c21cf54f732d48d2fa8069aceeff2720..8275ca5e9b6f59b64ff7cda174e9fa4dca6fa086 100644 (file)
@@ -598,6 +598,8 @@ static int send_packet(struct imon_context *ictx)
        int retval = 0;
        struct usb_ctrlrequest *control_req = NULL;
 
+       lockdep_assert_held(&ictx->lock);
+
        /* Check if we need to use control or interrupt urb */
        if (!ictx->tx_control) {
                pipe = usb_sndintpipe(ictx->usbdev_intf0,
@@ -1124,7 +1126,7 @@ static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto)
        int retval;
        struct imon_context *ictx = rc->priv;
        struct device *dev = ictx->dev;
-       bool unlock = false;
+       const bool unlock = mutex_trylock(&ictx->lock);
        unsigned char ir_proto_packet[] = {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
 
@@ -1151,8 +1153,6 @@ static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto)
 
        memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
 
-       unlock = mutex_trylock(&ictx->lock);
-
        retval = send_packet(ictx);
        if (retval)
                goto out;