Skip to contentSkip to conversation

timer: dw-apb: fix compiler warnings

PATCH New Heinrich Schuchardt 2 participants 4 messages Aug 26, 2020 – Feb 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 timer: dw-apb: fix compiler warnings

readl() and writel() expect void *. Do not pass an integer value.

Remove unused include asm/arch/timer.h.

---
v2:
correct typo in commit message

---
 drivers/timer/dw-apb-timer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/timer/dw-apb-timer.c +3 -4
index 35271b20c8..c8be4417fd 100644
@@ -14,7 +14,6 @@
 #include <dm/device_compat.h>
 
 #include <asm/io.h>
-#include <asm/arch/timer.h>
 
 #define DW_APB_LOAD_VAL		0x0
 #define DW_APB_CURR_VAL		0x4
@@ -34,7 +33,7 @@ static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
 	 * requires the count to be incrementing. Invert the
 	 * result.
 	 */
-	*count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
+	*count = timer_conv_64(~readl((void *)(priv->regs + DW_APB_CURR_VAL)));
 
 	return 0;
 }
@@ -61,8 +60,8 @@ static int dw_apb_timer_probe(struct udevice *dev)
 	clk_free(&clk);
 
 	/* init timer */
-	writel(0xffffffff, priv->regs + DW_APB_LOAD_VAL);
-	writel(0xffffffff, priv->regs + DW_APB_CURR_VAL);
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_LOAD_VAL));
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_CURR_VAL));
 	setbits_le32(priv->regs + DW_APB_CTRL, 0x3);
 
 	return 0;

--
2.27.0

#1 lore raw

PATCH v2 1/1 timer: dw-apb: fix compiler warnings

Quoted 26 lines · Heinrich Schuchardt

readl() and writel() expect void *. Do not pass an integer value.

Remove unused include asm/arch/timer.h.

---
v2:
correct typo in commit message

---
 drivers/timer/dw-apb-timer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/timer/dw-apb-timer.c +0 -1
index 35271b20c8..c8be4417fd 100644
@@ -14,7 +14,6 @@
 #include <dm/device_compat.h>
 
 #include <asm/io.h>
-#include <asm/arch/timer.h>
 
 #define DW_APB_LOAD_VAL		0x0
 #define DW_APB_CURR_VAL		0x4

drivers/timer/dw-apb-timer.c static int dw_apb_timer_get_count(struct udevice *dev, u64 *count) · line 36

Quoted 5 lines
drivers/timer/dw-apb-timer.c +1 -1
@@ -34,7 +33,7 @@ static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
 	 * requires the count to be incrementing. Invert the
 	 * result.
 	 */
-	*count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
+	*count = timer_conv_64(~readl((void *)(priv->regs + DW_APB_CURR_VAL)));

How about changing the type of priv.regs to void * and using dev_read_addr_ptr instead of dev_read_addr in probe?

Quoted 17 lines
drivers/timer/dw-apb-timer.c +2 -3
 	return 0;
 }
@@ -61,8 +60,8 @@ static int dw_apb_timer_probe(struct udevice *dev)
 	clk_free(&clk);
 
 	/* init timer */
-	writel(0xffffffff, priv->regs + DW_APB_LOAD_VAL);
-	writel(0xffffffff, priv->regs + DW_APB_CURR_VAL);
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_LOAD_VAL));
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_CURR_VAL));
 	setbits_le32(priv->regs + DW_APB_CTRL, 0x3);
 
 	return 0;
--

2.27.0

#2 lore raw

PATCH v2 1/1 timer: dw-apb: fix compiler warnings

Am 26. August 2020 23:13:01 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 36 lines · Heinrich Schuchardt
Quoted 6 lines

readl() and writel() expect void *. Do not pass an integer value.

Remove unused include asm/arch/timer.h.

Review

Quoted 8 lines

---
v2:
correct typo in commit message

---
 drivers/timer/dw-apb-timer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/timer/dw-apb-timer.c

drivers/timer/dw-apb-timer.c static int dw_apb_timer_get_count(struct udevice

Quoted 12 lines

index 35271b20c8..c8be4417fd 100644

drivers/timer/dw-apb-timer.c +0 -1
@@ -14,7 +14,6 @@
 #include <dm/device_compat.h>
 
 #include <asm/io.h>
-#include <asm/arch/timer.h>
 
 #define DW_APB_LOAD_VAL		0x0
 #define DW_APB_CURR_VAL		0x4
@@ -34,7 +33,7 @@ static int dw_apb_timer_get_count(struct udevice

*dev, u64 *count)

drivers/timer/dw-apb-timer.c static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)

Quoted 5 lines
drivers/timer/dw-apb-timer.c +1 -1
 	 * requires the count to be incrementing. Invert the
 	 * result.
 	 */
-	*count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
+	*count = timer_conv_64(~readl((void *)(priv->regs +

DW_APB_CURR_VAL)));

Quoted 2 lines

How about changing the type of priv.regs to void * and using dev_read_addr_ptr instead of dev_read_addr in probe?

Adding to void* results undefined behavior in C. I know gcc currently supports it, but that does not make it recommendable.

If you wanted to change the type, you could use u8*.

A cleaner way would be to change regs to a pointer to a structure with all registers and to eliminate the offsets.

@Marek
Which way do you want it?

Best regards

Heinrich

Quoted 18 lines
Quoted 18 lines
drivers/timer/dw-apb-timer.c +2 -3
 	return 0;
 }
@@ -61,8 +60,8 @@ static int dw_apb_timer_probe(struct udevice *dev)
 	clk_free(&clk);
 
 	/* init timer */
-	writel(0xffffffff, priv->regs + DW_APB_LOAD_VAL);
-	writel(0xffffffff, priv->regs + DW_APB_CURR_VAL);
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_LOAD_VAL));
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_CURR_VAL));
 	setbits_le32(priv->regs + DW_APB_CTRL, 0x3);
 
 	return 0;
--

2.27.0

#3 lore raw

PATCH v2 1/1 timer: dw-apb: fix compiler warnings

Quoted 40 lines · Heinrich Schuchardt

Am 26. August 2020 23:13:01 MESZ schrieb Sean Anderson <[email protected]>:

Quoted 36 lines · Heinrich Schuchardt
Quoted 6 lines

readl() and writel() expect void *. Do not pass an integer value.

Remove unused include asm/arch/timer.h.

Review

Quoted 8 lines

---
v2:
correct typo in commit message

---
 drivers/timer/dw-apb-timer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/timer/dw-apb-timer.c

drivers/timer/dw-apb-timer.c static int dw_apb_timer_get_count(struct udevice

Quoted 12 lines

index 35271b20c8..c8be4417fd 100644

drivers/timer/dw-apb-timer.c +0 -1
@@ -14,7 +14,6 @@
 #include <dm/device_compat.h>
 
 #include <asm/io.h>
-#include <asm/arch/timer.h>
 
 #define DW_APB_LOAD_VAL		0x0
 #define DW_APB_CURR_VAL		0x4
@@ -34,7 +33,7 @@ static int dw_apb_timer_get_count(struct udevice

*dev, u64 *count)

drivers/timer/dw-apb-timer.c static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)

Quoted 5 lines
drivers/timer/dw-apb-timer.c +1 -1
 	 * requires the count to be incrementing. Invert the
 	 * result.
 	 */
-	*count = timer_conv_64(~readl(priv->regs + DW_APB_CURR_VAL));
+	*count = timer_conv_64(~readl((void *)(priv->regs +

DW_APB_CURR_VAL)));

Quoted 2 lines

How about changing the type of priv.regs to void * and using dev_read_addr_ptr instead of dev_read_addr in probe?

Quoted 8 lines

Adding to void* results in undefined behavior in C. I know gcc currently supports it, but that does not make it recommendable.

If you wanted to change the type, you could use u8*.

A cleaner way would be to change regs to a pointer to a structure with all registers and to eliminate the offsets.

@Marek
Which way do you want it?

Hello Marek,

What are your thoughts?

Best regards

Heinrich

Quoted 20 lines
Quoted 19 lines
Quoted 19 lines
drivers/timer/dw-apb-timer.c +2 -3
 	return 0;
 }
@@ -61,8 +60,8 @@ static int dw_apb_timer_probe(struct udevice *dev)
 	clk_free(&clk);
 
 	/* init timer */
-	writel(0xffffffff, priv->regs + DW_APB_LOAD_VAL);
-	writel(0xffffffff, priv->regs + DW_APB_CURR_VAL);
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_LOAD_VAL));
+	writel(0xffffffff, (void *)(priv->regs + DW_APB_CURR_VAL));
 	setbits_le32(priv->regs + DW_APB_CTRL, 0x3);
 
 	return 0;
--

2.27.0