[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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/cache/cache-sifive-ccache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cache/cache-sifive-ccache.c b/drivers/cache/cache-sifive-ccache.c index 76c0ab26ae..c8766f6242 100644 --- a/drivers/cache/cache-sifive-ccache.c +++ b/drivers/cache/cache-sifive-ccache.c @@ -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; }

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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/clk/sifive/sifive-prci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/sifive/sifive-prci.c b/drivers/clk/sifive/sifive-prci.c index cd1acb9442..52ae268e0c 100644 --- a/drivers/clk/sifive/sifive-prci.c +++ b/drivers/clk/sifive/sifive-prci.c @@ -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)

On Sun, Sep 12, 2021 at 11:15:09AM +0800, Bin Meng wrote:
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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/clk/sifive/sifive-prci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/gpio/sifive-gpio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/sifive-gpio.c b/drivers/gpio/sifive-gpio.c index abd1f629b9..151f484e8f 100644 --- a/drivers/gpio/sifive-gpio.c +++ b/drivers/gpio/sifive-gpio.c @@ -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; }

On Sun, Sep 12, 2021 at 11:15:10AM +0800, Bin Meng wrote:
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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/gpio/sifive-gpio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/i2c/ocores_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/ocores_i2c.c b/drivers/i2c/ocores_i2c.c index f129ec3818..3b19ba78fa 100644 --- a/drivers/i2c/ocores_i2c.c +++ b/drivers/i2c/ocores_i2c.c @@ -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' */

On Sun, Sep 12, 2021 at 11:15:11AM +0800, Bin Meng wrote:
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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/i2c/ocores_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/core/fdtaddr.c | 11 ++++++++--- include/dm/fdtaddr.h | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 4ffbd6b2eb..8dbb06ab03 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -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) diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index a4fda581a7..d2c1994291 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -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 *

On Sun, Sep 12, 2021 at 11:15:12AM +0800, Bin Meng wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/core/fdtaddr.c | 11 ++++++++--- include/dm/fdtaddr.h | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

Hi Bin,
On Sat, 11 Sept 2021 at 21:15, Bin Meng bmeng.cn@gmail.com wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
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.

Like dev_read_addr_ptr(), provide a wrapper for the indexed version.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
include/dm/read.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/include/dm/read.h b/include/dm/read.h index 5bf3405614..890bf3d847 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -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)

On Sun, Sep 12, 2021 at 11:15:13AM +0800, Bin Meng wrote:
Like dev_read_addr_ptr(), provide a wrapper for the indexed version.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
include/dm/read.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

On Sat, 11 Sept 2021 at 21:15, Bin Meng bmeng.cn@gmail.com wrote:
Like dev_read_addr_ptr(), provide a wrapper for the indexed version.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
include/dm/read.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/net/macb.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 57ea45e2dc..fe14027b31 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -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;

On Sun, Sep 12, 2021 at 6:16 AM Bin Meng bmeng.cn@gmail.com wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/net/macb.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 57ea45e2dc..fe14027b31 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -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;
-- 2.25.1
Reviewed-by: Ramon Fried rfried.dev@gmail.com

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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
drivers/ram/sifive/sifive_ddr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/ram/sifive/sifive_ddr.c b/drivers/ram/sifive/sifive_ddr.c index ba18466033..4bd69a62be 100644 --- a/drivers/ram/sifive/sifive_ddr.c +++ b/drivers/ram/sifive/sifive_ddr.c @@ -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

On Sun, Sep 12, 2021 at 11:15:15AM +0800, Bin Meng wrote:
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().
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/ram/sifive/sifive_ddr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
board/sifive/unleashed/unleashed.c | 2 +- board/sifive/unmatched/unmatched.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/board/sifive/unleashed/unleashed.c b/board/sifive/unleashed/unleashed.c index 33baeda986..e7d2332d8c 100644 --- a/board/sifive/unleashed/unleashed.c +++ b/board/sifive/unleashed/unleashed.c @@ -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; diff --git a/board/sifive/unmatched/unmatched.c b/board/sifive/unmatched/unmatched.c index 8773b660fa..93c452c57f 100644 --- a/board/sifive/unmatched/unmatched.c +++ b/board/sifive/unmatched/unmatched.c @@ -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;

On Sun, Sep 12, 2021 at 11:15:16AM +0800, Bin Meng wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
board/sifive/unleashed/unleashed.c | 2 +- board/sifive/unmatched/unmatched.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

On Sun, Sep 12, 2021 at 11:15:08AM +0800, Bin Meng wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/cache/cache-sifive-ccache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com 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.

On Wed, Sep 15, 2021 at 11:40 AM Leo Liang ycliang@andestech.com wrote:
On Sun, Sep 12, 2021 at 11:15:08AM +0800, Bin Meng wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/cache/cache-sifive-ccache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com
Ping for apply?

On Mon, Oct 11, 2021 at 11:14:21AM +0800, Bin Meng wrote:
On Wed, Sep 15, 2021 at 11:40 AM Leo Liang ycliang@andestech.com wrote:
On Sun, Sep 12, 2021 at 11:15:08AM +0800, Bin Meng wrote:
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.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
drivers/cache/cache-sifive-ccache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com
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
participants (4)
-
Bin Meng
-
Leo Liang
-
Ramon Fried
-
Simon Glass