Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1652092lqp; Mon, 15 Apr 2024 12:41:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMnTdVp+k634Glk4HolOSE6o1N5vaWutpXDr4HLRDO3XkfjHyl8D8YuYOf7jihGLX3umiQsboN1BuFN6okFDa4Bewbb4IacCJU4+VsSQ== X-Google-Smtp-Source: AGHT+IFQMnACL4RopzKQrLM1NLNs51D5xM95ugpp+KvAwePHSoHThsBr+X70wLeOautnwlZXgyy8 X-Received: by 2002:a05:6a21:2b14:b0:1a7:507a:c9f4 with SMTP id ss20-20020a056a212b1400b001a7507ac9f4mr8660433pzb.30.1713210087497; Mon, 15 Apr 2024 12:41:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713210087; cv=pass; d=google.com; s=arc-20160816; b=jC0xECRMahqlFTUtMG/XtPrTB9IiN7b5X3zzYmRz6rqcw4DMrMGI/TPcxP3WlvioW4 1jYYI5gl1n6UhsFMx07/xZH4+7hXlI2f2/Sl61DEO0S3msBVPK4hKQDQn8DYKgbNlMvC UEKmW2J13iDVW4xU/oOh7Bd/XxMsp0hXsEhSXfVJK+1Od5+Z+kDg+tTuAYFWv5VZAG/m /TWn4407GqEx6+hlWO2O3kM6G/BjN2zLk9WGNJY5L3zhKA/Ky4tNe92KVrxvUzVYgeXI B2T+yRGhFXRBVeCDqhicJh5zGZSaWgQquN2ATmfwE4MsV3BL3HNVz87CCGyiVDmQ8be5 Avyg== 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=hx47X/CBEUsxAKiiRrHT5ksgFdQJWx3yIi/EXUgSCek=; fh=vnjgZQnZacLfslhoojKh3SlKAZ2BvfxaXX3/P1cqD3Y=; b=kGUHLlfJg1ki1AK4ZHGjY0ykcqDL+RvubEdDIkIQXd0l22iSMWKM7APoAPUnVAnTbG cULA5gExmjSa0ssT5K42lP2vWD279a0gMYISnwfY3JGDl2TEDbyJc1BysmVW1v5N4tF0 IpW6HEl34Lqawr2CtMsTedEjrqIVywJXhM+TRjCHfDS8XEGDsbhmW4WQU6Sow+BkcbDg /6bD94H4i/oqXvZ76K8BoaxHd4kFGSrYa33S39Ps5qr6ipONJ+v3W5XlI+QE8aWzXjrT LHN6jK3SaFhcYmcxeKaFV5QiNQEUHRr7tqvWf2ALjrMwxdpzhDXnwicIvLBB0hxhdEOh +dNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RT2Eje2S; 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-145793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s30-20020a63af5e000000b005e858e6a1e5si8356773pgo.585.2024.04.15.12.41.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:41:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RT2Eje2S; 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-145793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145793-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 24DF9B23823 for ; Mon, 15 Apr 2024 19:39:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCBAF15D5BE; Mon, 15 Apr 2024 19:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RT2Eje2S" Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 AEA4E15B573 for ; Mon, 15 Apr 2024 19:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209682; cv=none; b=cvu/3c9dm5Y3QYqLAHMjuJPjryBpRTdY4DsuoY7of89yZGfERmBukk1Q/GgbxiKwiBo3eP4X/4sVax6+ILsI+lctdgb9+4GjlVapFRcYj17Jml9EZQSNazhF6+wBCwWLkFlownLpoTFhGp5CK/kXiyGSptf5rZ3IOxsCvcUdQ0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209682; c=relaxed/simple; bh=ZU3FVdGesXLn5Tghd6pW0dVrnY1rgwS3JWG+FuKO0Qo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NhaUI9nu3CP8fUl5/6BDNs6K388XNAm8wmdgu+Tkl+rqIFVDBKHnVKbOuImzU7I5XI+u40gGVKmdkXxjPu1efRiDgcJML+pqxHZ5KqiGLM3JWpv/uxsnvLYVw2+tVy9uG40qMkUumkE+6ExS73dNoDERZ946MpuxmIAqcUsdpVU= 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=RT2Eje2S; arc=none smtp.client-ip=209.85.222.178 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-f178.google.com with SMTP id af79cd13be357-78edc0a81efso140417985a.1 for ; Mon, 15 Apr 2024 12:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713209680; x=1713814480; 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=hx47X/CBEUsxAKiiRrHT5ksgFdQJWx3yIi/EXUgSCek=; b=RT2Eje2S7mExkzPQVOFs0OLWidGNMqi25p4XYRUCfkYdoDxKWGQmBCsERqUavHq3SP IWbtKPeYMp9eO8u6HcuK895QbTuiliDr8zSxmsp5i+DWIiVDnBybsSMu29dSDWz/Oz93 iF92DEeu1S5zqYzY1uUQjoinJnbg2l1NmC/aw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713209680; x=1713814480; 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=hx47X/CBEUsxAKiiRrHT5ksgFdQJWx3yIi/EXUgSCek=; b=YKGT6jSaTH1yDbBP/wXKwVJgKxaBFKJWB1llJHeOJy0lBZ4TCqrh01E0nbK8rlXxu+ iEAIXy0cdBfbkMSBAncOOAyL3YbCr4uAZ7Uf7H2pXRxjiwqiGvQnkPkmLTk9lIUUWj2f LxjtOn4XmcNWcJX7pfY6H63IWb488fLaEys44BpvjISFAXa0Hd1ipmdY+yAJsUFGjIBy RYUcFpfJzJl26lEt05vjQTSDG4q/qRoTf6eiVpbUGkkzEJYJZjTVXnvE4mzpxU4+8Ftf yIoXQZE6DwGlU/pz34o0tpXeB59PZb7pq8KGYGmgYsoeWXuwuQc4c+Jv7Yh7u+2p02kn IfDg== X-Forwarded-Encrypted: i=1; AJvYcCWjf3hJYOMp95sKxacAfLziiFs/INVv1DtsTMV+kNGph1JZKecORislIpJzPY7L0uZGR8wgYuERjlw/pPdx+sK9zs8KMx+d1GrFTBdO X-Gm-Message-State: AOJu0YzuALTcCvA7sh8dNWoU4pvcZuJi+UUxFYyws6nXVMkcE+gzTRk9 YhwFd4+yP9dztH7uik2w6NQXCY1UXmv+sVSgk3FRrb8ZWEVhPwCDr2nuIY3enw== X-Received: by 2002:a05:620a:2443:b0:78d:6b72:b45 with SMTP id h3-20020a05620a244300b0078d6b720b45mr14283622qkn.1.1713209679634; Mon, 15 Apr 2024 12:34:39 -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 s26-20020ae9f71a000000b0078d3b54eb76sm6718055qkg.78.2024.04.15.12.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:34:39 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 15 Apr 2024 19:34:28 +0000 Subject: [PATCH 11/35] media: s2255: Use refcount_t instead of atomic_t for num_channels 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: <20240415-fix-cocci-v1-11-477afb23728b@chromium.org> References: <20240415-fix-cocci-v1-0-477afb23728b@chromium.org> In-Reply-To: <20240415-fix-cocci-v1-0-477afb23728b@chromium.org> To: Martin Tuma , Mauro Carvalho Chehab , Laurent Pinchart , Hans Verkuil , Hugues Fruchet , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Paul Kocialkowski , Greg Kroah-Hartman , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Sakari Ailus , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil , Sergey Kozlov , Abylay Ospan , Ezequiel Garcia , Dmitry Osipenko , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio , Benjamin Mugnier , Sylvain Petinot , Jacopo Mondi , Kieran Bingham , Laurent Pinchart , =?utf-8?q?Niklas_S=C3=B6derlund?= , Pavel Machek Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.12.4 Use an API that resembles more the actual use of num_channels. Found by cocci: drivers/media/usb/s2255/s2255drv.c:2362:5-24: WARNING: atomic_dec_and_test variation before object free at line 2363. drivers/media/usb/s2255/s2255drv.c:1557:5-24: WARNING: atomic_dec_and_test variation before object free at line 1558. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/s2255/s2255drv.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c index 8e1de1e8bd12..a6e450181fd0 100644 --- a/drivers/media/usb/s2255/s2255drv.c +++ b/drivers/media/usb/s2255/s2255drv.c @@ -247,7 +247,7 @@ struct s2255_vc { struct s2255_dev { struct s2255_vc vc[MAX_CHANNELS]; struct v4l2_device v4l2_dev; - atomic_t num_channels; + refcount_t num_channels; int frames; struct mutex lock; /* channels[].vdev.lock */ struct mutex cmdlock; /* protects cmdbuf */ @@ -1550,11 +1550,11 @@ static void s2255_video_device_release(struct video_device *vdev) container_of(vdev, struct s2255_vc, vdev); dprintk(dev, 4, "%s, chnls: %d\n", __func__, - atomic_read(&dev->num_channels)); + refcount_read(&dev->num_channels)); v4l2_ctrl_handler_free(&vc->hdl); - if (atomic_dec_and_test(&dev->num_channels)) + if (refcount_dec_and_test(&dev->num_channels)) s2255_destroy(dev); return; } @@ -1659,7 +1659,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev) "failed to register video device!\n"); break; } - atomic_inc(&dev->num_channels); + refcount_inc(&dev->num_channels); v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", video_device_node_name(&vc->vdev)); @@ -1667,11 +1667,11 @@ static int s2255_probe_v4l(struct s2255_dev *dev) pr_info("Sensoray 2255 V4L driver Revision: %s\n", S2255_VERSION); /* if no channels registered, return error and probe will fail*/ - if (atomic_read(&dev->num_channels) == 0) { + if (refcount_read(&dev->num_channels) == 0) { v4l2_device_unregister(&dev->v4l2_dev); return ret; } - if (atomic_read(&dev->num_channels) != MAX_CHANNELS) + if (refcount_read(&dev->num_channels) != MAX_CHANNELS) pr_warn("s2255: Not all channels available.\n"); return 0; } @@ -2221,7 +2221,7 @@ static int s2255_probe(struct usb_interface *interface, goto errorFWDATA1; } - atomic_set(&dev->num_channels, 0); + refcount_set(&dev->num_channels, 0); dev->pid = id->idProduct; dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); if (!dev->fw_data) @@ -2341,12 +2341,12 @@ static void s2255_disconnect(struct usb_interface *interface) { struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface)); int i; - int channels = atomic_read(&dev->num_channels); + int channels = refcount_read(&dev->num_channels); mutex_lock(&dev->lock); v4l2_device_disconnect(&dev->v4l2_dev); mutex_unlock(&dev->lock); /*see comments in the uvc_driver.c usb disconnect function */ - atomic_inc(&dev->num_channels); + refcount_inc(&dev->num_channels); /* unregister each video device. */ for (i = 0; i < channels; i++) video_unregister_device(&dev->vc[i].vdev); @@ -2359,7 +2359,7 @@ static void s2255_disconnect(struct usb_interface *interface) dev->vc[i].vidstatus_ready = 1; wake_up(&dev->vc[i].wait_vidstatus); } - if (atomic_dec_and_test(&dev->num_channels)) + if (refcount_dec_and_test(&dev->num_channels)) s2255_destroy(dev); dev_info(&interface->dev, "%s\n", __func__); } -- 2.44.0.683.g7961c838ac-goog