mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] resource: return NULL for error in request_barebox_region
@ 2024-07-22 17:06 Ahmad Fatoum
  2024-07-22 17:06 ` [PATCH master 2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-22 17:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The function currently returns NULL for error if the range is in SDRAM
and couldn't be requested or an error pointer if the range is outside.

Reduce the confusion by using only one way to indicate error. As
request_barebox_region is used to replace request_sdram_region calls and
that returns NULL on error, follow suit.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/memory.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index eb7838d03613..c155cb317f25 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -84,9 +84,12 @@ struct resource *request_barebox_region(const char *name,
 	resource_size_t end = start + size - 1;
 
 	if (barebox_res && barebox_res->start <= start &&
-	    end <= barebox_res->end)
-		return __request_region(barebox_res, start, end,
-					name, IORESOURCE_MEM);
+	    end <= barebox_res->end) {
+		struct resource *iores;
+		iores = __request_region(barebox_res, start, end,
+					 name, IORESOURCE_MEM);
+		return !IS_ERR(iores) ? iores : NULL;
+	}
 
 	return request_sdram_region(name, start, size);
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH master 2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error
  2024-07-22 17:06 [PATCH master 1/3] resource: return NULL for error in request_barebox_region Ahmad Fatoum
@ 2024-07-22 17:06 ` Ahmad Fatoum
  2024-07-22 17:06 ` [PATCH master 3/3] RISC-V: cpu: " Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-22 17:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

request_barebox_region returns NULL on error, so adjust the initcall
accordingly.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-imx/scratch.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/scratch.c b/arch/arm/mach-imx/scratch.c
index 002b499fab3a..b7280ff60952 100644
--- a/arch/arm/mach-imx/scratch.c
+++ b/arch/arm/mach-imx/scratch.c
@@ -95,8 +95,8 @@ const struct optee_header *imx_scratch_get_optee_hdr(void)
 
 static int imx8m_reserve_scratch_area(void)
 {
-	return PTR_ERR_OR_ZERO(request_barebox_region("scratch area",
-				    (ulong)arm_mem_scratch_get(),
-				    sizeof(struct imx_scratch_space)));
+	return request_barebox_region("scratch area",
+				      (ulong)arm_mem_scratch_get(),
+				      sizeof(struct imx_scratch_space)) ? 0 : -EINVAL;
 }
 device_initcall(imx8m_reserve_scratch_area);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH master 3/3] RISC-V: cpu: fix initcall return code on request_barebox_region error
  2024-07-22 17:06 [PATCH master 1/3] resource: return NULL for error in request_barebox_region Ahmad Fatoum
  2024-07-22 17:06 ` [PATCH master 2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error Ahmad Fatoum
@ 2024-07-22 17:06 ` Ahmad Fatoum
  2024-07-22 17:49 ` [PATCH master 1/3] resource: return NULL for error in request_barebox_region Marco Felsch
  2024-07-24  8:08 ` Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-22 17:06 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

request_barebox_region returns NULL on error, so adjust the initcall
accordingly.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/riscv/cpu/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/cpu/core.c b/arch/riscv/cpu/core.c
index ad9030ede78b..4889f774cbb3 100644
--- a/arch/riscv/cpu/core.c
+++ b/arch/riscv/cpu/core.c
@@ -28,7 +28,9 @@
 static int riscv_request_stack(void)
 {
 	extern unsigned long riscv_stack_top;
-	return PTR_ERR_OR_ZERO(request_barebox_region("stack", riscv_stack_top - STACK_SIZE, STACK_SIZE));
+	return request_barebox_region("stack",
+				      riscv_stack_top - STACK_SIZE,
+				      STACK_SIZE) ? 0 : -EINVAL;
 }
 coredevice_initcall(riscv_request_stack);
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH master 1/3] resource: return NULL for error in request_barebox_region
  2024-07-22 17:06 [PATCH master 1/3] resource: return NULL for error in request_barebox_region Ahmad Fatoum
  2024-07-22 17:06 ` [PATCH master 2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error Ahmad Fatoum
  2024-07-22 17:06 ` [PATCH master 3/3] RISC-V: cpu: " Ahmad Fatoum
@ 2024-07-22 17:49 ` Marco Felsch
  2024-07-23  6:07   ` Ahmad Fatoum
  2024-07-24  8:08 ` Sascha Hauer
  3 siblings, 1 reply; 6+ messages in thread
From: Marco Felsch @ 2024-07-22 17:49 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hi Ahmad,

On 24-07-22, Ahmad Fatoum wrote:
> The function currently returns NULL for error if the range is in SDRAM
> and couldn't be requested or an error pointer if the range is outside.
> 
> Reduce the confusion by using only one way to indicate error. As
> request_barebox_region is used to replace request_sdram_region calls and
> that returns NULL on error, follow suit.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/memory.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/common/memory.c b/common/memory.c
> index eb7838d03613..c155cb317f25 100644
> --- a/common/memory.c
> +++ b/common/memory.c
> @@ -84,9 +84,12 @@ struct resource *request_barebox_region(const char *name,
>  	resource_size_t end = start + size - 1;
>  
>  	if (barebox_res && barebox_res->start <= start &&
> -	    end <= barebox_res->end)
> -		return __request_region(barebox_res, start, end,
> -					name, IORESOURCE_MEM);
> +	    end <= barebox_res->end) {
> +		struct resource *iores;
> +		iores = __request_region(barebox_res, start, end,
> +					 name, IORESOURCE_MEM);
> +		return !IS_ERR(iores) ? iores : NULL;

Of course a nit but IMHO

   		return IS_ERR(iores) ? NULL : iores;

is easier to read.

Regards,
  Marco

> +	}
>  
>  	return request_sdram_region(name, start, size);
>  }
> -- 
> 2.39.2
> 
> 
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH master 1/3] resource: return NULL for error in request_barebox_region
  2024-07-22 17:49 ` [PATCH master 1/3] resource: return NULL for error in request_barebox_region Marco Felsch
@ 2024-07-23  6:07   ` Ahmad Fatoum
  0 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2024-07-23  6:07 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On 22.07.24 19:49, Marco Felsch wrote:
> Hi Ahmad,
> 
> On 24-07-22, Ahmad Fatoum wrote:
>> The function currently returns NULL for error if the range is in SDRAM
>> and couldn't be requested or an error pointer if the range is outside.
>>
>> Reduce the confusion by using only one way to indicate error. As
>> request_barebox_region is used to replace request_sdram_region calls and
>> that returns NULL on error, follow suit.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  common/memory.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/common/memory.c b/common/memory.c
>> index eb7838d03613..c155cb317f25 100644
>> --- a/common/memory.c
>> +++ b/common/memory.c
>> @@ -84,9 +84,12 @@ struct resource *request_barebox_region(const char *name,
>>  	resource_size_t end = start + size - 1;
>>  
>>  	if (barebox_res && barebox_res->start <= start &&
>> -	    end <= barebox_res->end)
>> -		return __request_region(barebox_res, start, end,
>> -					name, IORESOURCE_MEM);
>> +	    end <= barebox_res->end) {
>> +		struct resource *iores;
>> +		iores = __request_region(barebox_res, start, end,
>> +					 name, IORESOURCE_MEM);
>> +		return !IS_ERR(iores) ? iores : NULL;
> 
> Of course a nit but IMHO
> 
>    		return IS_ERR(iores) ? NULL : iores;
> 
> is easier to read.

I wanted the successful case to be first.

> 
> Regards,
>   Marco
> 
>> +	}
>>  
>>  	return request_sdram_region(name, start, size);
>>  }
>> -- 
>> 2.39.2
>>
>>
>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH master 1/3] resource: return NULL for error in request_barebox_region
  2024-07-22 17:06 [PATCH master 1/3] resource: return NULL for error in request_barebox_region Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2024-07-22 17:49 ` [PATCH master 1/3] resource: return NULL for error in request_barebox_region Marco Felsch
@ 2024-07-24  8:08 ` Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2024-07-24  8:08 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 22 Jul 2024 19:06:04 +0200, Ahmad Fatoum wrote:
> The function currently returns NULL for error if the range is in SDRAM
> and couldn't be requested or an error pointer if the range is outside.
> 
> Reduce the confusion by using only one way to indicate error. As
> request_barebox_region is used to replace request_sdram_region calls and
> that returns NULL on error, follow suit.
> 
> [...]

Applied, thanks!

[1/3] resource: return NULL for error in request_barebox_region
      https://git.pengutronix.de/cgit/barebox/commit/?id=43b22bac73b7 (link may not be stable)
[2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error
      https://git.pengutronix.de/cgit/barebox/commit/?id=302d824e27f3 (link may not be stable)
[3/3] RISC-V: cpu: fix initcall return code on request_barebox_region error
      https://git.pengutronix.de/cgit/barebox/commit/?id=9f09e687430f (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-24  8:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-22 17:06 [PATCH master 1/3] resource: return NULL for error in request_barebox_region Ahmad Fatoum
2024-07-22 17:06 ` [PATCH master 2/3] ARM: i.MX8M: scratch: fix initcall return code on request_barebox_region error Ahmad Fatoum
2024-07-22 17:06 ` [PATCH master 3/3] RISC-V: cpu: " Ahmad Fatoum
2024-07-22 17:49 ` [PATCH master 1/3] resource: return NULL for error in request_barebox_region Marco Felsch
2024-07-23  6:07   ` Ahmad Fatoum
2024-07-24  8:08 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox