Skip to contentSkip to conversation

cache: sifive: Fix -Wint-to-pointer-cast warning

PATCH In review Bin Meng 4 participants 22 messages Sep 12, 2021 – Oct 12, 2021

Subsystems (6)
Network drivers GPIO Common clk I2C +2 more subsystems
lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/9 cache: sifive: Fix -Wint-to-pointer-cast warning

The following warning is seen in cache-sifive-ccache.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fix by casting it with uintptr_t.

---

 drivers/cache/cache-sifive-ccache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cache/cache-sifive-ccache.c +1 -1
index 76c0ab26ae..c8766f6242 100644
@@ -38,7 +38,7 @@ static int sifive_ccache_get_info(struct udevice *dev, struct cache_info *info)
 {
 	struct sifive_ccache *priv = dev_get_priv(dev);
 
-	info->base = (phys_addr_t)priv->base;
+	info->base = (uintptr_t)priv->base;
 
 	return 0;
 }
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/9 clk: sifive: Fix -Wint-to-pointer-cast warning

dev_read_addr() returns a value of type fdt_addr_t which is a 64-bit address and pd->va is a pointer. In a 32-bit build, this causes the following warning seen when building sifive-prci.c:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_ptr().

---

 drivers/clk/sifive/sifive-prci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/sifive/sifive-prci.c +3 -3
index cd1acb9442..52ae268e0c 100644
@@ -653,9 +653,9 @@ static int sifive_prci_probe(struct udevice *dev)
 	struct prci_clk_desc *data =
 		(struct prci_clk_desc *)dev_get_driver_data(dev);
 
-	pd->va = (void *)dev_read_addr(dev);
-	if (IS_ERR(pd->va))
-		return PTR_ERR(pd->va);
+	pd->va = dev_read_addr_ptr(dev);
+	if (!pd->va)
+		return -EINVAL;
 
 	err = clk_get_by_index(dev, 0, &pd->parent_hfclk);
 	if (err)
Signature · 1 line
2.25.1
Reviewed-by on v1 2/9
#2 lore raw

Re: [PATCH 2/9] clk: sifive: Fix -Wint-to-pointer-cast warning

Quoted 6 lines · Bin Meng

dev_read_addr() returns a value of type fdt_addr_t which is a 64-bit address and pd->va is a pointer. In a 32-bit build, this causes the following warning seen when building sifive-prci.c:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 7 lines

Change to use dev_read_addr_ptr().

---

 drivers/clk/sifive/sifive-prci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
author
#3 lore raw

PATCH 3/9 gpio: sifive: Fix -Wint-to-pointer-cast warning

In reply to Bin Meng

dev_read_addr() returns a value of type fdt_addr_t which is a 64-bit address and plat->base is a pointer. In a 32-bit build, this causes the following warning seen when building sifive-gpio.c:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_ptr().

---

 drivers/gpio/sifive-gpio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpio/sifive-gpio.c +2 -4
index abd1f629b9..151f484e8f 100644
@@ -157,13 +157,11 @@ static const struct dm_gpio_ops sifive_gpio_ops = {
 static int sifive_gpio_of_to_plat(struct udevice *dev)
 {
 	struct sifive_gpio_plat *plat = dev_get_plat(dev);
-	fdt_addr_t addr;
 
-	addr = dev_read_addr(dev);
-	if (addr == FDT_ADDR_T_NONE)
+	plat->base = dev_read_addr_ptr(dev);
+	if (!plat->base)
 		return -EINVAL;
 
-	plat->base = (void *)addr;
 	return 0;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 3/9
#4 lore raw

Re: [PATCH 3/9] gpio: sifive: Fix -Wint-to-pointer-cast warning

Quoted 6 lines · Bin Meng

dev_read_addr() returns a value of type fdt_addr_t which is a 64-bit address and plat->base is a pointer. In a 32-bit build, this causes the following warning seen when building sifive-gpio.c:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 7 lines

Change to use dev_read_addr_ptr().

---

 drivers/gpio/sifive-gpio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
author
#5 lore raw

PATCH 4/9 i2c: ocores: Fix -Wint-to-pointer-cast warning

In reply to Bin Meng

The following warning is seen in ocores_i2c.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_ptr().

---

 drivers/i2c/ocores_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/ocores_i2c.c +1 -1
index f129ec3818..3b19ba78fa 100644
@@ -516,7 +516,7 @@ static int ocores_i2c_probe(struct udevice *dev)
 	u32 clock_frequency_khz;
 	int ret;
 
-	bus->base = (void __iomem *)devfdt_get_addr(dev);
+	bus->base = dev_read_addr_ptr(dev);
 
 	if (dev_read_u32(dev, "reg-shift", &bus->reg_shift)) {
 		/* no 'reg-shift', check for deprecated 'regstep' */
Signature · 1 line
2.25.1
Reviewed-by on v1 4/9
#6 lore raw

Re: [PATCH 4/9] i2c: ocores: Fix -Wint-to-pointer-cast warning

Quoted 11 lines · Bin Meng

The following warning is seen in ocores_i2c.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_ptr().

---

 drivers/i2c/ocores_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author
#7 lore raw

PATCH 5/9 dm: core: Add a new API devfdt_get_addr_index_ptr()

In reply to Bin Meng

At present there is only devfdt_get_addr_ptr() which only returns the first <addr, size> pair in the 'reg' property. Add a new API devfdt_get_addr_index_ptr() to return the indexed pointer.

---

 drivers/core/fdtaddr.c | 11 ++++++++---
 include/dm/fdtaddr.h   | 12 ++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)
drivers/core/fdtaddr.c +8 -3
index 4ffbd6b2eb..8dbb06ab03 100644
@@ -93,6 +93,13 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 #endif
 }
 
+void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index)
+{
+	fdt_addr_t addr = devfdt_get_addr_index(dev, index);
+
+	return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+}
+
 fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
 				      fdt_size_t *size)
 {
@@ -155,9 +162,7 @@ fdt_addr_t devfdt_get_addr(const struct udevice *dev)
 
 void *devfdt_get_addr_ptr(const struct udevice *dev)
 {
-	fdt_addr_t addr = devfdt_get_addr_index(dev, 0);
-
-	return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+	return devfdt_get_addr_index_ptr(dev, 0);
 }
 
 void *devfdt_remap_addr_index(const struct udevice *dev, int index)
include/dm/fdtaddr.h +12 -0
index a4fda581a7..d2c1994291 100644
@@ -92,6 +92,18 @@ void *devfdt_map_physmem(const struct udevice *dev, unsigned long size);
  */
 fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index);
 
+/**
+ * devfdt_get_addr_index_ptr() - Return indexed pointer to the address of the
+ *                               reg property of a device
+ *
+ * @dev: Pointer to a device
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *	   and @index is used to select which one is required
+ *
+ * @return Pointer to addr, or NULL if there is no such property
+ */
+void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index);
+
 /**
  * devfdt_get_addr_size_index() - Get the indexed reg property of a device
  *
Signature · 1 line
2.25.1
Reviewed-by on v1 5/9
#8 lore raw

Re: [PATCH 5/9] dm: core: Add a new API devfdt_get_addr_index_ptr()

Quoted 10 lines · Bin Meng

At present there is only devfdt_get_addr_ptr() which only returns the first <addr, size> pair in the 'reg' property. Add a new API devfdt_get_addr_index_ptr() to return the indexed pointer.

---

 drivers/core/fdtaddr.c | 11 ++++++++---
 include/dm/fdtaddr.h   | 12 ++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)
#9 lore raw

Re: [PATCH 5/9] dm: core: Add a new API devfdt_get_addr_index_ptr()

In reply to Bin Meng

Hi Bin,

Quoted 11 lines · Bin Meng

At present there is only devfdt_get_addr_ptr() which only returns the first <addr, size> pair in the 'reg' property. Add a new API devfdt_get_addr_index_ptr() to return the indexed pointer.

---

 drivers/core/fdtaddr.c | 11 ++++++++---
 include/dm/fdtaddr.h   | 12 ++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

Please do update the tests for this new function.

author
#10 lore raw

PATCH 6/9 dm: Provide dev_read_addr_index_ptr() wrapper

In reply to Bin Meng

Like dev_read_addr_ptr(), provide a wrapper for the indexed version.

---

 include/dm/read.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/dm/read.h +18 -0
index 5bf3405614..890bf3d847 100644
@@ -180,6 +180,18 @@ int dev_read_size(const struct udevice *dev, const char *propname);
  */
 fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
 
+/**
+ * dev_read_addr_index_ptr() - Get the indexed reg property of a device
+ *                             as a pointer
+ *
+ * @dev: Device to read from
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *	   and @index is used to select which one is required
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_read_addr_index_ptr(const struct udevice *dev, int index);
+
 /**
  * dev_read_addr_size_index() - Get the indexed reg property of a device
  *
@@ -805,6 +817,12 @@ static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
 	return devfdt_get_addr_index(dev, index);
 }
 
+static inline void *dev_read_addr_index_ptr(const struct udevice *dev,
+					    int index)
+{
+	return devfdt_get_addr_index_ptr(dev, index);
+}
+
 static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
 						  int index,
 						  fdt_size_t *size)
Signature · 1 line
2.25.1
author
#13 lore raw

PATCH 7/9 net: macb: Fix -Wint-to-pointer-cast warnings

In reply to Bin Meng

The following warning is seen in macb.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_index_ptr(), or cast with uintptr_t.

---

 drivers/net/macb.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/macb.c +3 -8
index 57ea45e2dc..fe14027b31 100644
@@ -574,14 +574,9 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH
 static int macb_sifive_clk_init(struct udevice *dev, ulong rate)
 {
-	fdt_addr_t addr;
 	void *gemgxl_regs;
 
-	addr = dev_read_addr_index(dev, 1);
-	if (addr == FDT_ADDR_T_NONE)
-		return -ENODEV;
-
-	gemgxl_regs = (void __iomem *)addr;
+	gemgxl_regs = dev_read_addr_index_ptr(dev, 1);
 	if (!gemgxl_regs)
 		return -ENODEV;
 
@@ -1383,7 +1378,7 @@ static int macb_eth_probe(struct udevice *dev)
 		macb->phy_addr = ofnode_read_u32_default(phandle_args.node,
 							 "reg", -1);
 
-	macb->regs = (void *)pdata->iobase;
+	macb->regs = (void *)(uintptr_t)pdata->iobase;
 
 	macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678);
 
@@ -1444,7 +1439,7 @@ static int macb_eth_of_to_plat(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
 
-	pdata->iobase = (phys_addr_t)dev_remap_addr(dev);
+	pdata->iobase = (uintptr_t)dev_remap_addr(dev);
 	if (!pdata->iobase)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 7/9
#14 lore raw

Re: [PATCH 7/9] net: macb: Fix -Wint-to-pointer-cast warnings

Quoted 52 lines · Bin Meng

The following warning is seen in macb.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_index_ptr(), or cast with uintptr_t.

---

 drivers/net/macb.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/macb.c +3 -9
index 57ea45e2dc..fe14027b31 100644
@@ -574,14 +574,9 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH
 static int macb_sifive_clk_init(struct udevice *dev, ulong rate)
 {
-       fdt_addr_t addr;
        void *gemgxl_regs;
 
-       addr = dev_read_addr_index(dev, 1);
-       if (addr == FDT_ADDR_T_NONE)
-               return -ENODEV;
-
-       gemgxl_regs = (void __iomem *)addr;
+       gemgxl_regs = dev_read_addr_index_ptr(dev, 1);
        if (!gemgxl_regs)
                return -ENODEV;
 
@@ -1383,7 +1378,7 @@ static int macb_eth_probe(struct udevice *dev)
                macb->phy_addr = ofnode_read_u32_default(phandle_args.node,
                                                         "reg", -1);
 
-       macb->regs = (void *)pdata->iobase;
+       macb->regs = (void *)(uintptr_t)pdata->iobase;
 
        macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678);
 
@@ -1444,7 +1439,7 @@ static int macb_eth_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
 
-       pdata->iobase = (phys_addr_t)dev_remap_addr(dev);
+       pdata->iobase = (uintptr_t)dev_remap_addr(dev);
        if (!pdata->iobase)
                return -EINVAL;
 
--
Quoted 2 lines

2.25.1

author
#15 lore raw

PATCH 8/9 ram: sifive: Fix -Wint-to-pointer-cast warnings

In reply to Bin Meng

The following warning is seen in sifive_ddr.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Change to use dev_read_addr_index_ptr().

---

 drivers/ram/sifive/sifive_ddr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/ram/sifive/sifive_ddr.c +4 -4
index ba18466033..4bd69a62be 100644
@@ -313,7 +313,7 @@ static int sifive_ddr_setup(struct udevice *dev)
 	sifive_ddr_phy_fixup(denali_phy);
 
 	/* check size */
-	priv->info.size = get_ram_size((long *)priv->info.base,
+	priv->info.size = get_ram_size((long *)(uintptr_t)priv->info.base,
 				       ddr_size);
 
 	debug("%s : %lx\n", __func__, (uintptr_t)priv->info.size);
@@ -369,9 +369,9 @@ static int sifive_ddr_probe(struct udevice *dev)
 		return ret;
 	}
 
-	priv->ctl = (struct sifive_ddrctl *)dev_read_addr_index(dev, 0);
-	priv->phy = (struct sifive_ddrphy *)dev_read_addr_index(dev, 1);
-	priv->physical_filter_ctrl = (u32 *)dev_read_addr_index(dev, 2);
+	priv->ctl = (struct sifive_ddrctl *)dev_read_addr_index_ptr(dev, 0);
+	priv->phy = (struct sifive_ddrphy *)dev_read_addr_index_ptr(dev, 1);
+	priv->physical_filter_ctrl = (u32 *)dev_read_addr_index_ptr(dev, 2);
 
 	return sifive_ddr_setup(dev);
 #endif
Signature · 1 line
2.25.1
Reviewed-by on v1 8/9
#16 lore raw

Re: [PATCH 8/9] ram: sifive: Fix -Wint-to-pointer-cast warnings

Quoted 4 lines · Bin Meng

The following warning is seen in sifive_ddr.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 8 lines

Change to use dev_read_addr_index_ptr().

---

 drivers/ram/sifive/sifive_ddr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
author
#17 lore raw

PATCH 9/9 board: sifive: Fix -Wint-to-pointer-cast warning

In reply to Bin Meng

The following warning is seen in unleashed.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Cast with uintptr_t.

---

 board/sifive/unleashed/unleashed.c | 2 +-
 board/sifive/unmatched/unmatched.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
board/sifive/unleashed/unleashed.c +1 -1
index 33baeda986..e7d2332d8c 100644
@@ -118,7 +118,7 @@ void *board_fdt_blob_setup(void)
 {
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
-			return (ulong *)gd->arch.firmware_fdt_addr;
+			return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
 	}
 
 	return (ulong *)&_end;
board/sifive/unmatched/unmatched.c +1 -1
index 8773b660fa..93c452c57f 100644
@@ -15,7 +15,7 @@ void *board_fdt_blob_setup(void)
 {
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
-			return (ulong *)gd->arch.firmware_fdt_addr;
+			return (ulong *)(uintptr_t)gd->arch.firmware_fdt_addr;
 	}
 
 	return (ulong *)&_end;
Signature · 1 line
2.25.1
Reviewed-by on v1 9/9
#18 lore raw

Re: [PATCH 9/9] board: sifive: Fix -Wint-to-pointer-cast warning

Quoted 4 lines · Bin Meng

The following warning is seen in unleashed.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 8 lines

Cast with uintptr_t.

---

 board/sifive/unleashed/unleashed.c | 2 +-
 board/sifive/unmatched/unmatched.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Reviewed-by on v1 1/9
#19 lore raw
In reply to Bin Meng
Quoted 11 lines · Bin Meng

The following warning is seen in cache-sifive-ccache.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fix by casting it with uintptr_t.

---

 drivers/cache/cache-sifive-ccache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

CONFIDENTIALITY NOTICE:

This e-mail (and its attachments) may contain confidential and legally privileged information or information protected from disclosure. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein is strictly prohibited. In this case, please immediately notify the sender by return e-mail, delete the message (and any accompanying documents) and destroy all printed hard copies. Thank you for your cooperation.

Copyright ANDES TECHNOLOGY CORPORATION - All Rights Reserved.

author
#20 lore raw
Quoted 8 lines · Leo Liang
Quoted 6 lines · Bin Meng

The following warning is seen in cache-sifive-ccache.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fix by casting it with uintptr_t.

Quoted 7 lines
Quoted 5 lines

---

 drivers/cache/cache-sifive-ccache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Ping for apply?

#21 lore raw
Quoted 12 lines · Bin Meng
Quoted 11 lines · Leo Liang
Quoted 9 lines · Bin Meng

The following warning is seen in cache-sifive-ccache.c in a 32-bit build:

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fix by casting it with uintptr_t.

---

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
 drivers/cache/cache-sifive-ccache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Ping for apply?

Hi Bin,

Sorry for the late reply.

For this patch set, I thought you were going to update the tests for the new API devfdt_get_addr_index_ptr() as Simon suggested.

Just wanted to make sure that you don't have any updates for this patchset, then I will apply this patch right away.

Hi Simon,

After checking the test/dm/test-fdt.c,
there seems to be no need for any updates, right?
Or is there anything I miss?

Best regards,
Leo