devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libfdt: Fix fdt_appendprop_addrrange documentation
@ 2023-08-31 12:39 Pierre-Clément Tosi
       [not found] ` <20230831123918.rf54emwkzgtcb7aw-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre-Clément Tosi @ 2023-08-31 12:39 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Mostafa Saleh,
	Pierre-Clément Tosi

According to the documentation, the function should default to the very
common property name <reg> when none is "specified". However, neither
passing NULL (ends up calling strlen(NULL) and segfaults) nor ""
(appends a property with an empty name) implements this behavior.

Furthermore, the test case supposed to cover this default value actually
passes the value to the function, somewhat defeating its own purpose:

    /* 2. default property name */

    // ...

    err = fdt_appendprop_addrrange(fdt, 0, offset, "reg", addr, size);
    if (err)
            FAIL("Failed to set \"reg\": %s", fdt_strerror(err));
    check_getprop_addrrange(fdt, 0, offset, "reg", 1);

Finally, nothing in the implementation of the function seems to attempt
to cover that use-case.

As the feature can't ever have been used by clients and as the resulting
reduced readability of the caller seems (IMO) to outweigh any potential
benefit this API would bring, remove the erroneous documentation instead
of trying to fix the function.

Reported-by: Mostafa Saleh <smostafa-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Pierre-Clément Tosi <ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
 libfdt/libfdt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 2a4f32c..0677fea 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -2029,7 +2029,7 @@ static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
  * address and size) to the value of the named property in the given
  * node, or creates a new property with that value if it does not
  * already exist.
- * If "name" is not specified, a default "reg" is used.
+ *
  * Cell sizes are determined by parent's #address-cells and #size-cells.
  *
  * This function may insert data into the blob, and will therefore
-- 
2.42.0.rc2.253.gd59a3bf2b4-goog


-- 
Pierre

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

* Re: [PATCH] libfdt: Fix fdt_appendprop_addrrange documentation
       [not found] ` <20230831123918.rf54emwkzgtcb7aw-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
@ 2023-09-04  5:31   ` David Gibson
  0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2023-09-04  5:31 UTC (permalink / raw)
  To: Pierre-Clément Tosi
  Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Mostafa Saleh

[-- Attachment #1: Type: text/plain, Size: 2513 bytes --]

On Thu, Aug 31, 2023 at 01:39:18PM +0100, Pierre-Clément Tosi wrote:
> According to the documentation, the function should default to the very
> common property name <reg> when none is "specified". However, neither
> passing NULL (ends up calling strlen(NULL) and segfaults) nor ""
> (appends a property with an empty name) implements this behavior.
> 
> Furthermore, the test case supposed to cover this default value actually
> passes the value to the function, somewhat defeating its own purpose:
> 
>     /* 2. default property name */
> 
>     // ...
> 
>     err = fdt_appendprop_addrrange(fdt, 0, offset, "reg", addr, size);
>     if (err)
>             FAIL("Failed to set \"reg\": %s", fdt_strerror(err));
>     check_getprop_addrrange(fdt, 0, offset, "reg", 1);
> 
> Finally, nothing in the implementation of the function seems to attempt
> to cover that use-case.
> 
> As the feature can't ever have been used by clients and as the resulting
> reduced readability of the caller seems (IMO) to outweigh any potential
> benefit this API would bring, remove the erroneous documentation instead
> of trying to fix the function.
> 
> Reported-by: Mostafa Saleh <smostafa-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Pierre-Clément Tosi <ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

Nice catch, and an excellent commit message.

I don't recall this specifically, but my guess would be that an
original draft included that behaviour, but I nixed it during review,
but then both the submitted and I forgot to update the documentation
comments as well.

Merged.

> ---
>  libfdt/libfdt.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
> index 2a4f32c..0677fea 100644
> --- a/libfdt/libfdt.h
> +++ b/libfdt/libfdt.h
> @@ -2029,7 +2029,7 @@ static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
>   * address and size) to the value of the named property in the given
>   * node, or creates a new property with that value if it does not
>   * already exist.
> - * If "name" is not specified, a default "reg" is used.
> + *
>   * Cell sizes are determined by parent's #address-cells and #size-cells.
>   *
>   * This function may insert data into the blob, and will therefore

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2023-09-04  5:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31 12:39 [PATCH] libfdt: Fix fdt_appendprop_addrrange documentation Pierre-Clément Tosi
     [not found] ` <20230831123918.rf54emwkzgtcb7aw-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2023-09-04  5:31   ` David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).