Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp520827lqt; Fri, 19 Apr 2024 02:52:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwyVzERII7/jaHdulXCityhpqaRjx3Z6ZdnEvCnLZSpGkQSJERxW7GkdoKCnf4f7ublXpfJ7nIJrqeJp14UbWxl2DmFj9/HLOKVNzDDg== X-Google-Smtp-Source: AGHT+IGNH4Slnyg8b21IxrivdQYnRru3NF3BVerUhR3/KzKFZvURjecXvV8XurBSiZumNSeq71Lj X-Received: by 2002:a05:6402:26d0:b0:56e:2a05:a0e3 with SMTP id x16-20020a05640226d000b0056e2a05a0e3mr1803388edd.21.1713520369816; Fri, 19 Apr 2024 02:52:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713520369; cv=pass; d=google.com; s=arc-20160816; b=Dn8/Ddr3KfjakkxznFRlpvx1KzUPx+Nd+MKG7uaBA1lWEnm9y5XkL4gFq76VhMtGj1 QhrM7eiUuph5DlYdzIi6Wts/w038YqoqXULWncjDFORyXEUm5cG2BngP9cyuZQxxynip 0SX2NpLYhrhIAK3zwa03ShrNQ1ProSHyf80KGwPu3NZVwJKh7Su7UP3aBROf/0dSjm4u 0PdYIjbox+9vuXS2mixfglTLj1RWiI6iuzzVLY+ZvC5HdLmFFkXEaFSMClrLyk/xYL0D 4B+wAyxLtBGWu/LxYk1InwUWvUmOi+k+WnhNkc+qwIYDSJkcEpoQFXDE7sqDl1IRD9EM /NpA== 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=M/K5Byxt1ig+CQr/X/PeYwmg4ty1EjIby+WFZ625f+g=; fh=C+1QLXnQhRevL26/T5C9gZ7RzsxdYs7VOW4Kd1JSZ2M=; b=wIhUsVQwoLwe+bWUxRVvV7rJ24qCh8F2L7Nd/QDUxP7judRoDdY+DHqJZS5cDDYRtF Ok5lm+KK8PjEzDs60WDqRXSmOiBreHX1cS5o8kLChSScyuT2gB/T/7v5M1ETagdxSfnr aDWdr7IGdD4cFbY2PIurUxFiwi5Lz1NKhTorebD4ba1xB4GOVrfxIts2DS0TkRFRa/Hw 31A2XE05YHzNtLmRI3TCGoF9aC1m/3hlwcOe1snNZ5azxNyLrB1IHSelnhay3/eRgTIO /a7AL4h8p5A1V4EWeBwAQ7jmTzPLbqUVxL009PNZ/LcKCj0Gqt+E1JR9RPWjhcK3hpyi fPVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IYWOB4xi; 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-151258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dc19-20020a056402311300b00571c994ccc0si1113749edb.323.2024.04.19.02.52.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IYWOB4xi; 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-151258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151258-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 60FF01F21317 for ; Fri, 19 Apr 2024 09:52:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CD33839EB; Fri, 19 Apr 2024 09:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IYWOB4xi" Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 56D9283CCB for ; Fri, 19 Apr 2024 09:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520175; cv=none; b=HF3ozrQ6O7NRIiTHGFSa6uPEPId7JDuH0IP2/5L9Lcfmt/snL+Uriy47uRHkEWmtjaD6vS6m60tcZR7n7e9Ab9z8riuxiqNeR5b6LHxUO8A9qkfVS8PoT4lqDuofhmoMeCaDgZSzUbEhGHbGGyCEsaubJ45VSlaovxJXFTpQvws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713520175; c=relaxed/simple; bh=IwVC+qmR5b/10H0elYXxcr5eG/G4ClY19WrOjc/vxJY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TYWcaibYLDT9kAhG8mruta3NVFNDDdTWkt9MBsYCSalunVX6O1bp2mZUQEYKdiGmGNOI5aRqZpSfp86Xumu3LE6j1CyCm8USWaXbzRlt3yFL2wZXbN7FOL0k/XJvCqI/lkDC4PQKwwwsdrWEgkE8/hV1ctex+DdO2KmQze+07B8= 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=IYWOB4xi; arc=none smtp.client-ip=209.85.222.177 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-f177.google.com with SMTP id af79cd13be357-78f056f928eso115328985a.0 for ; Fri, 19 Apr 2024 02:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713520172; x=1714124972; 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=M/K5Byxt1ig+CQr/X/PeYwmg4ty1EjIby+WFZ625f+g=; b=IYWOB4xi57QKQvaMi2xOTTog7GkPX59ZjlhgVswh9TDKqU8F0GJ6dgLaqRJWunFXMb LZ3AePDlpQKXyOP7IZ8ZTUhaGnX0kPSU+HP7azWzi/dgZGtXDlur5NSK2u8zEAU/7SnT 0B8UPHcf8qJSaCnzHKteqwOSbUdY9zt5U3VlQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713520172; x=1714124972; 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=M/K5Byxt1ig+CQr/X/PeYwmg4ty1EjIby+WFZ625f+g=; b=Uleleboe/0kr3U9Xu4AN+LstycVTTw1MSUWGNWQ7v2ZuJL1fiJ5IbbYRXgfhb3mDyN Zzhh3nI1LSJ83cCM76IzNCMZMJiUjng3weERUQMzz2y+hx0bxB7qhqQ+SM5408XGmTX5 ZrjhA7YhjevNYCCzP+lD3xasfc+b9OILuGcwu63dShS1k88vmgLYNVxYwNmkaTk+na25 9ymCLskkBnFncSgUtbcMbc6EJY4V64QuAI+rZ4dqcRKRWmFE+j99cD0t1hU9gvclafrO M/ngsY205S7SONubZcWItEOsC6imfZF6Mq0GnG6ur23w1eOUA/eshXmfyrtPXl+t97/r rhHw== X-Forwarded-Encrypted: i=1; AJvYcCVPjTKDGxEe1NBv6Q+4yOXFOkQn5hbsOlbW2MmEl8kIyaHhvgv4bfvuV7LtF7LYdE7Mj68Sgp0S2V1IvLtZFPFqP97YkjraScuL9fee X-Gm-Message-State: AOJu0YzCrkuN/HwNWV79ZrucziyJpZwi25CdYskovbWcHpy02Jwo+1mr GWjMyPtWVGTqcLRBcxfEW+pESbdiZarPKIQJt/J/vKi45vpfbsX4NhB9ChCglA== X-Received: by 2002:a05:620a:8da:b0:78a:68c3:dceb with SMTP id z26-20020a05620a08da00b0078a68c3dcebmr1504339qkz.32.1713520172428; Fri, 19 Apr 2024 02:49:32 -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 dt14-20020a05620a478e00b0078d735ca917sm1434532qkb.123.2024.04.19.02.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:49:32 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 19 Apr 2024 09:47:57 +0000 Subject: [PATCH v2 11/26] 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: <20240419-fix-cocci-v2-11-2119e692309c@chromium.org> References: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> In-Reply-To: <20240419-fix-cocci-v2-0-2119e692309c@chromium.org> To: Martin Tuma , Mauro Carvalho Chehab , Laurent Pinchart , 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 , Benjamin Mugnier , Sylvain Petinot , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Bjorn Andersson , Konrad Dybcio 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.769.g3c40516874-goog