Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2532410rwl; Fri, 6 Jan 2023 07:41:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXv79tpINrfA29+P9NjL5+GFyOmYrbL7mEPPLZpRWVyp5A/4vXD4aD9nVr4pJ6blkYfZ3bcT X-Received: by 2002:a17:906:6896:b0:7c1:4c46:30a0 with SMTP id n22-20020a170906689600b007c14c4630a0mr50928246ejr.65.1673019679575; Fri, 06 Jan 2023 07:41:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673019679; cv=none; d=google.com; s=arc-20160816; b=si8P3KhNCAi07hKoJbUV3oI8cqZ/b66sqCvI2rJU/fcrX9rIoTBOJIZN3ER/KnR6b6 xNJZPTrTQqQhapldGuKM3KM4oTkJ/0kAwHk2YuqhKbVMVR5vxJQEQ5hTO72IVP1V81ns ySkGxQWyIHXN9mB4Bx9uRqmcpJXhdCyTaOV/tgf68YlmncwcN2yVeOxF4VZ4xG3AvxSQ 49J3trUInAuDYKxWK+2OM0AS/a8nUJPK9r34mRSsrsnKI+q5H4EwcTSlFkz3VIITpWL/ La04+fXxUbef/M7gIHYuAzgqgmT3zKbxxAMaq15Dlz4MaoMOX20p9kVfPKmGsRJAMekp ni/g== 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=un/+3nd+MF+10pVy1TiuQXO/nIH4zE4iSKe+sAsEbD4=; b=nFAwNf6O2hGi9teLn3ikmWClssEgNwknexpCFYzGBe3RVLOqPrrfopA+OsNhU7qTsW Mve89SGuiF7zS/Fk7YVabhJAH7Qi6KqNBKZHUZ9J4zFyQfyTFIcuKCnXfRAIF2WWH0wY hg9bL99CWQ93vGa+csIjLW9WohUeJP10kaIMnT6i1w2GtFmW33JH34xopSNLO5VE9cjs ncUSc7y3m9nIi81a3LdMSvMO6EOrtu0FTbgKjc8Gv02yRZTsNKwChFV1vw2ktRkh5f5E a2wMQ7Kn0ue0vyhJzmcYSf1CYk6Prcc8znKkJYsyhRRm0/ykP9vtzqC71V/IMCoLSs6F s+1w== 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 l18-20020a170906795200b0078266dc4b8csi2017039ejo.719.2023.01.06.07.41.06; Fri, 06 Jan 2023 07:41:19 -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 S233812AbjAFPYF (ORCPT + 54 others); Fri, 6 Jan 2023 10:24:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233592AbjAFPXr (ORCPT ); Fri, 6 Jan 2023 10:23:47 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7F4AB6ECAC for ; Fri, 6 Jan 2023 07:23:46 -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 14DAC15A1; Fri, 6 Jan 2023 07:24:28 -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 A5D943F71A; Fri, 6 Jan 2023 07:23:44 -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 3/3] coresight: cti: Remove atomic type from enable_req_count Date: Fri, 6 Jan 2023 15:23:30 +0000 Message-Id: <20230106152331.1374973-4-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 enable_req_count is only ever accessed inside the spinlock, so to avoid confusion that there are concurrent accesses and simplify the code, change it to an int. One access outside of the spinlock is in enable_show() which appears to allow partially written data to be displayed between enable_req_count, powered and enabled so move this one inside the spin lock too. Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-cti-core.c | 14 +++++++------- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-cti.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c b/drivers/hwtracing/coresight/coresight-cti-core.c index 838872f2484d..277c890a1f1f 100644 --- a/drivers/hwtracing/coresight/coresight-cti-core.c +++ b/drivers/hwtracing/coresight/coresight-cti-core.c @@ -107,12 +107,12 @@ static int cti_enable_hw(struct cti_drvdata *drvdata) cti_write_all_hw_regs(drvdata); config->hw_enabled = true; - atomic_inc(&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++; spin_unlock_irqrestore(&drvdata->spinlock, flags); return rc; cti_state_unchanged: - atomic_inc(&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++; /* cannot enable due to error */ cti_err_not_enabled: @@ -129,7 +129,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata) config->hw_powered = true; /* no need to do anything if no enable request */ - if (!atomic_read(&drvdata->config.enable_req_count)) + if (!drvdata->config.enable_req_count) goto cti_hp_not_enabled; /* try to claim the device */ @@ -156,13 +156,13 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) spin_lock(&drvdata->spinlock); /* don't allow negative refcounts, return an error */ - if (!atomic_read(&drvdata->config.enable_req_count)) { + if (!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) + if (--drvdata->config.enable_req_count > 0) goto cti_not_disabled; /* no need to do anything if disabled or cpu unpowered */ @@ -239,7 +239,7 @@ static void cti_set_default_config(struct device *dev, /* Most regs default to 0 as zalloc'ed except...*/ config->trig_filter_enable = true; config->ctigate = GENMASK(config->nr_ctm_channels - 1, 0); - atomic_set(&config->enable_req_count, 0); + config->enable_req_count = 0; } /* @@ -696,7 +696,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd, drvdata->config.hw_enabled = false; /* check enable reference count to enable HW */ - if (atomic_read(&drvdata->config.enable_req_count)) { + if (drvdata->config.enable_req_count) { /* check we can claim the device as we re-power */ if (coresight_claim_device(csdev)) goto cti_notify_exit; diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c b/drivers/hwtracing/coresight/coresight-cti-sysfs.c index 71e7a8266bb3..e528cff9d4e2 100644 --- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c @@ -84,8 +84,8 @@ static ssize_t enable_show(struct device *dev, bool enabled, powered; struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); - enable_req = atomic_read(&drvdata->config.enable_req_count); spin_lock(&drvdata->spinlock); + enable_req = drvdata->config.enable_req_count; powered = drvdata->config.hw_powered; enabled = drvdata->config.hw_enabled; spin_unlock(&drvdata->spinlock); diff --git a/drivers/hwtracing/coresight/coresight-cti.h b/drivers/hwtracing/coresight/coresight-cti.h index acf7b545e6b9..8b106b13a244 100644 --- a/drivers/hwtracing/coresight/coresight-cti.h +++ b/drivers/hwtracing/coresight/coresight-cti.h @@ -141,7 +141,7 @@ struct cti_config { int nr_trig_max; /* cti enable control */ - atomic_t enable_req_count; + int enable_req_count; bool hw_enabled; bool hw_powered; -- 2.25.1