Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2556218rwl; Fri, 6 Jan 2023 08:00:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXtCHjEvBlKjpBR2YD/fNtTCW7EmA6Eu2/Y4gHqRNqYYDqqxVyrOh161ZZO+//7Q/YhjKRL9 X-Received: by 2002:a17:90a:7503:b0:226:c196:db55 with SMTP id q3-20020a17090a750300b00226c196db55mr9341280pjk.18.1673020841359; Fri, 06 Jan 2023 08:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673020841; cv=none; d=google.com; s=arc-20160816; b=L15qGeyLLNhrpGWLCqiO4u3vjAN8YY7MjbXdOjMvfDryMPhzc3uZyiEMxpi0wROKn0 JZwUztUsNl0KpK0k37a7pVng1igZ9SiavKIVaIJ8k+nOCrhrNhCTE+D8d9oSLCfqKrxK /1cwNCsFhSSzencwUQN66TiRAMbeWG9N0/uAMHNw/Dv9/2vBIAspFlvFCq6yGH+US1/u Q8zmtVbUXzi8QRXjDm7CIjOfc7YxEnJaO2ViaAdzebif7FmrDQ5QqoN3TCk7M6fbvhU7 lSxjX1v7bVw6GrkGpAUZjsumNzkpNypjUrp6mae+xNk6y/j87XPSX9/Q9plJAfnXkj86 NJOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vZgwaGsG68bVOS27H11rwRjuZNB/vkzG/qm1T65bKjY=; b=XPuPVwPemp5at05GyXQMM7J2Yj6c7zHyGwSOSQJwwc5y7MxzkBsjBGfyAHOQNXFlOf 3ITHwIRhTsNatnB8yjWad8wJMMvXcYjnjJqdsz+5b3Ebdikg9F5k6EkPFiiqhOBIAGrd hpqSZ67uC/vFg2S9WlR9WYiNA5m7NE09tcTYmxpcn9+krnilgOT/4bsBms/W3jJ6ni8b CIS9FQo0zdnD2P8sUgcfOkzNuyqkgxdlmYXwRExyOcVWpl/t3ZYU4qa61Umgr2/AXyrc pymP1/TLijN1K0GiETr5OIQuOqsDYn+5KdQrj2tkTv85ZqtUQyG2AUP2cndEEPAk3B6a 0EJA== 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=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nt1-20020a17090b248100b00226a8c884a2si1519768pjb.95.2023.01.06.08.00.34; Fri, 06 Jan 2023 08:00:41 -0800 (PST) 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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232291AbjAFPXs (ORCPT + 54 others); Fri, 6 Jan 2023 10:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232331AbjAFPXn (ORCPT ); Fri, 6 Jan 2023 10:23:43 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E650B45649 for ; Fri, 6 Jan 2023 07:23:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8552812FC; Fri, 6 Jan 2023 07:24:23 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 220673F71A; Fri, 6 Jan 2023 07:23:40 -0800 (PST) From: James Clark To: coresight@lists.linaro.org, quic_jinlmao@quicinc.com, suzuki.poulose@arm.com, mike.leach@linaro.org Cc: James Clark , Mathieu Poirier , Leo Yan , Alexander Shishkin , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] coresight: cti: Prevent negative values of enable count Date: Fri, 6 Jan 2023 15:23:28 +0000 Message-Id: <20230106152331.1374973-2-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230106152331.1374973-1-james.clark@arm.com> References: <20230106152331.1374973-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 Writing 0 to the enable control repeatedly results in a negative value for enable_req_count. After this, writing 1 to the enable control appears to not work until the count returns to positive. Change it so that it's impossible for enable_req_count to be < 0. Returning an error will also allow us to decide whether to call runtime_pm_put() or not in the following commit. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-cti-core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c b/drivers/hwtracing/coresight/coresight-cti-core.c index d2cf4f4848e1..838872f2484d 100644 --- a/drivers/hwtracing/coresight/coresight-cti-core.c +++ b/drivers/hwtracing/coresight/coresight-cti-core.c @@ -151,9 +151,16 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) { struct cti_config *config = &drvdata->config; struct coresight_device *csdev = drvdata->csdev; + int ret = 0; spin_lock(&drvdata->spinlock); + /* don't allow negative refcounts, return an error */ + if (!atomic_read(&drvdata->config.enable_req_count)) { + ret = -EINVAL; + goto cti_not_disabled; + } + /* check refcount - disable on 0 */ if (atomic_dec_return(&drvdata->config.enable_req_count) > 0) goto cti_not_disabled; @@ -171,12 +178,12 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) coresight_disclaim_device_unlocked(csdev); CS_LOCK(drvdata->base); spin_unlock(&drvdata->spinlock); - return 0; + return ret; /* not disabled this call */ cti_not_disabled: spin_unlock(&drvdata->spinlock); - return 0; + return ret; } void cti_write_single_reg(struct cti_drvdata *drvdata, int offset, u32 value) -- 2.25.1