From patchwork Fri Jan 6 15:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 40169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp879532wrt; Fri, 6 Jan 2023 07:25:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsW9dbs1CeHRanR7ivskY1pQhtda8QwIXsZpH8dDdVkNtLQMzKBMAWmV+7nNb29myYr4Zze X-Received: by 2002:a05:6a00:288f:b0:581:fddb:749c with SMTP id ch15-20020a056a00288f00b00581fddb749cmr28392499pfb.5.1673018720708; Fri, 06 Jan 2023 07:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673018720; cv=none; d=google.com; s=arc-20160816; b=rcHBn+/eE5gzWc9x+M4PYJeDwVqct7h3hHBWKQi4aT8HalQB/o3o17lmEJoFhQ+yLV vufzkkN9K2tE0Hwf3V0VDqCG1NtcY1URcHlW7pjEFJY7LcwTCvj5nWaMRhaYEjKAExdM sXYAHjLLtf6Xb6U+acr1ItFeV34Sj8EeMRY4KHea+wk7GestxbIt3SNF/U4Vy6vgQtdq nIc/jfCA6pBUK1boYSSb0qAjpxx3iGVBLCm5dPWd6H8ePoq+nNo2s2EWNRYAYUwHg5vr Ihgq+sY+U0qJnGWRwWURCGrxsEzxWDKMsJpCYOt/Iyjj25wCQpaICCD18PEnxRIzmZjS ObaQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a056a000cd600b0056de69b0c7esi1649803pfv.284.2023.01.06.07.25.07; Fri, 06 Jan 2023 07:25:20 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754287277630373603?= X-GMAIL-MSGID: =?utf-8?q?1754287277630373603?= 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)