devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pylibfdt: Work-around SWIG limitations with flexible arrays
@ 2023-02-01 22:44 Rob Herring
       [not found] ` <20230201224441.305757-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2023-02-01 22:44 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA; +Cc: Kees Cook, Simon Glass

Commit a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with
proper flexible arrays") fails to build pylibfdt:

./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_node_header_name_set’:
./pylibfdt/libfdt_wrap.c:4350:18: error: cast specifies array type
 4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
      |                  ^
./pylibfdt/libfdt_wrap.c:4350:16: error: invalid use of flexible array member
 4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
      |                ^
./pylibfdt/libfdt_wrap.c:4352:16: error: invalid use of flexible array member
 4352 |     arg1->name = 0;
      |                ^
./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_property_data_set’:
./pylibfdt/libfdt_wrap.c:4613:18: error: cast specifies array type
 4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
      |                  ^
./pylibfdt/libfdt_wrap.c:4613:16: error: invalid use of flexible array member
 4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
      |                ^
./pylibfdt/libfdt_wrap.c:4615:16: error: invalid use of flexible array member
 4615 |     arg1->data = 0;
      |                ^

Turns out this is known issue with SWIG: https://github.com/swig/swig/issues/1699

Implement the work-around to ignore the flexible array member.

Fixes: a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with proper flexible arrays")
Cc: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 pylibfdt/libfdt.i | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index f9f7e7e66d13..987f7b9c3339 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -1036,6 +1036,9 @@ class NodeAdder():
 
 %rename(fdt_property) fdt_property_func;
 
+%immutable fdt_property::data;
+%immutable fdt_node_header::name;
+
 /*
  * fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
  * so use the same type here.
-- 
2.39.0


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

* Re: [PATCH] pylibfdt: Work-around SWIG limitations with flexible arrays
       [not found] ` <20230201224441.305757-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2023-02-01 22:49   ` Simon Glass
  2023-02-02  5:35   ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2023-02-01 22:49 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Kees Cook

On Wed, 1 Feb 2023 at 15:44, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
>
> Commit a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with
> proper flexible arrays") fails to build pylibfdt:
>
> ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_node_header_name_set’:
> ./pylibfdt/libfdt_wrap.c:4350:18: error: cast specifies array type
>  4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                  ^
> ./pylibfdt/libfdt_wrap.c:4350:16: error: invalid use of flexible array member
>  4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                ^
> ./pylibfdt/libfdt_wrap.c:4352:16: error: invalid use of flexible array member
>  4352 |     arg1->name = 0;
>       |                ^
> ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_property_data_set’:
> ./pylibfdt/libfdt_wrap.c:4613:18: error: cast specifies array type
>  4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                  ^
> ./pylibfdt/libfdt_wrap.c:4613:16: error: invalid use of flexible array member
>  4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                ^
> ./pylibfdt/libfdt_wrap.c:4615:16: error: invalid use of flexible array member
>  4615 |     arg1->data = 0;
>       |                ^
>
> Turns out this is known issue with SWIG: https://github.com/swig/swig/issues/1699
>
> Implement the work-around to ignore the flexible array member.
>
> Fixes: a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with proper flexible arrays")
> Cc: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
>  pylibfdt/libfdt.i | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index f9f7e7e66d13..987f7b9c3339 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -1036,6 +1036,9 @@ class NodeAdder():
>
>  %rename(fdt_property) fdt_property_func;
>
> +%immutable fdt_property::data;
> +%immutable fdt_node_header::name;
> +
>  /*
>   * fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
>   * so use the same type here.
> --
> 2.39.0
>

Reviewed-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Just 'make check':
Tested-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

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

* Re: [PATCH] pylibfdt: Work-around SWIG limitations with flexible arrays
       [not found] ` <20230201224441.305757-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  2023-02-01 22:49   ` Simon Glass
@ 2023-02-02  5:35   ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2023-02-02  5:35 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Kees Cook, Simon Glass

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

On Wed, Feb 01, 2023 at 04:44:41PM -0600, Rob Herring wrote:
> Commit a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with
> proper flexible arrays") fails to build pylibfdt:
> 
> ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_node_header_name_set’:
> ./pylibfdt/libfdt_wrap.c:4350:18: error: cast specifies array type
>  4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                  ^
> ./pylibfdt/libfdt_wrap.c:4350:16: error: invalid use of flexible array member
>  4350 |     arg1->name = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                ^
> ./pylibfdt/libfdt_wrap.c:4352:16: error: invalid use of flexible array member
>  4352 |     arg1->name = 0;
>       |                ^
> ./pylibfdt/libfdt_wrap.c: In function ‘_wrap_fdt_property_data_set’:
> ./pylibfdt/libfdt_wrap.c:4613:18: error: cast specifies array type
>  4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                  ^
> ./pylibfdt/libfdt_wrap.c:4613:16: error: invalid use of flexible array member
>  4613 |     arg1->data = (char [])(char *)memcpy(malloc((size)*sizeof(char)), (const char *)(arg2), sizeof(char)*(size));
>       |                ^
> ./pylibfdt/libfdt_wrap.c:4615:16: error: invalid use of flexible array member
>  4615 |     arg1->data = 0;
>       |                ^
> 
> Turns out this is known issue with SWIG: https://github.com/swig/swig/issues/1699
> 
> Implement the work-around to ignore the flexible array member.
> 
> Fixes: a41509bea3e7 ("libfdt: Replace deprecated 0-length arrays with proper flexible arrays")
> Cc: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Cc: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

Applied, thanks.  I can't test what effect this has on the pylibfdt
stuff itself, because that has been broken for months for me.

> ---
>  pylibfdt/libfdt.i | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index f9f7e7e66d13..987f7b9c3339 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -1036,6 +1036,9 @@ class NodeAdder():
>  
>  %rename(fdt_property) fdt_property_func;
>  
> +%immutable fdt_property::data;
> +%immutable fdt_node_header::name;
> +
>  /*
>   * fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
>   * so use the same type here.

-- 
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] 3+ messages in thread

end of thread, other threads:[~2023-02-02  5:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01 22:44 [PATCH] pylibfdt: Work-around SWIG limitations with flexible arrays Rob Herring
     [not found] ` <20230201224441.305757-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2023-02-01 22:49   ` Simon Glass
2023-02-02  5:35   ` 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).