Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2365360pxp; Fri, 18 Mar 2022 09:04:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxirXqVIEHGGBe26Zq29NlPyL3XHpM62dlhoW6LZdARMFPwwQOmfNeGYx87HLNiFphKpSSS X-Received: by 2002:a17:90a:205:b0:1c6:5b78:5c5 with SMTP id c5-20020a17090a020500b001c65b7805c5mr14843947pjc.54.1647619470957; Fri, 18 Mar 2022 09:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647619470; cv=none; d=google.com; s=arc-20160816; b=EKEg+13tRYdzE3+fE2Wtv4m1unlswA2IMLjcRYATALaSVGkdYvYR2oIroXUoeei6mD 5GbTWAw5VjL52Zh484aGIAotb9EctoLFISlP6pJtZnxBg4zjy8PWcjLitfleuVba37DI rVQIW/FV/+6+m2oOWQQRl65ltGP5hnD0dESFYgBaSlMiRrmJKZVTvPZpWPC/EXwiKz0I ExESjD+TKRML/U+nc3E1+yLMo7dB4igCSMupArqCLdmlGxZAkiBUQKPFb6LKbjcBnjBc usLC1LaUGxdemac/GvbjwH+unt9mnL2CtK2IOU649zTPyXLPWkTSvv2qbRZMb/VIki+k cH0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=ufdCtUXsz/YiIb60f/cSxA++orqdk2i6/27t43ZfaRY=; b=CdDAVbNkg9mXl/l1Ow1HPUitBuPdOqbqDS/AOh5rWqlS/5yNjM+PDBo1I6ahOyUCUo CSTnC+DIefEvAbmUaR0RZtv9Vf8SH3Qpu/dpdn5kSq0UKJ2984IAK7/A3MIusIoCf+ag kTVcWrZ+8COGFwzcRb0zLG5qddBjQKYmqWRA1Ar9mBIu7j5e/Fkh71qrpytBaommhytZ JWVQWJNHy0vBMaCqf5SxHDkUOqWbI3S5POO/oX5RRQ2sga3lpiuZElen0h1bZpWDU5jN CdhwGb8y9NnMiCOtiLC31lxEdDXUaUH0YoK9GloR5ecGkqtza1h8qgpMKMVKWbB+lKcX 8dSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a170902c38500b00153b2d164bfsi2435680plg.199.2022.03.18.09.04.16; Fri, 18 Mar 2022 09:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234801AbiCRKCg (ORCPT + 99 others); Fri, 18 Mar 2022 06:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234079AbiCRKCf (ORCPT ); Fri, 18 Mar 2022 06:02:35 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C15100E09; Fri, 18 Mar 2022 03:01:16 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 1DE441A1F2A; Fri, 18 Mar 2022 11:01:15 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D3A261A1F1D; Fri, 18 Mar 2022 11:01:14 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 83AEC183AD67; Fri, 18 Mar 2022 18:01:13 +0800 (+08) From: Shengjiu Wang To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com Subject: [PATCH] remoteproc: core: check rproc->power value before decreasing it Date: Fri, 18 Mar 2022 17:51:36 +0800 Message-Id: <1647597096-5480-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are possibility that two 'stop' operation happen in parallel, then the rproc->power may be decreased to -1, that this reference count will be in wrong state. So check rproc->power to make sure it is larger than zero before decreasing it. Signed-off-by: Shengjiu Wang --- drivers/remoteproc/remoteproc_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c510125769b9..84e065ad8743 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2075,6 +2075,9 @@ int rproc_shutdown(struct rproc *rproc) return ret; } + if (atomic_read(&rproc->power) <= 0) + goto out; + /* if the remote proc is still needed, bail out */ if (!atomic_dec_and_test(&rproc->power)) goto out; -- 2.17.1