[PATCH 2/5] arch_topology: update CPU map to use the new API

Alireza Sanaee posted 5 patches 3 months ago
There is a newer version of this series
[PATCH 2/5] arch_topology: update CPU map to use the new API
Posted by Alireza Sanaee 3 months ago
Cleans up the cpu-map generation using the created API.

Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
---
 drivers/base/arch_topology.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 3ebe77566788..88970f13f684 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
  */
 static int __init get_cpu_for_node(struct device_node *node)
 {
+	struct device_node *cpu_node __free(device_node) = NULL;
 	int cpu;
-	struct device_node *cpu_node __free(device_node) =
-		of_parse_phandle(node, "cpu", 0);
 
-	if (!cpu_node)
-		return -1;
+	cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
 
-	cpu = of_cpu_node_to_id(cpu_node);
 	if (cpu >= 0)
 		topology_parse_cpu_capacity(cpu_node, cpu);
-	else
+	else if (cpu == -ENODEV)
 		pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
 			cpu_node, cpumask_pr_args(cpu_possible_mask));
+	else
+		return -1;
 
 	return cpu;
 }
 
+
 static int __init parse_core(struct device_node *core, int package_id,
 			     int cluster_id, int core_id)
 {
-- 
2.43.0
Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
Posted by Jonathan Cameron 3 months ago
On Mon, 7 Jul 2025 16:04:11 +0100
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:

> Cleans up the cpu-map generation using the created API.
> 
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>  drivers/base/arch_topology.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 3ebe77566788..88970f13f684 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
>   */
>  static int __init get_cpu_for_node(struct device_node *node)
>  {
> +	struct device_node *cpu_node __free(device_node) = NULL;
>  	int cpu;
> -	struct device_node *cpu_node __free(device_node) =
> -		of_parse_phandle(node, "cpu", 0);
>  
> -	if (!cpu_node)
> -		return -1;
> +	cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
>  
> -	cpu = of_cpu_node_to_id(cpu_node);

Better I think to flip logic to exit early on errors.

So taking previous review into account - something like.

	struct device_node *cpu_node = NULL;
	int cpu;

	cpu = of_cpu_phandle_to_id(node, &cpu_node, 0);
	if (cpu == -ENODEV) {
 		pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
			cpu_node, cpumask_pr_args(cpu_possible_mask));
		return -ENODEV;
	} else if (cpu < 0) {
		return cpu;
	}

	topology_parse_cpu_capacity(cpu_node, cpu);
	of_node_put(cpu_node);

	return cpu;


>  	if (cpu >= 0)
>  		topology_parse_cpu_capacity(cpu_node, cpu);
> -	else
> +	else if (cpu == -ENODEV)
>  		pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
>  			cpu_node, cpumask_pr_args(cpu_possible_mask));
> +	else
> +		return -1;
>  
>  	return cpu;
>  }
>  
> +

Check all patches before posting for noise like this. It sneaks in as
rebases / refactors happen so you always need to eyeball for it at the end
of development.

>  static int __init parse_core(struct device_node *core, int package_id,
>  			     int cluster_id, int core_id)
>  {
Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
Posted by Krzysztof Kozlowski 3 months ago
On 07/07/2025 17:04, Alireza Sanaee wrote:
> Cleans up the cpu-map generation using the created API.
> 
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
>  drivers/base/arch_topology.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> index 3ebe77566788..88970f13f684 100644
> --- a/drivers/base/arch_topology.c
> +++ b/drivers/base/arch_topology.c
> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
>   */
>  static int __init get_cpu_for_node(struct device_node *node)
>  {
> +	struct device_node *cpu_node __free(device_node) = NULL;


That's not a correct style anymore. What's more it is not really
explained anywhere. Follow standard cleanup.h rules (constructor).


Best regards,
Krzysztof
Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
Posted by Jonathan Cameron 3 months ago
On Tue, 8 Jul 2025 08:29:43 +0200
Krzysztof Kozlowski <krzk@kernel.org> wrote:

> On 07/07/2025 17:04, Alireza Sanaee wrote:
> > Cleans up the cpu-map generation using the created API.
> > 
> > Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> > ---
> >  drivers/base/arch_topology.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
> > index 3ebe77566788..88970f13f684 100644
> > --- a/drivers/base/arch_topology.c
> > +++ b/drivers/base/arch_topology.c
> > @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
> >   */
> >  static int __init get_cpu_for_node(struct device_node *node)
> >  {
> > +	struct device_node *cpu_node __free(device_node) = NULL;  
> 
> 
> That's not a correct style anymore. What's more it is not really
> explained anywhere. Follow standard cleanup.h rules (constructor).

There isn't a good solution in this case as the constructor is via
a pointer passed as an argument. I'd just fall back to not using
__free here and instead doing a manual put of the node in the
paths where it is set.   That might just be the final successful
return path - I've not checked closely.

> 
> 
> Best regards,
> Krzysztof
Re: [PATCH 2/5] arch_topology: update CPU map to use the new API
Posted by Krzysztof Kozlowski 3 months ago
On 08/07/2025 10:22, Jonathan Cameron wrote:
> On Tue, 8 Jul 2025 08:29:43 +0200
> Krzysztof Kozlowski <krzk@kernel.org> wrote:
> 
>> On 07/07/2025 17:04, Alireza Sanaee wrote:
>>> Cleans up the cpu-map generation using the created API.
>>>
>>> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
>>> ---
>>>  drivers/base/arch_topology.c | 12 ++++++------
>>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
>>> index 3ebe77566788..88970f13f684 100644
>>> --- a/drivers/base/arch_topology.c
>>> +++ b/drivers/base/arch_topology.c
>>> @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity);
>>>   */
>>>  static int __init get_cpu_for_node(struct device_node *node)
>>>  {
>>> +	struct device_node *cpu_node __free(device_node) = NULL;  
>>
>>
>> That's not a correct style anymore. What's more it is not really
>> explained anywhere. Follow standard cleanup.h rules (constructor).
> 
> There isn't a good solution in this case as the constructor is via
> a pointer passed as an argument. I'd just fall back to not using


That's even more confusing! There is a destructor here but no
constructor. This is clearly the pattern we people wanted to avoid with
cleanup.h.

> __free here and instead doing a manual put of the node in the
> paths where it is set.   That might just be the final successful

Yes.

> return path - I've not checked closely.

Just noticed now:

Patch btw has some more unrelated white space changes... :/

Best regards,
Krzysztof