Skip to contentSkip to conversation

core: of_addr: Correct the size type of of_get_address to fdt_size_t

PATCH New Keerthy 3 participants 5 messages Aug 14, 2019 – Sep 17, 2019

lore
Share & tools
lore

Keerthy

author
#0 lore raw

PATCH 1/1 core: of_addr: Correct the size type of of_get_address to fdt_size_t

Currently the size parameter is defined as u64 type. Correct the size type of of_get_address to fdt_size_t so that both 64 bit and 32 bit architectures are taken care of.

The initial bug report:
https://patchwork.ozlabs.org/patch/1090094/#2212555

Fixes e679d03b08fb ("core: ofnode: Add ofnode_get_addr_size_index")

---

Changes from RFT:

* Fixed a typo in the commit log.
* Added Reported-by: Eugeniu Rosca <[email protected]>

 drivers/core/of_addr.c | 4 ++--
 drivers/core/ofnode.c  | 2 +-
 include/dm/of_addr.h   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/core/of_addr.c +2 -2
index 4e256d9926..812a400b19 100644
@@ -122,7 +122,7 @@ static void dev_count_cells(const struct device_node *np, int *nap, int *nsp)
 }
 
 const __be32 *of_get_address(const struct device_node *dev, int index,
-			     u64 *size, unsigned int *flags)
+			     fdt_size_t *size, unsigned int *flags)
 {
 	const __be32 *prop;
 	int psize;
@@ -347,7 +347,7 @@ int of_address_to_resource(const struct device_node *dev, int index,
 			   struct resource *r)
 {
 	const __be32	*addrp;
-	u64		size;
+	fdt_size_t	size;
 	unsigned int	flags;
 	const char	*name = NULL;
 
drivers/core/ofnode.c +1 -1
index 2ac73af934..b21b5183a3 100644
@@ -260,7 +260,7 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
 		uint flags;
 
 		prop_val = of_get_address(ofnode_to_np(node), index,
-					  (u64 *)size, &flags);
+					  size, &flags);
 		if (!prop_val)
 			return FDT_ADDR_T_NONE;
 
include/dm/of_addr.h +1 -1
index 3fa1ffce81..52443ef296 100644
@@ -58,7 +58,7 @@ u64 of_translate_dma_address(const struct device_node *no, const __be32 *in_addr
  * @return pointer to address which can be read
  */
 const __be32 *of_get_address(const struct device_node *no, int index,
-			     u64 *size, unsigned int *flags);
+			     fdt_size_t *size, unsigned int *flags);
 
 struct resource;
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 core: of_addr: Correct the size type of of_get_address to fdt_size_t

Hi Keerthy,

Quoted 30 lines · Keerthy

Currently the size parameter is defined as u64 type. Correct the size type of of_get_address to fdt_size_t so that both 64 bit and 32 bit architectures are taken care of.

The initial bug report:
https://patchwork.ozlabs.org/patch/1090094/#2212555

Fixes e679d03b08fb ("core: ofnode: Add ofnode_get_addr_size_index")

---

Changes from RFT:

* Fixed a typo in the commit log.
* Added Reported-by: Eugeniu Rosca <[email protected]>

 drivers/core/of_addr.c | 4 ++--
 drivers/core/ofnode.c  | 2 +-
 include/dm/of_addr.h   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/core/of_addr.c +0 -0
index 4e256d9926..812a400b19 100644

drivers/core/of_addr.c static void dev_count_cells(const struct device_node *np, int *nap, int *nsp) · line 125

Quoted 5 lines
drivers/core/of_addr.c +1 -1
@@ -122,7 +122,7 @@ static void dev_count_cells(const struct device_node *np, int *nap, int *nsp)
 }
 
 const __be32 *of_get_address(const struct device_node *dev, int index,
-			     u64 *size, unsigned int *flags)
+			     fdt_size_t *size, unsigned int *flags)

I took some time to also review the changes in addition to testing.

I can see that, since its inception in Linux [1], of_get_address() used 'u64*' type for its 'size' argument. That's still valid in v5.3-rc5. So, it looks to me that with this patch we diverge from Linux.

I would barely think that the ASAN issue being fixed in this patch exists in Linux, since the latter receives much more KASAN-enabled testing on regular basis.

Do you foresee any alternative fix w/o diverging from Linux?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=22ae782f86b7

Signature · 2 lines
Best Regards,
Eugeniu.
author
#2 lore raw

PATCH 1/1 core: of_addr: Correct the size type of of_get_address to fdt_size_t

Quoted 45 lines · Eugeniu Rosca

Hi Keerthy,

Quoted 30 lines · Keerthy

Currently the size parameter is defined as u64 type. Correct the size type of of_get_address to fdt_size_t so that both 64 bit and 32 bit architectures are taken care of.

The initial bug report:
https://patchwork.ozlabs.org/patch/1090094/#2212555

Fixes e679d03b08fb ("core: ofnode: Add ofnode_get_addr_size_index")

---

Changes from RFT:

* Fixed a typo in the commit log.
* Added Reported-by: Eugeniu Rosca <[email protected]>

  drivers/core/of_addr.c | 4 ++--
  drivers/core/ofnode.c  | 2 +-
  include/dm/of_addr.h   | 2 +-
  3 files changed, 4 insertions(+), 4 deletions(-)
drivers/core/of_addr.c +0 -0
index 4e256d9926..812a400b19 100644

drivers/core/of_addr.c static void dev_count_cells(const struct device_node *np, int *nap, int *nsp) · line 125

Quoted 5 lines
drivers/core/of_addr.c +1 -1
@@ -122,7 +122,7 @@ static void dev_count_cells(const struct device_node *np, int *nap, int *nsp)
  }
 
  const __be32 *of_get_address(const struct device_node *dev, int index,
-			     u64 *size, unsigned int *flags)
+			     fdt_size_t *size, unsigned int *flags)

I took some time to also review the changes in addition to testing.

I can see that, since its inception in Linux [1], of_get_address() used 'u64*' type for its 'size' argument. That's still valid in v5.3-rc5. So, it looks to me that with this patch we diverge from Linux.

Quoted 5 lines

I would barely think that the ASAN issue being fixed in this patch exists in Linux, since the latter receives much more KASAN-enabled testing on regular basis.

Do you foresee any alternative fix w/o diverging from Linux?

I am afraid No but isn't fdt_size_t also right type to represent size?

Quoted 3 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=22ae782f86b7

#3 lore raw

PATCH 1/1 core: of_addr: Correct the size type of of_get_address to fdt_size_t

Hi Keerthy,
Hi Simon,
cc: Tom

Quoted 1 line · Keerthy

On 19/08/19 3:54 PM, Eugeniu Rosca wrote:

[..]

Quoted 6 lines
Quoted 6 lines

I took some time to also review the changes in addition to testing.

I can see that, since its inception in Linux [1], of_get_address() used 'u64*' type for its 'size' argument. That's still valid in v5.3-rc5. So, it looks to me that with this patch we diverge from Linux.

Quoted 7 lines
Quoted 5 lines

I would barely think that the ASAN issue being fixed in this patch exists in Linux, since the latter receives much more KASAN-enabled testing on regular basis.

Do you foresee any alternative fix w/o diverging from Linux?

I am afraid No but isn't fdt_size_t also right type to represent size?

'fdt_size_t' is a U-Boot-ism, i.e. it exists nowhere else but in U-Boot. Just for the record, it appears to be added by Simon's v2013.04 commit 4397a2a80baef ("fdt: Add fdtdec_get_addr_size() to read reg properties")

IMHO injecting a U-Boot-specific data type into the prototype of a Linux-backported function has below major drawbacks:

- It is a non-upstream-able solution. Linux will unlikely accept 'fdt_size_t' as a new type simply b/c Linux OF code existed over a decade and it didn't need this type so far.
- Mutilating Linux upstream code will make further U-Boot backports painful, time consuming and error-prone.

Are we on the same page here?

Quoted 2 lines
Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=22ae782f86b7

Signature · 2 lines
Best Regards,
Eugeniu.
#4 lore raw

PATCH 1/1 core: of_addr: Correct the size type of of_get_address to fdt_size_t

Hi,

Quoted 29 lines · Eugeniu Rosca

Hi Keerthy,
Hi Simon,
cc: Tom

Quoted 1 line · Keerthy

On 19/08/19 3:54 PM, Eugeniu Rosca wrote:

[..]

Quoted 6 lines
Quoted 6 lines

I took some time to also review the changes in addition to testing.

I can see that, since its inception in Linux [1], of_get_address() used 'u64*' type for its 'size' argument. That's still valid in v5.3-rc5. So, it looks to me that with this patch we diverge from Linux.

Quoted 7 lines
Quoted 5 lines

I would barely think that the ASAN issue being fixed in this patch exists in Linux, since the latter receives much more KASAN-enabled testing on regular basis.

Do you foresee any alternative fix w/o diverging from Linux?

I am afraid No but isn't fdt_size_t also right type to represent size?

'fdt_size_t' is a U-Boot-ism, i.e. it exists nowhere else but in U-Boot. Just for the record, it appears to be added by Simon's v2013.04 commit 4397a2a80baef ("fdt: Add fdtdec_get_addr_size() to read reg properties")

IMHO injecting a U-Boot-specific data type into the prototype of a Linux-backported function has below major drawbacks:

Quoted 11 lines

- It is a non-upstream-able solution. Linux will unlikely accept 'fdt_size_t' as a new type simply b/c Linux OF code existed over a decade and it didn't need this type so far.
- Mutilating Linux upstream code will make further U-Boot backports painful, time consuming and error-prone.

Are we on the same page here?

Quoted 2 lines
Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=22ae782f86b7

Yes I agree.

What do people think about this approach?

https://gitlab.denx.de/u-boot/custodians/u-boot-dm/commit/82c65a88284c27a02d0958d8a5354390893b172a

Regards,
SImon