diff mbox series

[1/6] fdt_support: make fdt_fixup_mtdparts() prototype more specific

Message ID 1531985307-4208-1-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 5f4e32d058755a93a9cc43ea9998195a3ef13aa2
Headers show
Series [1/6] fdt_support: make fdt_fixup_mtdparts() prototype more specific | expand

Commit Message

Masahiro Yamada July 19, 2018, 7:28 a.m. UTC
The second argument of fdt_fixup_mtdparts() is an opaque pointer,
'void *node_info', hence callers can pass any pointer.

Obviously, fdt_fixup_mtdparts() expects 'struct node_info *'
otherwise, it crashes run-time.

Change the prototype so that it is compile-time checked.

Also, add 'const' qualifier to it so that callers can constify
the struct node_info arrays.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 common/fdt_support.c  | 13 +++++++------
 include/fdt_support.h | 11 ++++++++---
 2 files changed, 15 insertions(+), 9 deletions(-)

Comments

Simon Glass July 19, 2018, 3:21 p.m. UTC | #1
Hi Masahiro,

On 19 July 2018 at 01:28, Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> The second argument of fdt_fixup_mtdparts() is an opaque pointer,
> 'void *node_info', hence callers can pass any pointer.
>
> Obviously, fdt_fixup_mtdparts() expects 'struct node_info *'
> otherwise, it crashes run-time.
>
> Change the prototype so that it is compile-time checked.
>
> Also, add 'const' qualifier to it so that callers can constify
> the struct node_info arrays.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
>  common/fdt_support.c  | 13 +++++++------
>  include/fdt_support.h | 11 ++++++++---
>  2 files changed, 15 insertions(+), 9 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Masahiro Yamada July 24, 2018, 11:43 p.m. UTC | #2
2018-07-19 16:28 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> The second argument of fdt_fixup_mtdparts() is an opaque pointer,
> 'void *node_info', hence callers can pass any pointer.
>
> Obviously, fdt_fixup_mtdparts() expects 'struct node_info *'
> otherwise, it crashes run-time.
>
> Change the prototype so that it is compile-time checked.
>
> Also, add 'const' qualifier to it so that callers can constify
> the struct node_info arrays.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---


Series, applied to u-boot-uniphier.


>  common/fdt_support.c  | 13 +++++++------
>  include/fdt_support.h | 11 ++++++++---
>  2 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index 812eca8..3b31f3d 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -893,9 +893,9 @@ err_prop:
>   *
>   *     fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
>   */
> -void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
> +void fdt_fixup_mtdparts(void *blob, const struct node_info *node_info,
> +                       int node_info_size)
>  {
> -       struct node_info *ni = node_info;
>         struct mtd_device *dev;
>         int i, idx;
>         int noff;
> @@ -905,12 +905,13 @@ void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
>
>         for (i = 0; i < node_info_size; i++) {
>                 idx = 0;
> -               noff = fdt_node_offset_by_compatible(blob, -1, ni[i].compat);
> +               noff = fdt_node_offset_by_compatible(blob, -1,
> +                                                    node_info[i].compat);
>                 while (noff != -FDT_ERR_NOTFOUND) {
>                         debug("%s: %s, mtd dev type %d\n",
>                                 fdt_get_name(blob, noff, 0),
> -                               ni[i].compat, ni[i].type);
> -                       dev = device_find(ni[i].type, idx++);
> +                               node_info[i].compat, node_info[i].type);
> +                       dev = device_find(node_info[i].type, idx++);
>                         if (dev) {
>                                 if (fdt_node_set_part_info(blob, noff, dev))
>                                         return; /* return on error */
> @@ -918,7 +919,7 @@ void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
>
>                         /* Jump to next flash node */
>                         noff = fdt_node_offset_by_compatible(blob, noff,
> -                                                            ni[i].compat);
> +                                                            node_info[i].compat);
>                 }
>         }
>  }
> diff --git a/include/fdt_support.h b/include/fdt_support.h
> index a9a0078..27fe564 100644
> --- a/include/fdt_support.h
> +++ b/include/fdt_support.h
> @@ -205,11 +205,16 @@ int fdt_increase_size(void *fdt, int add_len);
>
>  int fdt_fixup_nor_flash_size(void *blob);
>
> +struct node_info;
>  #if defined(CONFIG_FDT_FIXUP_PARTITIONS)
> -void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size);
> +void fdt_fixup_mtdparts(void *fdt, const struct node_info *node_info,
> +                       int node_info_size);
>  #else
> -static inline void fdt_fixup_mtdparts(void *fdt, void *node_info,
> -                                       int node_info_size) {}
> +static inline void fdt_fixup_mtdparts(void *fdt,
> +                                     const struct node_info *node_info,
> +                                     int node_info_size)
> +{
> +}
>  #endif
>
>  void fdt_del_node_and_alias(void *blob, const char *alias);
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
diff mbox series

Patch

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 812eca8..3b31f3d 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -893,9 +893,9 @@  err_prop:
  *
  *	fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  */
-void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
+void fdt_fixup_mtdparts(void *blob, const struct node_info *node_info,
+			int node_info_size)
 {
-	struct node_info *ni = node_info;
 	struct mtd_device *dev;
 	int i, idx;
 	int noff;
@@ -905,12 +905,13 @@  void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
 
 	for (i = 0; i < node_info_size; i++) {
 		idx = 0;
-		noff = fdt_node_offset_by_compatible(blob, -1, ni[i].compat);
+		noff = fdt_node_offset_by_compatible(blob, -1,
+						     node_info[i].compat);
 		while (noff != -FDT_ERR_NOTFOUND) {
 			debug("%s: %s, mtd dev type %d\n",
 				fdt_get_name(blob, noff, 0),
-				ni[i].compat, ni[i].type);
-			dev = device_find(ni[i].type, idx++);
+				node_info[i].compat, node_info[i].type);
+			dev = device_find(node_info[i].type, idx++);
 			if (dev) {
 				if (fdt_node_set_part_info(blob, noff, dev))
 					return; /* return on error */
@@ -918,7 +919,7 @@  void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size)
 
 			/* Jump to next flash node */
 			noff = fdt_node_offset_by_compatible(blob, noff,
-							     ni[i].compat);
+							     node_info[i].compat);
 		}
 	}
 }
diff --git a/include/fdt_support.h b/include/fdt_support.h
index a9a0078..27fe564 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -205,11 +205,16 @@  int fdt_increase_size(void *fdt, int add_len);
 
 int fdt_fixup_nor_flash_size(void *blob);
 
+struct node_info;
 #if defined(CONFIG_FDT_FIXUP_PARTITIONS)
-void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size);
+void fdt_fixup_mtdparts(void *fdt, const struct node_info *node_info,
+			int node_info_size);
 #else
-static inline void fdt_fixup_mtdparts(void *fdt, void *node_info,
-					int node_info_size) {}
+static inline void fdt_fixup_mtdparts(void *fdt,
+				      const struct node_info *node_info,
+				      int node_info_size)
+{
+}
 #endif
 
 void fdt_del_node_and_alias(void *blob, const char *alias);