Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp143838lqh; Mon, 6 May 2024 14:11:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXMsOIcAvT7UsRQMB3XCmjYmletg+xWug/H9PSwLJ3djD+9GgFDvFG4LififytYh9lwSqIsg89Dw8usvivhebbzJWxUVUMJQ42w+qyZSw== X-Google-Smtp-Source: AGHT+IFrZZppCrH+dUqJXQqi43QShU27iTSTD03U8I2JKqENuQp8Yr0HlzUPPQ23tLzxzGDZawt/ X-Received: by 2002:a05:622a:152:b0:43a:d3ac:e568 with SMTP id v18-20020a05622a015200b0043ad3ace568mr15098939qtw.60.1715029882050; Mon, 06 May 2024 14:11:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715029882; cv=pass; d=google.com; s=arc-20160816; b=X5caX9YB2ruYA4KXB2vinvBkn0Xi9dcaizx1huTK5jcy7TtTvUiitzz4Hq7enV79u2 C+WYrXpWrrZAD/eEgfcyYX463sJ79zwWI4IeBhYPbw1mm8H06WGKx3qRLLddaCm9S0Wi 9LXN8njF1zNeFR0EkbvtlTS3JV/whuUzr2z36B7gi+wmhIJ9ZknlfTDYD6IxzyfgojX4 LaLevhW9Irl8V3IO8ZHlNQVwNtLXkIAQ1qQ76Obi3bTTGdastS/JVMtjUyuRS9Gxfj7k rx0r6qCZjNU/iMz+MIuh3vm9CurJU113PTmE0Bpe4tc60rOlxAu32g5P7MRbMNx04KU7 yaSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=GChtxSEHiZ0rsnEnXBszudDorgEfMXDvam+C+CQ8ysU=; fh=vCW1nLgKplwnnef6s0lFjYW4Ev4S/7Ye5Ejf4WK2Pc0=; b=gZSjW6CU0AyjRV+ySJ6Lz6QbluAyT/LUdd1CnzIne+WUukItTCzvMTLY8+s7K9a2uW wyyx+HBoRh7FGCTFLiDWvfRmHz9xZJ/sTWsvIxy9xKBAYtoBeqJdHmXl7IdVMKie6OM9 X4s/98Gc/5hP7gzDUz7rJGKdCK1lrkF0D3eDMthso+Zm6R/cK3j4PRflCu5NtF3QrnE2 ZbuQlhAxMmoHswgNvnA6vMCEzzfgf0BT8vtqa6xD4T313rHy2im1luHJBoHG5Tubh2Nv dhTfATVOOZq9MSMXTjGqmqwdrCUfXz1sry7eUGUJ2xBBNqpKxkD5kZf80K/wKDsvVW6e l4/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AD8v238k; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-170425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g14-20020ac87f4e000000b0043abcda92c3si10520225qtk.220.2024.05.06.14.11.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 14:11:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AD8v238k; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-170425-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C0A821C2132C for ; Mon, 6 May 2024 21:11:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED74415DBC0; Mon, 6 May 2024 21:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AD8v238k" Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4442315B966 for ; Mon, 6 May 2024 21:10:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715029834; cv=none; b=WkDEYhLW4jK6vkop6jZGTkzy0SHNpqsYnqDmgGVofu9rsAznKxSU99fze+pgyXpQGqv/CM2QK3OSPkCuAUuPZfTlWlZIko00RGaUyIjZ+r/X9QJ4HdX7JRO7wfFslAn4pR6rKxaTNDhtfwMvLmmgdkFbmcwOiYZK1AQSqD842WU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715029834; c=relaxed/simple; bh=rmMHfZ07Kd9lTZW6PwC3rqA96g9FbrjW5lK3extywms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dJnTnMjCMHHV4tuqxfyl6Hb+KqQLoz8bYeSy8HO2fFOre81bN1z1CinKdNIHSr9kXaWtx3/i7MUslu7Xf5o5XRmB8GETvKAwb9obfoFM9kkqxaoVYXDRy5yeSqaGTl+W4I9rwt9z8a/YwKyng4shTU7A7JKCntfP+ntzCBv8nXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=AD8v238k; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-792639cf4faso260818785a.1 for ; Mon, 06 May 2024 14:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1715029830; x=1715634630; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GChtxSEHiZ0rsnEnXBszudDorgEfMXDvam+C+CQ8ysU=; b=AD8v238kG/nRmGskPklFvxXewBA+3TI+A2uSOWBNUYHNym1YT14DlD/dUc0YpjsH+d ZiyY+x2FX2Zx6tatsr7ebbwclChoXX6QC6WQb0fUSQQzuT9aToTXu4jrT1bPQ2qUnN2n Y6vGYnqE+O706qslQb5NRtbF4W3TtkKtiTsls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715029830; x=1715634630; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GChtxSEHiZ0rsnEnXBszudDorgEfMXDvam+C+CQ8ysU=; b=rqCAiqjHv5US0Blnj0fdqff2u7hVYXN1yUY3/RnVRU9Bs6SgUwVhN6EsZL89DDb7Ug yPm3FHJrrpGXmkuV7FAnYX+CiDHfw0i8RurmbY7oPw1SUu9sois/o4JhGwvii9bDQyBc sEf70z4ysNQZSoVPSmv2Xu/Oge9r/p/eCSeX9Vi1L5BTf9Y/7vxkCk/yrVMRxvix1IS7 XkMvNYkxXYRPyvu/0tUWtumoagcdaXs5vi1cMYndxJrJK0B/TsAifEuePc8yVUYs7vbu Pmck1KbCQ9WrwL39q/XJnD/03bRrIw4bB56monozX3dycKbBZbES9z/+pvNexhMzTYaK Ih5A== X-Forwarded-Encrypted: i=1; AJvYcCXbDnQTWONNMNhSN9qt25loT/DL98OJ58qH2e31t0WpuQiyRTANAq6+pJvlCOyMLsY2MXUejA22bsh+uUBb95VbVtTz1kA9Nz0Re1KR X-Gm-Message-State: AOJu0Yy4UXizJHMYBHCbmedN+DKnuP3LdEwEt7BQPMNMWuKyp4ivITmQ YDp9IG1Wsz0neD8x/AP2KmmjTaj7HBKfszVX5/1ONqFkjNouHp3TNF0T97zCVA== X-Received: by 2002:a05:620a:89e:b0:792:93ed:2e7c with SMTP id b30-20020a05620a089e00b0079293ed2e7cmr4684450qka.76.1715029830157; Mon, 06 May 2024 14:10:30 -0700 (PDT) Received: from denia.c.googlers.com (114.152.245.35.bc.googleusercontent.com. [35.245.152.114]) by smtp.gmail.com with ESMTPSA id pa20-20020a05620a831400b0078f13e59dc9sm4224921qkn.102.2024.05.06.14.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 14:10:29 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 06 May 2024 21:10:27 +0000 Subject: [PATCH 2/5] media: imon: Fix race getting ictx->lock Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240506-cocci-locks-v1-2-a67952fe5d19@chromium.org> References: <20240506-cocci-locks-v1-0-a67952fe5d19@chromium.org> In-Reply-To: <20240506-cocci-locks-v1-0-a67952fe5d19@chromium.org> To: Andy Walls , Mauro Carvalho Chehab , Sean Young , Jarod Wilson Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.12.4 Lets fix a race between mutex_is_lock() and mutex_lock(). <-mutex is not locked if (!mutex_is_locked(&ictx->lock)) { unlock = true; <- mutex is locked externaly mutex_lock(&ictx->lock); } Let's use mutex_trylock() that does mutex_is_lock() and mutex_lock() atomically. Fix the following cocci warning: drivers/media/rc/imon.c:1167:1-7: preceding lock on line 1153 Fixes: 23ef710e1a6c ("[media] imon: add conditional locking in change_protocol") Signed-off-by: Ricardo Ribalda --- drivers/media/rc/imon.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c index 0b55314a8082..8f1361bcce3a 100644 --- a/drivers/media/rc/imon.c +++ b/drivers/media/rc/imon.c @@ -1148,10 +1148,7 @@ 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)); - if (!mutex_is_locked(&ictx->lock)) { - unlock = true; - mutex_lock(&ictx->lock); - } + unlock = mutex_trylock(&ictx->lock); retval = send_packet(ictx); if (retval) -- 2.45.0.rc1.225.g2a3ae87e7f-goog