RE: [PATCH 7/8] coresight: cti: Remove hw_enabled flag
From: Mike Leach
Date: Fri Feb 20 2026 - 09:37:12 EST
Hi Leo,
> -----Original Message-----
> From: Leo Yan <leo.yan@xxxxxxx>
> Sent: Monday, February 9, 2026 6:01 PM
> To: Suzuki Poulose <Suzuki.Poulose@xxxxxxx>; Mike Leach
> <Mike.Leach@xxxxxxx>; James Clark <james.clark@xxxxxxxxxx>; Alexander
> Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>; Greg Kroah-Hartman
> <gregkh@xxxxxxxxxxxxxxxxxxx>; Mathieu Poirier
> <mathieu.poirier@xxxxxxxxxx>; Tingwei Zhang <quic_tingwei@xxxxxxxxxxx>;
> Yingchao Deng <yingchao.deng@xxxxxxxxxxxxxxxx>; Jie Gan
> <jie.gan@xxxxxxxxxxxxxxxx>
> Cc: coresight@xxxxxxxxxxxxxxxx; linux-arm-kernel@xxxxxxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; Leo Yan <Leo.Yan@xxxxxxx>
> Subject: [PATCH 7/8] coresight: cti: Remove hw_enabled flag
>
> The enable_req_count field already tracks whether the CTI device is
> enabled. A non-zero value indicates that the device is active, the
> hw_enabled flag is redundant if so.
>
Minor nit - removal of this flag actually started in the previous patch. If respinning might be worth combining this and the previous one.
> Remove hw_enabled and update cti_is_active() to check enable_req_count.
> Replace open-coded enable_req_count checks with cti_is_active().
>
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> drivers/hwtracing/coresight/coresight-cti-core.c | 11 ++---------
> drivers/hwtracing/coresight/coresight-cti-sysfs.c | 2 +-
> drivers/hwtracing/coresight/coresight-cti.h | 4 +---
> 3 files changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c
> b/drivers/hwtracing/coresight/coresight-cti-core.c
> index
> 3b3b851a018851a8656eba64e638c61f3d04b99f..a7acee27d0aa2c842733f
> 62b7ff88a4c296b51cc 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-core.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-core.c
> @@ -90,7 +90,7 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
> guard(raw_spinlock_irqsave)(&drvdata->spinlock);
>
> /* no need to do anything if enabled */
> - if (config->hw_enabled)
> + if (cti_is_active(config))
> goto cti_state_unchanged;
>
> /* claim the device */
> @@ -100,8 +100,6 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
>
> cti_write_all_hw_regs(drvdata);
>
> - config->hw_enabled = true;
> -
> cti_state_unchanged:
> drvdata->config.enable_req_count++;
> return 0;
> @@ -116,22 +114,17 @@ static int cti_disable_hw(struct cti_drvdata
> *drvdata)
> guard(raw_spinlock_irqsave)(&drvdata->spinlock);
>
> /* don't allow negative refcounts, return an error */
> - if (!drvdata->config.enable_req_count)
> + if (!cti_is_active(config))
> return -EINVAL;
>
> /* check refcount - disable on 0 */
> if (--drvdata->config.enable_req_count > 0)
> return 0;
>
> - /* no need to do anything if disabled */
> - if (!config->hw_enabled)
> - return 0;
> -
> CS_UNLOCK(drvdata->base);
>
> /* disable CTI */
> writel_relaxed(0, drvdata->base + CTICONTROL);
> - config->hw_enabled = false;
>
> coresight_disclaim_device_unlocked(csdev);
> CS_LOCK(drvdata->base);
> diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> index
> 9ab586a5c9a4fd2a64c542aaaaa625e2299edd62..9ef44956ebdc7781717d7
> 73fa014165989df2048 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> @@ -84,7 +84,7 @@ static ssize_t enable_show(struct device *dev,
> struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
>
> scoped_guard(raw_spinlock_irqsave, &drvdata->spinlock)
> - enable_req = drvdata->config.enable_req_count;
> + enable_req = cti_is_active(&drvdata->config);
>
> return sprintf(buf, "%d\n", !!enable_req);
> }
> diff --git a/drivers/hwtracing/coresight/coresight-cti.h
> b/drivers/hwtracing/coresight/coresight-cti.h
> index
> c858847a5b80036fb48180ff7fbbfe684028cb89..fbb48eb5b0b6a571235d7f
> ecb2c13fc294d8ba50 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.h
> +++ b/drivers/hwtracing/coresight/coresight-cti.h
> @@ -121,7 +121,6 @@ struct cti_device {
> * @nr_ctm_channels: number of available CTM channels - from ID register.
> * @asicctl_impl: true if asicctl is implemented.
> * @enable_req_count: CTI is enabled alongside >=1 associated devices.
> - * @hw_enabled: true if hw is currently enabled.
> * @trig_in_use: bitfield of in triggers registered as in use.
> * @trig_out_use: bitfield of out triggers registered as in use.
> * @trig_out_filter: bitfield of out triggers that are blocked if filter
> @@ -144,7 +143,6 @@ struct cti_config {
>
> /* cti enable control */
> int enable_req_count;
> - bool hw_enabled;
>
> /* registered triggers and filtering */
> u32 trig_in_use;
> @@ -238,7 +236,7 @@ const char *cti_plat_get_node_name(struct
> fwnode_handle *fwnode);
> /* Check if a cti device is enabled */
> static inline bool cti_is_active(struct cti_config *cfg)
> {
> - return cfg->hw_enabled;
> + return !!cfg->enable_req_count;
> }
>
> #endif /* _CORESIGHT_CORESIGHT_CTI_H */
>
> --
> 2.34.1
Reviewed-by: Mike Leach <mike.leach@xxxxxxx>