Commit 479043b7 authored by James Clark's avatar James Clark Committed by Suzuki K Poulose

coresight: cti: Remove atomic type from enable_req_count

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: default avatarJames Clark <james.clark@arm.com>
Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20230110110736.2709917-4-james.clark@arm.com
parent eff674a9
...@@ -107,12 +107,12 @@ static int cti_enable_hw(struct cti_drvdata *drvdata) ...@@ -107,12 +107,12 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
cti_write_all_hw_regs(drvdata); cti_write_all_hw_regs(drvdata);
config->hw_enabled = true; config->hw_enabled = true;
atomic_inc(&drvdata->config.enable_req_count); drvdata->config.enable_req_count++;
spin_unlock_irqrestore(&drvdata->spinlock, flags); spin_unlock_irqrestore(&drvdata->spinlock, flags);
return rc; return rc;
cti_state_unchanged: cti_state_unchanged:
atomic_inc(&drvdata->config.enable_req_count); drvdata->config.enable_req_count++;
/* cannot enable due to error */ /* cannot enable due to error */
cti_err_not_enabled: cti_err_not_enabled:
...@@ -129,7 +129,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata) ...@@ -129,7 +129,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
config->hw_powered = true; config->hw_powered = true;
/* no need to do anything if no enable request */ /* 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; goto cti_hp_not_enabled;
/* try to claim the device */ /* try to claim the device */
...@@ -156,13 +156,13 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) ...@@ -156,13 +156,13 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)
spin_lock(&drvdata->spinlock); spin_lock(&drvdata->spinlock);
/* don't allow negative refcounts, return an error */ /* don't allow negative refcounts, return an error */
if (!atomic_read(&drvdata->config.enable_req_count)) { if (!drvdata->config.enable_req_count) {
ret = -EINVAL; ret = -EINVAL;
goto cti_not_disabled; goto cti_not_disabled;
} }
/* check refcount - disable on 0 */ /* 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; goto cti_not_disabled;
/* no need to do anything if disabled or cpu unpowered */ /* no need to do anything if disabled or cpu unpowered */
...@@ -239,7 +239,7 @@ static void cti_set_default_config(struct device *dev, ...@@ -239,7 +239,7 @@ static void cti_set_default_config(struct device *dev,
/* Most regs default to 0 as zalloc'ed except...*/ /* Most regs default to 0 as zalloc'ed except...*/
config->trig_filter_enable = true; config->trig_filter_enable = true;
config->ctigate = GENMASK(config->nr_ctm_channels - 1, 0); 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, ...@@ -696,7 +696,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
drvdata->config.hw_enabled = false; drvdata->config.hw_enabled = false;
/* check enable reference count to enable HW */ /* 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 */ /* check we can claim the device as we re-power */
if (coresight_claim_device(csdev)) if (coresight_claim_device(csdev))
goto cti_notify_exit; goto cti_notify_exit;
......
...@@ -84,8 +84,8 @@ static ssize_t enable_show(struct device *dev, ...@@ -84,8 +84,8 @@ static ssize_t enable_show(struct device *dev,
bool enabled, powered; bool enabled, powered;
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent); struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
enable_req = atomic_read(&drvdata->config.enable_req_count);
spin_lock(&drvdata->spinlock); spin_lock(&drvdata->spinlock);
enable_req = drvdata->config.enable_req_count;
powered = drvdata->config.hw_powered; powered = drvdata->config.hw_powered;
enabled = drvdata->config.hw_enabled; enabled = drvdata->config.hw_enabled;
spin_unlock(&drvdata->spinlock); spin_unlock(&drvdata->spinlock);
......
...@@ -141,7 +141,7 @@ struct cti_config { ...@@ -141,7 +141,7 @@ struct cti_config {
int nr_trig_max; int nr_trig_max;
/* cti enable control */ /* cti enable control */
atomic_t enable_req_count; int enable_req_count;
bool hw_enabled; bool hw_enabled;
bool hw_powered; bool hw_powered;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment