Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1651389lqp; Mon, 15 Apr 2024 12:40:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1YABgt/ly7iI3v+ruHq+U6vIHbE7VO/rYa96nBoxfF8yxrnWgb+Tp7ItTKPw2EpXLE5wUrqqUkgtuk/y8lJeLs5hskd3bCciDNK6NOQ== X-Google-Smtp-Source: AGHT+IFoZ2IQ6+8vXyRpM99qp4KRO0Dx6Q7NI4SC5O+CGz7P9Q0W68ATVRjeIFmZLHDEuBPNdk9d X-Received: by 2002:a17:906:2b0e:b0:a51:9f51:4af5 with SMTP id a14-20020a1709062b0e00b00a519f514af5mr6155971ejg.45.1713210006554; Mon, 15 Apr 2024 12:40:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713210006; cv=pass; d=google.com; s=arc-20160816; b=KT+kR5D00lTunzo7VVmvFDNb8IaKjwgZL2KGYe8zmghM7vTnNjZ3DcGsBuz3Yty/2G KZBXIOBo/QSIg1B4KVjXIn+7t+I5VkkWuOI7Thgwa/NJsu18A3RaBcX4Uc9fiPJjoBzI LMxc4q9gJwCOemcEdgBow3R2GdQXGFLnSUJUgodq+bFLj06jvq8BZ27/kX+TZWO6fPn0 zR+mx4CYnwK8Spbi4dddJsAxP1U4F9iapIZftJhTcOFklWB1Pf04RZtAyVf3Y33kkwU1 T8yJOqXBv7cf1rDlw5wbzufljLkH+iH0itn96n2KjBR2PhffxZ4yg7Qky/gt9qLCyaGx nvOw== 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=33KvbvTql7+TfuU6gagkdE47f06z1GuAxIph77Mkm3M=; fh=jxYgZWrbm8CIrUlio8/a6nSg/W+yI9R3Tdw9nsWXh4k=; b=zyMPO+ggbh7BedTq7r4D6QD41K5NlKHGUGB6C24iFfQeBW96s72uqWQJrBzhsxuLn3 1a+MBd7UY/4xNHzOhEYTkTLobGSSVQ8m0w2IuXBhkI2I22aj8okI0sI6d+BlCE6UZa/H IRJfOcRXB55zx8UKYQR8o4VF80Xs+1syg5mlkNBCPbHg7RT+C7x1X4sRc/sVRGQc3thU XM1hKoyrEHhnUjYfDNWQ/SQttmmbFqRct6n3LMdpHz9zGc/iQmgRNM1gapBAJJYjK3ws r421gJ9Kbjp8QsU3fgN6wGjUrY4irlTaDg3EDB2vPNjc9hj7XA1v9nXIhKWyuPh42yBP n1yA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="g76E/EJT"; 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-145794-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145794-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 gb40-20020a170907962800b00a522c00939dsi4220723ejc.813.2024.04.15.12.40.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:40:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145794-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="g76E/EJT"; 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-145794-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145794-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 1BC5F1F22DF8 for ; Mon, 15 Apr 2024 19:40:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50E0915E1FB; Mon, 15 Apr 2024 19:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="g76E/EJT" Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 19E67156669 for ; Mon, 15 Apr 2024 19:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209685; cv=none; b=ONxw2h8s7LUFjJtsyDhrph438MPXLfFitUS0Phj8KqIHeym5TuJW4LHIY0yvyLEGUfzIBalokVmOYAtAjiGbnmtz4mt6hODtfcG8AjlRBt5sCg4OLplWGDrf0XI/JX8crpyK2BUUk8jNrlSblW4RyT8uiTI/ZP8Oo3m+q7X247Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713209685; c=relaxed/simple; bh=voYFN1/inOeTC56UFpR6f4g83j+vq/jARmGXAqFZb60=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jc+R5t/mJRn1GVDs2z1Zy2yOcCZOta1Ffnfu+7Hy6ODMpk8aERyTtpyFqSOB9xtqVsRPjJiuHuHwTXdW3reCzZmrKUL93cGu4+shxc3qKTKCkPQTrzYXAj74E/v0PC9zLh/xnE15C5/fku9eWMAXj64+KqqZi8Ww+QBm842EJ0U= 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=g76E/EJT; arc=none smtp.client-ip=209.85.222.181 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-f181.google.com with SMTP id af79cd13be357-78d54a3e462so263150985a.0 for ; Mon, 15 Apr 2024 12:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713209681; x=1713814481; 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=33KvbvTql7+TfuU6gagkdE47f06z1GuAxIph77Mkm3M=; b=g76E/EJTDtrkZb6sBB4tJfxz3/pyyjo6H/KmEgP2J9pyPI8Zyc6KMtds96mo5ip8+a Vq6PP0BTSpV08gGNv+qf7KZDHTAHE3+owmHAW3Rc+dnifcnLqwj6NL3Fbqeu0maTOs19 INkY/kOnYLodye3C1IzOfQgP/PqlHfgLtZSag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713209681; x=1713814481; 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=33KvbvTql7+TfuU6gagkdE47f06z1GuAxIph77Mkm3M=; b=I+zjzea/deCKPZUFdwyDayQhb76xIbGUbYtUS13oWh/1pTz7kafdiWU98wHionUHi4 qCIT5U6OB16bThYt3bbzSuqYkjN2r2JzOd0Kg/K6Nb7Xrv9qMlisbxQ9esvNzYymd4mn BOKNx24Bc8joIgvWANF4AKKpGRfGZERqlhzJpNSkvFGgtn46edZtKFJrslKb54inMGnE xezDfHUV8R4y0TsiiocVFl2w3/IiaFC3+MtKsLrKqe1J23WOuFgKTpzFq6soJs2j+jvx Jf+D4ZxsQNwKU4+5gvCl8hOzE6+4n31QojAvtmIUMlZkSP0IH2w88QG8hq68OU6f8cmo tOmg== X-Forwarded-Encrypted: i=1; AJvYcCVSHMlcqy47F8EiX32r7qd61S3tylEWJYivSAlycNYmwi9tqWzNUfQfpBXuiigmI+SpTgZss7LnVHn1/cr+7qUu7SG++zwXnmSBYzEc X-Gm-Message-State: AOJu0Yw172kenJvFdewmU4pkWkFwoi3XxlBfrfPF42VxS1mkPC0lQf4y te/dMwP0puEOu160GLyqTD1LHhb5oMGzlLdof2DFVXRYSAdqFpMFZtPZfBJ/iw== X-Received: by 2002:a05:620a:5719:b0:78d:6b8e:18d with SMTP id wi25-20020a05620a571900b0078d6b8e018dmr11861292qkn.64.1713209681163; Mon, 15 Apr 2024 12:34:41 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 12:34:40 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 15 Apr 2024 19:34:29 +0000 Subject: [PATCH 12/35] media: platform: mtk-mdp3: Use refcount_t for job_count 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-12-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 job_count. Found by cocci: drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c:527:5-24: WARNING: atomic_dec_and_test variation before object free at line 541. drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c:578:6-25: WARNING: atomic_dec_and_test variation before object free at line 581. Signed-off-by: Ricardo Ribalda --- drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 10 +++++----- drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c | 6 +++--- drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h | 2 +- drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c index 1d64bac34b90..ea2ea119dd2a 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c @@ -524,7 +524,7 @@ static void mdp_auto_release_work(struct work_struct *work) mdp_comp_clocks_off(&mdp->pdev->dev, cmd->comps, cmd->num_comps); - if (atomic_dec_and_test(&mdp->job_count)) { + if (refcount_dec_and_test(&mdp->job_count)) { if (cmd->mdp_ctx) mdp_m2m_job_finish(cmd->mdp_ctx); @@ -575,7 +575,7 @@ static void mdp_handle_cmdq_callback(struct mbox_client *cl, void *mssg) mdp_comp_clocks_off(&mdp->pdev->dev, cmd->comps, cmd->num_comps); - if (atomic_dec_and_test(&mdp->job_count)) + if (refcount_dec_and_test(&mdp->job_count)) wake_up(&mdp->callback_wq); mdp_cmdq_pkt_destroy(&cmd->pkt); @@ -724,9 +724,9 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param) int i, ret; u8 pp_used = __get_pp_num(param->param->type); - atomic_set(&mdp->job_count, pp_used); + refcount_set(&mdp->job_count, pp_used); if (atomic_read(&mdp->suspended)) { - atomic_set(&mdp->job_count, 0); + refcount_set(&mdp->job_count, 0); return -ECANCELED; } @@ -764,7 +764,7 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param) mdp_comp_clocks_off(&mdp->pdev->dev, cmd[i]->comps, cmd[i]->num_comps); err_cancel_job: - atomic_set(&mdp->job_count, 0); + refcount_set(&mdp->job_count, 0); return ret; } diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c index 5209f531ef8d..c1f3bf98120a 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c @@ -380,14 +380,14 @@ static int __maybe_unused mdp_suspend(struct device *dev) atomic_set(&mdp->suspended, 1); - if (atomic_read(&mdp->job_count)) { + if (refcount_read(&mdp->job_count)) { ret = wait_event_timeout(mdp->callback_wq, - !atomic_read(&mdp->job_count), + !refcount_read(&mdp->job_count), 2 * HZ); if (ret == 0) { dev_err(dev, "%s:flushed cmdq task incomplete, count=%d\n", - __func__, atomic_read(&mdp->job_count)); + __func__, refcount_read(&mdp->job_count)); return -EBUSY; } } diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h index 8c09e984fd01..430251f63754 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.h @@ -134,7 +134,7 @@ struct mdp_dev { /* synchronization protect for m2m device operation */ struct mutex m2m_lock; atomic_t suspended; - atomic_t job_count; + refcount_t job_count; }; struct mdp_pipe_info { diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c index 35a8b059bde5..0e69128a3772 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-m2m.c @@ -104,14 +104,14 @@ static void mdp_m2m_device_run(void *priv) task.cb_data = NULL; task.mdp_ctx = ctx; - if (atomic_read(&ctx->mdp_dev->job_count)) { + if (refcount_read(&ctx->mdp_dev->job_count)) { ret = wait_event_timeout(ctx->mdp_dev->callback_wq, - !atomic_read(&ctx->mdp_dev->job_count), + !refcount_read(&ctx->mdp_dev->job_count), 2 * HZ); if (ret == 0) { dev_err(&ctx->mdp_dev->pdev->dev, "%d jobs not yet done\n", - atomic_read(&ctx->mdp_dev->job_count)); + refcount_read(&ctx->mdp_dev->job_count)); goto worker_end; } } -- 2.44.0.683.g7961c838ac-goog