Skip to contentSkip to conversation

coresight: etm4x: Fix etm4_count race by moving cpuhp callbacks to init

PATCH Superseded Sai Prakash Ranjan 3 participants 5 messages Jul 28, 2020 – Jul 29, 2020

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 coresight: etm4x: Fix etm4_count race by moving cpuhp callbacks to init

etm4_count keeps track of number of ETMv4 registered and on some systems, a race is observed on etm4_count variable which can lead to multiple calls to cpuhp_setup_state_nocalls_cpuslocked(). This function internally calls cpuhp_store_callbacks() which prevents multiple registrations of callbacks for a given state and due to this race, it returns -EBUSY leading to ETM probe failures like below.

coresight-etm4x: probe of 7040000.etm failed with error -16

This race can easily be triggered with async probe by setting probe type as PROBE_PREFER_ASYNCHRONOUS and with ETM power management property "arm,coresight-loses-context-with-cpu".

Prevent this race by moving cpuhp callbacks to etm driver init since the cpuhp callbacks doesn't have to depend on the etm4_count and can be once setup during driver init. Similarly we move cpu_pm notifier registration to driver init and completely remove etm4_count usage.

Fixes 9b6a3f3633a5 ("coresight: etmv4: Fix CPU power management setup in probe() function")
Fixes 58eb457be028 ("hwtracing/coresight-etm4x: Convert to hotplug state machine")

---

Changes in v2:
* Rearrange cpuhp callbacks and move them to driver init (Suzuki K Poulose)

---
 drivers/hwtracing/coresight/coresight-etm4x.c | 51 ++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +27 -24
index 6d7d2169bfb2..adb71987a1e3 100644
@@ -48,8 +48,6 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
 	"Save/restore state on power down: 1 = never, 2 = self-hosted");
 
-/* The number of ETMv4 currently registered */
-static int etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);
 static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
@@ -1403,12 +1401,9 @@ static int etm4_pm_setup_cpuslocked(void)
 {
 	int ret;
 
-	if (etm4_count++)
-		return 0;
-
 	ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
 	if (ret)
-		goto reduce_count;
+		return ret;
 
 	ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
 						   "arm/coresight4:starting",
@@ -1432,17 +1427,11 @@ static int etm4_pm_setup_cpuslocked(void)
 
 unregister_notifier:
 	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-
-reduce_count:
-	--etm4_count;
 	return ret;
 }
 
 static void etm4_pm_clear(void)
 {
-	if (--etm4_count != 0)
-		return;
-
 	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
 	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
 	if (hp_online) {
@@ -1498,22 +1487,12 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	if (!desc.name)
 		return -ENOMEM;
 
-	cpus_read_lock();
 	etmdrvdata[drvdata->cpu] = drvdata;
 
 	if (smp_call_function_single(drvdata->cpu,
 				etm4_init_arch_data,  drvdata, 1))
 		dev_err(dev, "ETM arch init failed\n");
 
-	ret = etm4_pm_setup_cpuslocked();
-	cpus_read_unlock();
-
-	/* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
-	if (ret) {
-		etmdrvdata[drvdata->cpu] = NULL;
-		return ret;
-	}
-
 	if (etm4_arch_supported(drvdata->arch) == false) {
 		ret = -EINVAL;
 		goto err_arch_supported;
@@ -1560,7 +1539,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 
 err_arch_supported:
 	etmdrvdata[drvdata->cpu] = NULL;
-	etm4_pm_clear();
 	return ret;
 }
 
@@ -1598,4 +1576,29 @@ static struct amba_driver etm4x_driver = {
 	.probe		= etm4_probe,
 	.id_table	= etm4_ids,
 };
-builtin_amba_driver(etm4x_driver);
+
+static int __init etm4x_init(void)
+{
+	int ret;
+
+	cpus_read_lock();
+	ret = etm4_pm_setup_cpuslocked();
+	cpus_read_unlock();
+
+	/* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
+	if (ret)
+		return ret;
+
+	ret = amba_driver_register(&etm4x_driver);
+	if (ret) {
+		pr_info("Error registering etm4x driver\n");
+		goto err_init;
+	}
+
+	return ret;
+
+err_init:
+	etm4_pm_clear();
+	return ret;
+}
+module_init(etm4x_init);
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

Quoting Sai Prakash Ranjan (2020-07-28 00:51:02)

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void)

Quoted 14 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0 -2
index 6d7d2169bfb2..adb71987a1e3 100644
@@ -48,8 +48,6 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
        "Save/restore state on power down: 1 = never, 2 = self-hosted");
 
-/* The number of ETMv4 currently registered */
-static int etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);
 static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
@@ -1403,12 +1401,9 @@ static int etm4_pm_setup_cpuslocked(void)

Is this only called from __init now? If so please mark it as __init then.

Quoted 14 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1 -4
 {
        int ret;
 
-       if (etm4_count++)
-               return 0;
-
        ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
        if (ret)
-               goto reduce_count;
+               return ret;
 
        ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
                                                   "arm/coresight4:starting",

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void) · line 1433

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0 -3
@@ -1432,17 +1427,11 @@ static int etm4_pm_setup_cpuslocked(void)
 
 unregister_notifier:
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-
-reduce_count:
-       --etm4_count;
        return ret;
 }
 
 static void etm4_pm_clear(void)

This is __init too?

Quoted 18 lines
drivers/hwtracing/coresight/coresight-etm4x.c +6 -4
 {
-       if (--etm4_count != 0)
-               return;
-
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
        cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
        if (hp_online) {
@@ -1598,4 +1576,29 @@ static struct amba_driver etm4x_driver = {
        .probe          = etm4_probe,
        .id_table       = etm4_ids,
 };
-builtin_amba_driver(etm4x_driver);
+
+static int __init etm4x_init(void)
+{
+       int ret;
+
+       cpus_read_lock();

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1594

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10 -0
+       ret = etm4_pm_setup_cpuslocked();
+       cpus_read_unlock();
+
+       /* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
+       if (ret)
+               return ret;
+
+       ret = amba_driver_register(&etm4x_driver);
+       if (ret) {
+               pr_info("Error registering etm4x driver\n");

Use pr_err() please.

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1600

Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +6 -0
+               goto err_init;
+       }
+
+       return ret;
+
+err_init:

Why is this a goto?

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1602

Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2 -0
+       etm4_pm_clear();
+       return ret;

Instead of just putting this in the if (ret) arm?

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1604

Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2 -0
+}
+module_init(etm4x_init);

It was device_initcall before with builtin_amba_driver(), best to not change that.

#2 lore raw
Quoted 10 lines · Stephen Boyd

Quoting Sai Prakash Ranjan (2020-07-28 00:51:02)

Quoted 9 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
index 6d7d2169bfb2..adb71987a1e3 100644
@@ -48,8 +48,6 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
        "Save/restore state on power down: 1 = never, 2 = 
 self-hosted");
 
Quoted 10 lines

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void)

Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0 -2
-/* The number of ETMv4 currently registered */
-static int etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);

static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,

drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
@@ -1403,12 +1401,9 @@ static int etm4_pm_setup_cpuslocked(void)

Is this only called from __init now? If so please mark it as __init then.

Yes, will change it.

Quoted 25 lines
Quoted 25 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1 -4
 {
        int ret;
 
-       if (etm4_count++)
-               return 0;
-
        ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
        if (ret)
-               goto reduce_count;
+               return ret;
 
        ret = 
 cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,

"arm/coresight4:starting",

drivers/hwtracing/coresight/coresight-etm4x.c +0 -3
@@ -1432,17 +1427,11 @@ static int etm4_pm_setup_cpuslocked(void)
 
 unregister_notifier:
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-
-reduce_count:
-       --etm4_count;
        return ret;
 }
 
Quoted 4 lines

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void) · line 1433

Quoted 1 line
drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
 static void etm4_pm_clear(void)

This is __init too?

Will change.

Quoted 23 lines
Quoted 23 lines
drivers/hwtracing/coresight/coresight-etm4x.c +10 -4
 {
-       if (--etm4_count != 0)
-               return;
-
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
        cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
        if (hp_online) {
@@ -1598,4 +1576,29 @@ static struct amba_driver etm4x_driver = {
        .probe          = etm4_probe,
        .id_table       = etm4_ids,
 };
-builtin_amba_driver(etm4x_driver);
+
+static int __init etm4x_init(void)
+{
+       int ret;
+
+       cpus_read_lock();
+       ret = etm4_pm_setup_cpuslocked();
+       cpus_read_unlock();
+
+       /* etm4_pm_setup_cpuslocked() does its own cleanup - exit on 

error */

Quoted 9 lines

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1594

Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +6 -0
+       if (ret)
+               return ret;
+
+       ret = amba_driver_register(&etm4x_driver);
+       if (ret) {
+               pr_info("Error registering etm4x driver\n");

Use pr_err() please.

Yes indeed, will change.

Quoted 9 lines

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1600

Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm4x.c +6 -0
+               goto err_init;
+       }
+
+       return ret;
+
+err_init:

Why is this a goto?

Quoted 5 lines

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1602

Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2 -0
+       etm4_pm_clear();
+       return ret;

Instead of just putting this in the if (ret) arm?

Will change.

Quoted 5 lines

drivers/hwtracing/coresight/coresight-etm4x.c

Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm4x.c +2 -0
+}
+module_init(etm4x_init);

It was device_initcall before with builtin_amba_driver(), best to not change that.

Sure.

I will wait to see if there are any more comments on this patch and then post a v3. Thanks for the review Stephen.

Thanks,
Sai

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw
In reply to Sai Prakash Ranjan

Hi Sai,

Quoted 46 lines · Sai Prakash Ranjan

etm4_count keeps track of number of ETMv4 registered and on some systems, a race is observed on etm4_count variable which can lead to multiple calls to cpuhp_setup_state_nocalls_cpuslocked(). This function internally calls cpuhp_store_callbacks() which prevents multiple registrations of callbacks for a given state and due to this race, it returns -EBUSY leading to ETM probe failures like below.

coresight-etm4x: probe of 7040000.etm failed with error -16

This race can easily be triggered with async probe by setting probe type as PROBE_PREFER_ASYNCHRONOUS and with ETM power management property "arm,coresight-loses-context-with-cpu".

Prevent this race by moving cpuhp callbacks to etm driver init since the cpuhp callbacks doesn't have to depend on the etm4_count and can be once setup during driver init. Similarly we move cpu_pm notifier registration to driver init and completely remove etm4_count usage.

Fixes 9b6a3f3633a5 ("coresight: etmv4: Fix CPU power management setup in probe() function")
Fixes 58eb457be028 ("hwtracing/coresight-etm4x: Convert to hotplug state machine")

---

Changes in v2:
* Rearrange cpuhp callbacks and move them to driver init (Suzuki K Poulose)

---
 drivers/hwtracing/coresight/coresight-etm4x.c | 51 ++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +0 -2
index 6d7d2169bfb2..adb71987a1e3 100644
@@ -48,8 +48,6 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
        "Save/restore state on power down: 1 = never, 2 = self-hosted");
 
-/* The number of ETMv4 currently registered */
-static int etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);
 static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void) · line 1401

Quoted 1 line
drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
@@ -1403,12 +1401,9 @@ static int etm4_pm_setup_cpuslocked(void)
 {

consider renaming this to etm4_pm_setup() and handing any cpu locking inside the function.
In the circumstances - as part of the driver init rather than probe it may be sufficient to call the cpuhp_setup functions without the _cpuslocked suffix and allow the calls to lock the cpus as they are made.
i.e. cpuhp_setup_state_nocalls_cpuslocked() => cpuhp_setup_state_nocalls()

Quoted 64 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1 -21
        int ret;
 
-       if (etm4_count++)
-               return 0;
-
        ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
        if (ret)
-               goto reduce_count;
+               return ret;
 
        ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
                                                   "arm/coresight4:starting",
@@ -1432,17 +1427,11 @@ static int etm4_pm_setup_cpuslocked(void)
 
 unregister_notifier:
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-
-reduce_count:
-       --etm4_count;
        return ret;
 }
 
 static void etm4_pm_clear(void)
 {
-       if (--etm4_count != 0)
-               return;
-
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
        cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
        if (hp_online) {
@@ -1498,22 +1487,12 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
        if (!desc.name)
                return -ENOMEM;
 
-       cpus_read_lock();
        etmdrvdata[drvdata->cpu] = drvdata;
 
        if (smp_call_function_single(drvdata->cpu,
                                etm4_init_arch_data,  drvdata, 1))
                dev_err(dev, "ETM arch init failed\n");
 
-       ret = etm4_pm_setup_cpuslocked();
-       cpus_read_unlock();
-
-       /* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
-       if (ret) {
-               etmdrvdata[drvdata->cpu] = NULL;
-               return ret;
-       }
-
        if (etm4_arch_supported(drvdata->arch) == false) {
                ret = -EINVAL;
                goto err_arch_supported;
@@ -1560,7 +1539,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 
 err_arch_supported:
        etmdrvdata[drvdata->cpu] = NULL;
-       etm4_pm_clear();
        return ret;
 }
 
@@ -1598,4 +1576,29 @@ static struct amba_driver etm4x_driver = {
        .probe          = etm4_probe,
        .id_table       = etm4_ids,

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1586

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x.c +8 -1
 };
-builtin_amba_driver(etm4x_driver);
+
+static int __init etm4x_init(void)
+{
+       int ret;
+
+       cpus_read_lock();
+       ret = etm4_pm_setup_cpuslocked();
+       cpus_read_unlock();

See my comment above about rename and use of cpus_read_lock

Regards

Mike

Quoted 26 lines
drivers/hwtracing/coresight/coresight-etm4x.c +18 -1
+
+       /* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
+       if (ret)
+               return ret;
+
+       ret = amba_driver_register(&etm4x_driver);
+       if (ret) {
+               pr_info("Error registering etm4x driver\n");
+               goto err_init;
+       }
+
+       return ret;
+
+err_init:
+       etm4_pm_clear();
+       return ret;
+}
+module_init(etm4x_init);
--

QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

_______________________________________________
CoreSight mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/coresight

Signature · 3 lines
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
#4 lore raw

Hi Mike,

Quoted 47 lines · Mike Leach

Hi Sai,

Quoted 43 lines · Sai Prakash Ranjan

etm4_count keeps track of number of ETMv4 registered and on some systems, a race is observed on etm4_count variable which can lead to multiple calls to cpuhp_setup_state_nocalls_cpuslocked(). This function internally calls cpuhp_store_callbacks() which prevents multiple registrations of callbacks for a given state and due to this race, it returns -EBUSY leading to ETM probe failures like below.

coresight-etm4x: probe of 7040000.etm failed with error -16

This race can easily be triggered with async probe by setting probe type as PROBE_PREFER_ASYNCHRONOUS and with ETM power management property "arm,coresight-loses-context-with-cpu".

Prevent this race by moving cpuhp callbacks to etm driver init since the cpuhp callbacks doesn't have to depend on the etm4_count and can be once setup during driver init. Similarly we move cpu_pm notifier registration to driver init and completely remove etm4_count usage.

Fixes 9b6a3f3633a5 ("coresight: etmv4: Fix CPU power management setup in probe() function")
Fixes 58eb457be028 ("hwtracing/coresight-etm4x: Convert to hotplug state machine")

---

Changes in v2:
* Rearrange cpuhp callbacks and move them to driver init (Suzuki K
Poulose)

---
 drivers/hwtracing/coresight/coresight-etm4x.c | 51 
++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
index 6d7d2169bfb2..adb71987a1e3 100644
@@ -48,8 +48,6 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
        "Save/restore state on power down: 1 = never, 2 = 
 self-hosted");
 
Quoted 15 lines

drivers/hwtracing/coresight/coresight-etm4x.c static int etm4_pm_setup_cpuslocked(void) · line 1401

Quoted 7 lines
drivers/hwtracing/coresight/coresight-etm4x.c +0 -2
-/* The number of ETMv4 currently registered */
-static int etm4_count;
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);

static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,

drivers/hwtracing/coresight/coresight-etm4x.c +0 -0
@@ -1403,12 +1401,9 @@ static int etm4_pm_setup_cpuslocked(void)
 {

consider renaming this to etm4_pm_setup() and handing any cpu locking inside the function.
In the circumstances - as part of the driver init rather than probe it may be sufficient to call the cpuhp_setup functions without the _cpuslocked suffix and allow the calls to lock the cpus as they are made.
i.e. cpuhp_setup_state_nocalls_cpuslocked() => cpuhp_setup_state_nocalls()

Sure, will make this change.

Quoted 67 lines
Quoted 67 lines
drivers/hwtracing/coresight/coresight-etm4x.c +1 -4
        int ret;
 
-       if (etm4_count++)
-               return 0;
-
        ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
        if (ret)
-               goto reduce_count;
+               return ret;
 
        ret = 
 cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,

"arm/coresight4:starting",

drivers/hwtracing/coresight/coresight-etm4x.c +0 -11
@@ -1432,17 +1427,11 @@ static int etm4_pm_setup_cpuslocked(void)
 
 unregister_notifier:
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
-
-reduce_count:
-       --etm4_count;
        return ret;
 }
 
 static void etm4_pm_clear(void)
 {
-       if (--etm4_count != 0)
-               return;
-
        cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
        cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
        if (hp_online) {
@@ -1498,22 +1487,12 @@ static int etm4_probe(struct amba_device 
 *adev, const struct amba_id *id)
        if (!desc.name)
                return -ENOMEM;
 
-       cpus_read_lock();
        etmdrvdata[drvdata->cpu] = drvdata;
 
        if (smp_call_function_single(drvdata->cpu,
                                etm4_init_arch_data,  drvdata, 1))
                dev_err(dev, "ETM arch init failed\n");
 
-       ret = etm4_pm_setup_cpuslocked();
-       cpus_read_unlock();
-
-       /* etm4_pm_setup_cpuslocked() does its own cleanup - exit on 

error */

drivers/hwtracing/coresight/coresight-etm4x.c +0 -6
-       if (ret) {
-               etmdrvdata[drvdata->cpu] = NULL;
-               return ret;
-       }
-
        if (etm4_arch_supported(drvdata->arch) == false) {
                ret = -EINVAL;
                goto err_arch_supported;
@@ -1560,7 +1539,6 @@ static int etm4_probe(struct amba_device *adev, 
 const struct amba_id *id)
 
 err_arch_supported:
        etmdrvdata[drvdata->cpu] = NULL;
-       etm4_pm_clear();
        return ret;
 }
Quoted 16 lines

drivers/hwtracing/coresight/coresight-etm4x.c static struct amba_driver etm4x_driver = { · line 1586

Quoted 13 lines
drivers/hwtracing/coresight/coresight-etm4x.c +8 -1
@@ -1598,4 +1576,29 @@ static struct amba_driver etm4x_driver = {
        .probe          = etm4_probe,
        .id_table       = etm4_ids,
 };
-builtin_amba_driver(etm4x_driver);
+
+static int __init etm4x_init(void)
+{
+       int ret;
+
+       cpus_read_lock();
+       ret = etm4_pm_setup_cpuslocked();
+       cpus_read_unlock();

See my comment above about rename and use of cpus_read_lock

Yes, thanks for the review Mike.

Thanks,
Sai

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation