Skip to contentSkip to conversation

lib: fix pointer of type 'void *' used in arithmetic

PATCH Superseded Jukka Laitinen 5 participants 10 messages Jan 13, 2022 – Jan 19, 2022

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]"

Avoid these by calculating on "char *" where 1-byte data size is assumed.

---
 include/sbi/sbi_scratch.h             | 4 ++--
 lib/sbi/sbi_fifo.c                    | 6 +++---
 lib/sbi/sbi_string.c                  | 4 ++--
 lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
 lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
 lib/utils/irqchip/plic.c              | 8 ++++----
 lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
 lib/utils/reset/fdt_reset_thead.c     | 4 ++--
 lib/utils/serial/gaisler-uart.c       | 4 ++--
 lib/utils/serial/shakti-uart.c        | 4 ++--
 lib/utils/serial/sifive-uart.c        | 4 ++--
 lib/utils/serial/uart8250.c           | 4 ++--
 lib/utils/timer/aclint_mtimer.c       | 2 +-
 13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)	((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)	(void *)((char *)(scratch) + (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)	\
-	((void *)sbi_scratch_thishart_ptr() + (offset))
+	(void *)((char *)sbi_scratch_thishart_ptr() + (offset))
 
 /** HART id to scratch table */
 extern struct sbi_scratch *hartid_to_scratch_table[];
lib/sbi/sbi_fifo.c +3 -3
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
 	if (head >= fifo->num_entries)
 		head = head - fifo->num_entries;
 
-	sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
+	sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
 
 	fifo->avail++;
 }
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
 		index = fifo->tail + i;
 		if (index >= fifo->num_entries)
 			index -= fifo->num_entries;
-		entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
+		entry = (char *)fifo->queue + (u32)index * fifo->entry_size;
 		ret = fptr(in, entry);
 
 		if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
 		return SBI_ENOENT;
 	}
 
-	sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size,
+	sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size,
 	       fifo->entry_size);
 
 	fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src, size_t count)
 			count--;
 		}
 	} else {
-		temp1 = dest + count - 1;
-		temp2 = src + count - 1;
+		temp1 = (char *)dest + count - 1;
+		temp2 = (char *)src + count - 1;
 
 		while (count > 0) {
 			*temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +2 -2
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
 				     uint8_t reg, uint8_t value)
 {
-	writel(value, (volatile void *)adap->addr + reg);
+	writel(value, (volatile char *)adap->addr + reg);
 }
 
 static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
 					uint8_t reg)
 {
-	return readl((volatile void *)adap->addr + reg);
+	return readl((volatile char *)adap->addr + reg);
 }
 
 static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)
lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-	writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+	writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG);
 }
 
 static const struct fdt_match irqchip_plic_match[] = {
lib/utils/irqchip/plic.c +4 -4
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 
 static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
 {
-	volatile void *plic_priority = (void *)plic->addr +
+	volatile void *plic_priority = (char *)plic->addr +
 			PLIC_PRIORITY_BASE + 4 * source;
 	writel(val, plic_priority);
 }
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32 cntxid, u32 val)
 	if (!plic)
 		return;
 
-	plic_thresh = (void *)plic->addr +
+	plic_thresh = (char *)plic->addr +
 		      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
 	writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val)
 {
-	volatile void *plic_ie;
+	volatile char *plic_ie;
 
 	if (!plic)
 		return;
 
-	plic_ie = (void *)plic->addr +
+	plic_ie = (char *)plic->addr +
 		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
 	writel(val, plic_ie + word_index * 4);
 }
lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG			0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int nodeoff,
 	if (rc < 0 || !reg_addr)
 		return SBI_ENODEV;
 
-	sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+	sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
 	sbi_system_reset_add_device(&sunxi_wdt_reset);
 
lib/utils/reset/fdt_reset_thead.c +2 -2
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
 				 const struct fdt_match *match)
 {
-	void *p;
+	char *p;
 	const fdt64_t *val;
 	const fdt32_t *val_w;
 	int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
 	/* Custom reset method for secondary harts */
 	val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
 	if (len > 0 && val) {
-		p = (void *)(ulong)fdt64_to_cpu(*val);
+		p = (char *)fdt64_to_cpu(*val);
 
 		val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
 		if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
 	u32 ctrl;
 
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 
 	/* Configure baudrate */
 	if (in_freq)
lib/utils/serial/shakti-uart.c +2 -2
index e77a985..5f2fe75 100644
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 	u16 baud = (u16)(in_freq/(16 * baudrate));
 	writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive-uart.c +2 -2
index 57d80fa..9478a77 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base     = (volatile void *)base;
+	uart_base     = (volatile char *)base;
 	uart_in_freq  = in_freq;
 	uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
 {
 	u16 bdiv;
 
-	uart8250_base      = (volatile void *)base;
+	uart8250_base      = (volatile char *)base;
 	uart8250_reg_shift = reg_shift;
 	uart8250_reg_width = reg_width;
 	uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +1 -1
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)
 static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)
 {
 	writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
-	writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+	writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
 	writel_relaxed((u32)value, (void *)(addr));
 }
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 8 lines

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer- arith]"

Avoid these by calculating on "char *" where 1-byte data size is assumed.

char has a specific meaning, such modification is not conducive to code reading. I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off)

{
     return (void *)((uintptr_t)p + off);
}

Regards,
Xiang W

Quoted 333 lines

---

?include/sbi/sbi_scratch.h???????????? | 4 ++--
?lib/sbi/sbi_fifo.c??????????????????? | 6 +++---
?lib/sbi/sbi_string.c????????????????? | 4 ++--
?lib/utils/i2c/fdt_i2c_sifive.c??????? | 4 ++--
?lib/utils/irqchip/fdt_irqchip_plic.c? | 2 +-
?lib/utils/irqchip/plic.c????????????? | 8 ++++----
?lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
?lib/utils/reset/fdt_reset_thead.c???? | 4 ++--
?lib/utils/serial/gaisler-uart.c?????? | 4 ++--
?lib/utils/serial/shakti-uart.c??????? | 4 ++--
?lib/utils/serial/sifive-uart.c??????? | 4 ++--
?lib/utils/serial/uart8250.c?????????? | 4 ++--
?lib/utils/timer/aclint_mtimer.c?????? | 2 +-

?13 files changed, 27 insertions(+), 27 deletions(-)

include/sbi/sbi_scratch.h +0 -0
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned
 long size);
 ?void sbi_scratch_free_offset(unsigned long offset);

?
?/** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)????????((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)????????(void *)((char *)(scratch) + (offset))
?
?/** Get pointer from offset in sbi_scratch for current HART */ ?#define sbi_scratch_thishart_offset_ptr(offset)????????\
-???????((void *)sbi_scratch_thishart_ptr() + (offset)) +???????(void *)((char *)sbi_scratch_thishart_ptr() + (offset)) ?
?/** HART id to scratch table */
?extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +0 -0
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void? __sbi_fifo_enqueue(struct
 sbi_fifo *fifo, void *data)
 ????????if (head >= fifo->num_entries)
 ????????????????head = head - fifo->num_entries;

?
-???????sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-

Quoted 1 line

entry_size);

+???????sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
?
????????fifo->avail++;
?}

lib/sbi/sbi_fifo.c +1 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo,
 void *in,
 ????????????????index = fifo->tail + i;
 ????????????????if (index >= fifo->num_entries)
 ????????????????????????index -= fifo->num_entries;
-???????????????entry = (void *)fifo->queue + (u32)index * fifo-
 >entry_size;
+???????????????entry = (char *)fifo->queue + (u32)index * fifo-
 >entry_size;

????????????????ret = fptr(in, entry);
?
????????????????if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {

lib/sbi/sbi_fifo.c +0 -0
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void
 *data)
 ????????????????return SBI_ENOENT;
 ????????}

?
-???????sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-

Quoted 1 line

entry_size,

+???????sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo-

Quoted 1 line

entry_size,

?????????????? fifo->entry_size);
?
????????fifo->avail--;

lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src,
 size_t count)
 ????????????????????????count--;
 ????????????????}
 ????????} else {
-???????????????temp1 = dest + count - 1;
-???????????????temp2 = src + count - 1;
+???????????????temp1 = (char *)dest + count - 1;
+???????????????temp2 = (char *)src + count - 1;

?
????????????????while (count > 0) {
????????????????????????*temp1-- = *temp2--;

lib/utils/i2c/fdt_i2c_sifive.c +1 -1
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;
 ?static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
 ???????????????????????????????????? uint8_t reg, uint8_t value)
 ?{
-???????writel(value, (volatile void *)adap->addr + reg);
+???????writel(value, (volatile char *)adap->addr + reg);
 ?}

?
?static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
????????????????????????????????????????uint8_t reg)
?{
-???????return readl((volatile void *)adap->addr + reg); +???????return readl((volatile char *)adap->addr + reg); ?}
?
?static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +0 -0
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int
 nodeoff,

?
?static void thead_plic_plat_init(struct plic_data *pd) ?{
-???????writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG); +???????writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG);
?}
?
?static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +0 -0
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@

?
?static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
?{
-???????volatile void *plic_priority = (void *)plic->addr + +???????volatile void *plic_priority = (char *)plic->addr + ????????????????????????PLIC_PRIORITY_BASE + 4 * source; ????????writel(val, plic_priority);
?}

lib/utils/irqchip/plic.c +0 -0
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32
 cntxid, u32 val)
 ????????if (!plic)
 ????????????????return;

?
-???????plic_thresh = (void *)plic->addr + +???????plic_thresh = (char *)plic->addr + ????????????????????? PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
????????writel(val, plic_thresh);
?}
?
?void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val)
?{
-???????volatile void *plic_ie;
+???????volatile char *plic_ie;
?
????????if (!plic)
????????????????return;
?
-???????plic_ie = (void *)plic->addr +
+???????plic_ie = (char *)plic->addr +
?????????????????? PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid; ????????writel(val, plic_ie + word_index * 4);
?}

lib/utils/reset/fdt_reset_sunxi_wdt.c +0 -0
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@

?
?#define WDT_MODE_REG???????????????????0x18
?

lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;

?
?static int sunxi_wdt_system_reset_check(u32 type, u32 reason) ?{

lib/utils/reset/fdt_reset_sunxi_wdt.c +0 -0
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int
 nodeoff,
 ????????if (rc < 0 || !reg_addr)
 ????????????????return SBI_ENODEV;

?
-???????sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr; +???????sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr; ? ????????sbi_system_reset_add_device(&sunxi_wdt_reset); ?

lib/utils/reset/fdt_reset_thead.c +1 -1
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 ?static int thead_reset_init(void *fdt, int nodeoff,
 ???????????????????????????????? const struct fdt_match *match)
 ?{
-???????void *p;
+???????char *p;
 ????????const fdt64_t *val;
 ????????const fdt32_t *val_w;
 ????????int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,

????????/* Custom reset method for secondary harts */ ????????val = fdt_getprop(fdt, nodeoff, "entry-reg", &len); ????????if (len > 0 && val) {
-???????????????p = (void *)(ulong)fdt64_to_cpu(*val); +???????????????p = (char *)fdt64_to_cpu(*val);
?
????????????????val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len); ????????????????if (len > 0 && val_w) {

lib/utils/serial/gaisler-uart.c +0 -0
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@

?
?/* clang-format on */
?

lib/utils/serial/gaisler-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?
?static u32 get_reg(u32 num)
?{

lib/utils/serial/gaisler-uart.c +0 -0
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32
 in_freq, u32 baudrate)
 ?{
 ????????u32 ctrl;

?
-???????uart_base = (volatile void *)base;
+???????uart_base = (volatile char *)base;
?
????????/* Configure baudrate */
????????if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +0 -0
@@ -21,7 +21,7 @@

?#define UART_TX_FULL? 0x2
?#define UART_RX_FULL? 0x8
?

lib/utils/serial/shakti-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?
?static void shakti_uart_putc(char ch)
?{

lib/utils/serial/shakti-uart.c +0 -0
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {

?
?int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate) ?{
-???????uart_base = (volatile void *)base; +???????uart_base = (volatile char *)base;
????????u16 baud = (u16)(in_freq/(16 * baudrate)); ????????writew(baud, uart_base + REG_BAUD);
?

lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +0 -0
@@ -29,7 +29,7 @@

?
?/* clang-format on */
?

lib/utils/serial/sifive-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?static u32 uart_in_freq;
?static u32 uart_baudrate;
?

lib/utils/serial/sifive-uart.c +0 -0
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {

?
?int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate) ?{
-???????uart_base???? = (volatile void *)base; +???????uart_base???? = (volatile char *)base; ????????uart_in_freq? = in_freq;
????????uart_baudrate = baudrate;
?

lib/utils/serial/uart8250.c +0 -0
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@

?
?/* clang-format on */
?

lib/utils/serial/uart8250.c +1 -1
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;

?static u32 uart8250_in_freq;
?static u32 uart8250_baudrate;
?static u32 uart8250_reg_width;

lib/utils/serial/uart8250.c +0 -0
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq,
 u32 baudrate, u32 reg_shift,
 ?{
 ????????u16 bdiv;

?
-???????uart8250_base????? = (volatile void *)base; +???????uart8250_base????? = (volatile char *)base; ????????uart8250_reg_shift = reg_shift; ????????uart8250_reg_width = reg_width; ????????uart8250_in_freq?? = in_freq;

lib/utils/timer/aclint_mtimer.c +0 -0
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)

?static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)
?{
????????writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr)); -???????writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04); +???????writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04); ????????writel_relaxed((u32)value, (void *)(addr));
?}
?

Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

Quoted 7 lines · Xiang W

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 5 lines

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer- arith]"

Quoted 5 lines
Quoted 3 lines

Avoid these by calculating on "char *" where 1-byte data size is assumed.

char has a specific meaning, such modification is not conducive to code reading.

This is extremely idiomatic, you see it everywhere in systems code.

Quoted 6 lines

I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off)

{
    return (void *)((uintptr_t)p + off);
}

This only serves to complicate, and using uintptr_t when you don?t need to is bad practice. Plus your version won?t work with volatile and/or const qualified pointers without warning if the relevant warnings are enabled.

Jess

Quoted 342 lines

Regards,
Xiang W

Quoted 333 lines
---
 include/sbi/sbi_scratch.h             | 4 ++--
 lib/sbi/sbi_fifo.c                    | 6 +++---
 lib/sbi/sbi_string.c                  | 4 ++--
 lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
 lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
 lib/utils/irqchip/plic.c              | 8 ++++----
 lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
 lib/utils/reset/fdt_reset_thead.c     | 4 ++--
 lib/utils/serial/gaisler-uart.c       | 4 ++--
 lib/utils/serial/shakti-uart.c        | 4 ++--
 lib/utils/serial/sifive-uart.c        | 4 ++--
 lib/utils/serial/uart8250.c           | 4 ++--
 lib/utils/timer/aclint_mtimer.c       | 2 +-
 13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned
 long size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)        ((void
 *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)        (void *)((char
 *)(scratch) + (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)        \
-       ((void *)sbi_scratch_thishart_ptr() + (offset))
+       (void *)((char *)sbi_scratch_thishart_ptr() + (offset))

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +1 -1
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct
 sbi_fifo *fifo, void *data)
        if (head >= fifo->num_entries)
                head = head - fifo->num_entries;
 
-       sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-
 > entry_size);
+       sbi_memcpy((char *)fifo->queue + head * fifo->entry_size,
 data, fifo->entry_size);
 
        fifo->avail++;

}

lib/sbi/sbi_fifo.c +1 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo,
 void *in,
                index = fifo->tail + i;
                if (index >= fifo->num_entries)
                        index -= fifo->num_entries;
-               entry = (void *)fifo->queue + (u32)index * fifo-
 > entry_size;
+               entry = (char *)fifo->queue + (u32)index * fifo-
 > entry_size;
                ret = fptr(in, entry);
 
                if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
lib/sbi/sbi_fifo.c +1 -1
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void
 *data)
                return SBI_ENOENT;
        }
 
-       sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
+       sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
               fifo->entry_size);
 
        fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src,
 size_t count)
                        count--;
                }
        } else {
-               temp1 = dest + count - 1;
-               temp2 = src + count - 1;
+               temp1 = (char *)dest + count - 1;
+               temp2 = (char *)src + count - 1;
 
                while (count > 0) {
                        *temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +2 -2
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
                                     uint8_t reg, uint8_t value)
 {
-       writel(value, (volatile void *)adap->addr + reg);
+       writel(value, (volatile char *)adap->addr + reg);
 }
 
 static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter
 *adap,
                                        uint8_t reg)
 {
-       return readl((volatile void *)adap->addr + reg);
+       return readl((volatile char *)adap->addr + reg);
 }

static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int
 nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-       writel_relaxed(BIT(0), (void *)pd->addr +
 THEAD_PLIC_CTRL_REG);
+       writel_relaxed(BIT(0), (char *)pd->addr +
 THEAD_PLIC_CTRL_REG);

}

static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +1 -1
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 
 static void plic_set_priority(struct plic_data *plic, u32 source, u32
 val)
 {
-       volatile void *plic_priority = (void *)plic->addr +
+       volatile void *plic_priority = (char *)plic->addr +
                        PLIC_PRIORITY_BASE + 4 * source;
        writel(val, plic_priority);

}

lib/utils/irqchip/plic.c +3 -3
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32
 cntxid, u32 val)
        if (!plic)
                return;
 
-       plic_thresh = (void *)plic->addr +
+       plic_thresh = (char *)plic->addr +
                      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE *
 cntxid;
        writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index,
 u32 val)
 {
-       volatile void *plic_ie;
+       volatile char *plic_ie;
 
        if (!plic)
                return;
 
-       plic_ie = (void *)plic->addr +
+       plic_ie = (char *)plic->addr +
                   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
        writel(val, plic_ie + word_index * 4);

}

lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG                   0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int
 nodeoff,
        if (rc < 0 || !reg_addr)
                return SBI_ENODEV;
 
-       sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+       sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
        sbi_system_reset_add_device(&sunxi_wdt_reset);
lib/utils/reset/fdt_reset_thead.c +2 -2
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
                                 const struct fdt_match *match)
 {
-       void *p;
+       char *p;
        const fdt64_t *val;
        const fdt32_t *val_w;
        int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
        /* Custom reset method for secondary harts */
        val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
        if (len > 0 && val) {
-               p = (void *)(ulong)fdt64_to_cpu(*val);
+               p = (char *)fdt64_to_cpu(*val);
 
                val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
                if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32
 in_freq, u32 baudrate)
 {
        u32 ctrl;
 
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
 
        /* Configure baudrate */

if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +2 -2
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
        u16 baud = (u16)(in_freq/(16 * baudrate));
        writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +2 -2
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base     = (volatile void *)base;
+       uart_base     = (volatile char *)base;
        uart_in_freq  = in_freq;
        uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq,
 u32 baudrate, u32 reg_shift,
 {
        u16 bdiv;
 
-       uart8250_base      = (volatile void *)base;
+       uart8250_base      = (volatile char *)base;
        uart8250_reg_shift = reg_shift;
        uart8250_reg_width = reg_width;
        uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +1 -1
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)
 static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64
 *addr)
 {
        writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
-       writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+       writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
        writel_relaxed((u32)value, (void *)(addr));
 }
Signature · 2 lines
-- 
2.25.1
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

Quoted 9 lines · Jessica Clarke
Quoted 7 lines · Xiang W

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 5 lines

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer- arith]"

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Avoid these by calculating on "char *" where 1-byte data size is assumed.

char has a specific meaning, such modification is not conducive to code reading.

This is extremely idiomatic, you see it everywhere in systems code.

See [1] for a crude estimate of how much code uses this idiom.

Jess

[1] https://codesearch.debian.net/search?q=%5C*%5C%29%5C%28%5C%28char+%5C*%5C%29%5BA-Za-z0-9_-%5D%2B+%5C%2B&literal=0&perpkg=1

Quoted 357 lines
Quoted 6 lines

I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off)

{
   return (void *)((uintptr_t)p + off);
}

This only serves to complicate, and using uintptr_t when you don?t need to is bad practice. Plus your version won?t work with volatile and/or const qualified pointers without warning if the relevant warnings are enabled.

Jess

Quoted 342 lines

Regards,
Xiang W

Quoted 333 lines

---

include/sbi/sbi_scratch.h             | 4 ++--
lib/sbi/sbi_fifo.c                    | 6 +++---
lib/sbi/sbi_string.c                  | 4 ++--
lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
lib/utils/irqchip/plic.c              | 8 ++++----
lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
lib/utils/reset/fdt_reset_thead.c     | 4 ++--
lib/utils/serial/gaisler-uart.c       | 4 ++--
lib/utils/serial/shakti-uart.c        | 4 ++--
lib/utils/serial/sifive-uart.c        | 4 ++--
lib/utils/serial/uart8250.c           | 4 ++--
lib/utils/timer/aclint_mtimer.c       | 2 +-
13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned
 long size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)        ((void
 *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)        (void *)((char
 *)(scratch) + (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)        \
-       ((void *)sbi_scratch_thishart_ptr() + (offset))
+       (void *)((char *)sbi_scratch_thishart_ptr() + (offset))

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +1 -1
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct
 sbi_fifo *fifo, void *data)
       if (head >= fifo->num_entries)
               head = head - fifo->num_entries;
 
-       sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-
 > entry_size);
+       sbi_memcpy((char *)fifo->queue + head * fifo->entry_size,
 data, fifo->entry_size);
       fifo->avail++;
}
lib/sbi/sbi_fifo.c +1 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo,
 void *in,
               index = fifo->tail + i;
               if (index >= fifo->num_entries)
                       index -= fifo->num_entries;
-               entry = (void *)fifo->queue + (u32)index * fifo-
 > entry_size;
+               entry = (char *)fifo->queue + (u32)index * fifo-
 > entry_size;
               ret = fptr(in, entry);

               if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
lib/sbi/sbi_fifo.c +1 -1
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void
 *data)
               return SBI_ENOENT;
       }
 
-       sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
+       sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
              fifo->entry_size);

       fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src,
 size_t count)
                       count--;
               }
       } else {
-               temp1 = dest + count - 1;
-               temp2 = src + count - 1;
+               temp1 = (char *)dest + count - 1;
+               temp2 = (char *)src + count - 1;
 
               while (count > 0) {
                       *temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +1 -1
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
                                    uint8_t reg, uint8_t value)
 {
-       writel(value, (volatile void *)adap->addr + reg);
+       writel(value, (volatile char *)adap->addr + reg);
 }
 

static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
uint8_t reg)
{

lib/utils/i2c/fdt_i2c_sifive.c +1 -1
-       return readl((volatile void *)adap->addr + reg);
+       return readl((volatile char *)adap->addr + reg);

}

static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int
 nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-       writel_relaxed(BIT(0), (void *)pd->addr +
 THEAD_PLIC_CTRL_REG);
+       writel_relaxed(BIT(0), (char *)pd->addr +
 THEAD_PLIC_CTRL_REG);

}

static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +0 -0
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 

static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
{

lib/utils/irqchip/plic.c +1 -1
-       volatile void *plic_priority = (void *)plic->addr +
+       volatile void *plic_priority = (char *)plic->addr +
                       PLIC_PRIORITY_BASE + 4 * source;
       writel(val, plic_priority);

}

lib/utils/irqchip/plic.c +3 -3
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32
 cntxid, u32 val)
       if (!plic)
               return;
 
-       plic_thresh = (void *)plic->addr +
+       plic_thresh = (char *)plic->addr +
                     PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE *
 cntxid;
       writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index,
 u32 val)
 {
-       volatile void *plic_ie;
+       volatile char *plic_ie;
 
       if (!plic)
               return;
 
-       plic_ie = (void *)plic->addr +
+       plic_ie = (char *)plic->addr +
                  PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
       writel(val, plic_ie + word_index * 4);
}
lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG                   0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int
 nodeoff,
       if (rc < 0 || !reg_addr)
               return SBI_ENODEV;
 
-       sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+       sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
       sbi_system_reset_add_device(&sunxi_wdt_reset);
lib/utils/reset/fdt_reset_thead.c +2 -2
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
                                const struct fdt_match *match)
 {
-       void *p;
+       char *p;
       const fdt64_t *val;
       const fdt32_t *val_w;
       int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
       /* Custom reset method for secondary harts */
       val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
       if (len > 0 && val) {
-               p = (void *)(ulong)fdt64_to_cpu(*val);
+               p = (char *)fdt64_to_cpu(*val);
 
               val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
               if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32
 in_freq, u32 baudrate)
 {
       u32 ctrl;
 
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
 
       /* Configure baudrate */

if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +2 -2
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
       u16 baud = (u16)(in_freq/(16 * baudrate));
       writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +2 -2
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base     = (volatile void *)base;
+       uart_base     = (volatile char *)base;
       uart_in_freq  = in_freq;
       uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq,
 u32 baudrate, u32 reg_shift,
 {
       u16 bdiv;
 
-       uart8250_base      = (volatile void *)base;
+       uart8250_base      = (volatile char *)base;
       uart8250_reg_shift = reg_shift;
       uart8250_reg_width = reg_width;
       uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +0 -0
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)

static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)

{
       writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
lib/utils/timer/aclint_mtimer.c +1 -1
-       writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+       writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
       writel_relaxed((u32)value, (void *)(addr));

}

Signature · 1 line
2.25.1
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#4 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

Thanks Jess!

Quoted 11 lines · Jessica Clarke
Quoted 10 lines · Jessica Clarke
Quoted 9 lines · Xiang W

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 8 lines

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer- arith]"

Avoid these by calculating on "char *" where 1-byte data size is assumed.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

char has a specific meaning, such modification is not conducive to code reading.

This is extremely idiomatic, you see it everywhere in systems code.

See [1] for a crude estimate of how much code uses this idiom.

Jess

[1] https://codesearch.debian.net/search?q=%5C*%5C%29%5C%28%5C%28char+%5C*%5C%29%5BA-Za-z0-9_-%5D%2B+%5C%2B&literal=0&perpkg=1

Yes, it is very common, and IMHO is strange property of a C language; I'll explain my thinking a bit longer...

As I explained previously, typically it is wrong to just cast pointers to integers and vice versa.

In C standards, the "void *" and "char *" are tightly tied to each other:

"A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements."

This is my opinion on void * arithmetic: As the size of "void" is not standard, it is really not proper to do arithmetic on "void *", even though this is enabled by gcc extension by doing the same as for char *. Simply because normally *(ptr+x) == ptr[x], and this is not valid on void ptr. For indexing, both alignment and data type size may matter for the compiler.

The GCC extension comes from the above definition (which basically says that void * can point to objects similarly aligned as char *). Also the standard basically says that sizeof(char *) == sizeof(void *).

What the original code does is, that it is indexing void pointers like they were char pointers (this is what the gcc extension does). So if you want to keep exactly the same functionality everywhere, the right thing is to cast it to char *. Anything else could (theoretically) lead to something else.

So, IMHO, using "char *" there is the most proper way to fix this specific compilation error. The best thing acc. to the standards is to always cast void * to the actual target data type, and let the compiler do the offset calculation based on the data type size and alignment(!), and the size of the char etc...

But I just wanted to do a change that doesn't change the functionality, or even the generated code, but just get rid of the warning/error and get rid of non-standard code...

Quoted 355 lines
Quoted 355 lines
Quoted 7 lines

I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off)

{
    return (void *)((uintptr_t)p + off);
}

This only serves to complicate, and using uintptr_t when you don?t need to is bad practice. Plus your version won?t work with volatile and/or const qualified pointers without warning if the relevant warnings are enabled.

Jess

Quoted 341 lines

Regards,
Xiang W

Quoted 333 lines

---

include/sbi/sbi_scratch.h             | 4 ++--
lib/sbi/sbi_fifo.c                    | 6 +++---
lib/sbi/sbi_string.c                  | 4 ++--
lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
lib/utils/irqchip/plic.c              | 8 ++++----
lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
lib/utils/reset/fdt_reset_thead.c     | 4 ++--
lib/utils/serial/gaisler-uart.c       | 4 ++--
lib/utils/serial/shakti-uart.c        | 4 ++--
lib/utils/serial/sifive-uart.c        | 4 ++--
lib/utils/serial/uart8250.c           | 4 ++--
lib/utils/timer/aclint_mtimer.c       | 2 +-
13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned
 long size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)        ((void
 *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)        (void *)((char
 *)(scratch) + (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)        \
-       ((void *)sbi_scratch_thishart_ptr() + (offset))
+       (void *)((char *)sbi_scratch_thishart_ptr() + (offset))

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +1 -1
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct
 sbi_fifo *fifo, void *data)
        if (head >= fifo->num_entries)
                head = head - fifo->num_entries;
 
-       sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-
 > entry_size);
+       sbi_memcpy((char *)fifo->queue + head * fifo->entry_size,
 data, fifo->entry_size);
        fifo->avail++;
}
lib/sbi/sbi_fifo.c +1 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo,
 void *in,
                index = fifo->tail + i;
                if (index >= fifo->num_entries)
                        index -= fifo->num_entries;
-               entry = (void *)fifo->queue + (u32)index * fifo-
 > entry_size;
+               entry = (char *)fifo->queue + (u32)index * fifo-
 > entry_size;
                ret = fptr(in, entry);

                if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
lib/sbi/sbi_fifo.c +1 -1
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void
 *data)
                return SBI_ENOENT;
        }
 
-       sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
+       sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
               fifo->entry_size);

        fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src,
 size_t count)
                        count--;
                }
        } else {
-               temp1 = dest + count - 1;
-               temp2 = src + count - 1;
+               temp1 = (char *)dest + count - 1;
+               temp2 = (char *)src + count - 1;
 
                while (count > 0) {
                        *temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +1 -1
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
                                     uint8_t reg, uint8_t value)
 {
-       writel(value, (volatile void *)adap->addr + reg);
+       writel(value, (volatile char *)adap->addr + reg);
 }
 

static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
uint8_t reg)
{

lib/utils/i2c/fdt_i2c_sifive.c +1 -1
-       return readl((volatile void *)adap->addr + reg);
+       return readl((volatile char *)adap->addr + reg);

}

static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int
 nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-       writel_relaxed(BIT(0), (void *)pd->addr +
 THEAD_PLIC_CTRL_REG);
+       writel_relaxed(BIT(0), (char *)pd->addr +
 THEAD_PLIC_CTRL_REG);

}

static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +0 -0
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 

static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
{

lib/utils/irqchip/plic.c +1 -1
-       volatile void *plic_priority = (void *)plic->addr +
+       volatile void *plic_priority = (char *)plic->addr +
                        PLIC_PRIORITY_BASE + 4 * source;
        writel(val, plic_priority);

}

lib/utils/irqchip/plic.c +3 -3
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32
 cntxid, u32 val)
        if (!plic)
                return;
 
-       plic_thresh = (void *)plic->addr +
+       plic_thresh = (char *)plic->addr +
                      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE *
 cntxid;
        writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index,
 u32 val)
 {
-       volatile void *plic_ie;
+       volatile char *plic_ie;
 
        if (!plic)
                return;
 
-       plic_ie = (void *)plic->addr +
+       plic_ie = (char *)plic->addr +
                   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
        writel(val, plic_ie + word_index * 4);
}
lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG                   0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int
 nodeoff,
        if (rc < 0 || !reg_addr)
                return SBI_ENODEV;
 
-       sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+       sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
        sbi_system_reset_add_device(&sunxi_wdt_reset);
lib/utils/reset/fdt_reset_thead.c +2 -2
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
                                 const struct fdt_match *match)
 {
-       void *p;
+       char *p;
        const fdt64_t *val;
        const fdt32_t *val_w;
        int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
        /* Custom reset method for secondary harts */
        val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
        if (len > 0 && val) {
-               p = (void *)(ulong)fdt64_to_cpu(*val);
+               p = (char *)fdt64_to_cpu(*val);
 
                val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
                if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32
 in_freq, u32 baudrate)
 {
        u32 ctrl;
 
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
 
        /* Configure baudrate */

if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +2 -2
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base = (volatile void *)base;
+       uart_base = (volatile char *)base;
        u16 baud = (u16)(in_freq/(16 * baudrate));
        writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +2 -2
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-       uart_base     = (volatile void *)base;
+       uart_base     = (volatile char *)base;
        uart_in_freq  = in_freq;
        uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq,
 u32 baudrate, u32 reg_shift,
 {
        u16 bdiv;
 
-       uart8250_base      = (volatile void *)base;
+       uart8250_base      = (volatile char *)base;
        uart8250_reg_shift = reg_shift;
        uart8250_reg_width = reg_width;
        uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +0 -0
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)

static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)

{
        writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
lib/utils/timer/aclint_mtimer.c +1 -1
-       writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+       writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
        writel_relaxed((u32)value, (void *)(addr));

}

Signature · 1 line
2.25.1
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#5 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

? 2022-01-13???? 18:42 +0200?Jukka Laitinen???

Quoted 80 lines

Thanks Jess!

Quoted 17 lines · Jessica Clarke
Quoted 16 lines · Jessica Clarke
Quoted 15 lines · Xiang W

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 11 lines

Using "void *" in arithmetic causes errors with strict compiler
settings:
"error: pointer of type 'void *' used in arithmetic [- Werror=pointer-
arith]"

Avoid these by calculating on "char *" where 1-byte data size is
assumed.

char has a specific meaning, such modification is not conducive to code
reading.

Quoted 8 lines
Quoted 2 lines

This is extremely idiomatic, you see it everywhere in systems code.

See [1] for a crude estimate of how much code uses this idiom.

Jess

[1]
https://codesearch.debian.net/search?q=%5C*%5C%29%5C%28%5C%28char+%5C*%5C%29%5BA-Za-z0-9_-%5D%2B+%5C%2B&literal=0&perpkg=1

Yes, it is very common, and IMHO is strange property of a C language; I'll explain my thinking a bit longer...

As I explained previously, typically it is wrong to just cast pointers to integers and vice versa.

In C standards, the "void *" and "char *" are tightly tied to each other:

"A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements."

This is my opinion on void * arithmetic: As the size of "void" is not standard, it is really not proper to do arithmetic on "void *", even though this is enabled by gcc extension by doing the same as for char *.
Simply because normally *(ptr+x) == ptr[x], and this is not valid on void ptr. For indexing, both alignment and data type size may matter for
the compiler.

The GCC extension comes from the above definition (which basically says
that void * can point to objects similarly aligned as char *). Also the
standard basically says that sizeof(char *) == sizeof(void *).

What the original code does is, that it is indexing void pointers like they were char pointers (this is what the gcc extension does). So if you
want to keep exactly the same functionality everywhere, the right thing
is to cast it to char *. Anything else could (theoretically) lead to something else.

So, IMHO, using "char *" there is the most proper way to fix this specific compilation error. The best thing acc. to the standards is to always cast void * to the actual target data type, and let the compiler
do the offset calculation based on the data type size and alignment(!),
and the size of the char etc...

Quoted 5 lines

But I just wanted to do a change that doesn't change the functionality,
or even the generated code, but just get rid of the warning/error and get rid of non-standard code...

This patch is necessary, thank you for your work. I think it is reasonable to convert void* to char* and then perform the calculation, because the size of char is one byte in general platforms. I just wanted to propose adding a ptr_with_offset to clarify the meaning, char* would give the feel of a string.

Regards?
Xiang W

Quoted 404 lines
Quoted 403 lines
Quoted 403 lines
Quoted 8 lines

I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off) {
??? return (void *)((uintptr_t)p + off);
}

This only serves to complicate, and using uintptr_t when you don?t need
to is bad practice. Plus your version won?t work with volatile and/or
const qualified pointers without warning if the relevant warnings are
enabled.

Jess

Quoted 385 lines

Regards,
Xiang W

Quoted 377 lines

---

include/sbi/sbi_scratch.h???????????? | 4 ++--
lib/sbi/sbi_fifo.c??????????????????? | 6 +++---
lib/sbi/sbi_string.c????????????????? | 4 ++--
lib/utils/i2c/fdt_i2c_sifive.c??????? | 4 ++--
lib/utils/irqchip/fdt_irqchip_plic.c? | 2 +-
lib/utils/irqchip/plic.c????????????? | 8 ++++----
lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
lib/utils/reset/fdt_reset_thead.c???? | 4 ++--
lib/utils/serial/gaisler-uart.c?????? | 4 ++--
lib/utils/serial/shakti-uart.c??????? | 4 ++--
lib/utils/serial/sifive-uart.c??????? | 4 ++--
lib/utils/serial/uart8250.c?????????? | 4 ++--
lib/utils/timer/aclint_mtimer.c?????? | 2 +-
13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +0 -0
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long

sbi_scratch_alloc_offset(unsigned
long size);
void sbi_scratch_free_offset(unsigned long offset);

/** Get pointer from offset in sbi_scratch */ -#define sbi_scratch_offset_ptr(scratch, offset)??????? ((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)??????? (void *)((char
*)(scratch) + (offset))

/** Get pointer from offset in sbi_scratch for current HART */ #define sbi_scratch_thishart_offset_ptr(offset)??????? \
-?????? ((void *)sbi_scratch_thishart_ptr() + (offset)) +?????? (void *)((char *)sbi_scratch_thishart_ptr() + (offset))

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +0 -0
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void?

__sbi_fifo_enqueue(struct
sbi_fifo *fifo, void *data)
??????? if (head >= fifo->num_entries) ??????????????? head = head - fifo->num_entries;

-?????? sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-

Quoted 1 line

entry_size);

+?????? sbi_memcpy((char *)fifo->queue + head * fifo-

Quoted 1 line

entry_size,

data, fifo->entry_size);

??????? fifo->avail++;
}

lib/sbi/sbi_fifo.c +0 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct
 sbi_fifo *fifo,
 void *in,
 ??????????????? index = fifo->tail + i;
 ??????????????? if (index >= fifo->num_entries)
 ??????????????????????? index -= fifo->num_entries;
-?????????????? entry = (void *)fifo->queue + (u32)index *

fifo-

Quoted 1 line

entry_size;

+?????????????? entry = (char *)fifo->queue + (u32)index * fifo-

Quoted 1 line

entry_size;

??????????????? ret = fptr(in, entry);

??????????????? if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {

lib/sbi/sbi_fifo.c +1 -1
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo
 *fifo, void
 *data)
 ??????????????? return SBI_ENOENT;
 ??????? }
 
-?????? sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-
 > entry_size,
+?????? sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail

* fifo-

Quoted 1 line

entry_size,

?????????????? fifo->entry_size);

??????? fifo->avail--;

lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void
 *src,
 size_t count)
 ??????????????????????? count--;
 ??????????????? }
 ??????? } else {
-?????????????? temp1 = dest + count - 1;
-?????????????? temp2 = src + count - 1;
+?????????????? temp1 = (char *)dest + count - 1;
+?????????????? temp2 = (char *)src + count - 1;
 

??????????????? while (count > 0) { ??????????????????????? *temp1-- = *temp2--;

lib/utils/i2c/fdt_i2c_sifive.c +0 -0
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;

static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
???????????????????????????????????? uint8_t reg, uint8_t value)
{
-?????? writel(value, (volatile void *)adap->addr + reg); +?????? writel(value, (volatile char *)adap->addr + reg); }

static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter
*adap,
??????????????????????????????????????? uint8_t reg) {
-?????? return readl((volatile void *)adap->addr + reg); +?????? return readl((volatile char *)adap->addr + reg); }

static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void
 *fdt, int
 nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-?????? writel_relaxed(BIT(0), (void *)pd->addr +
 THEAD_PLIC_CTRL_REG);
+?????? writel_relaxed(BIT(0), (char *)pd->addr +

THEAD_PLIC_CTRL_REG);
}

static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +0 -0
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 

static void plic_set_priority(struct plic_data *plic, u32 source, u32
val)
{
-?????? volatile void *plic_priority = (void *)plic->addr + +?????? volatile void *plic_priority = (char *)plic->addr + ??????????????????????? PLIC_PRIORITY_BASE + 4 * source; ??????? writel(val, plic_priority);
}

lib/utils/irqchip/plic.c +1 -1
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data
 *plic, u32
 cntxid, u32 val)
 ??????? if (!plic)
 ??????????????? return;
 
-?????? plic_thresh = (void *)plic->addr +
+?????? plic_thresh = (char *)plic->addr +

????????????????????? PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE *
cntxid;
??????? writel(val, plic_thresh);
}

void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index,
u32 val)
{
-?????? volatile void *plic_ie;
+?????? volatile char *plic_ie;

??????? if (!plic)
??????????????? return;

-?????? plic_ie = (void *)plic->addr +
+?????? plic_ie = (char *)plic->addr + ?????????????????? PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
??????? writel(val, plic_ie + word_index * 4);
}

lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG?????????????????? 0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt,

int
nodeoff,
??????? if (rc < 0 || !reg_addr)
??????????????? return SBI_ENODEV;

-?????? sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+?????? sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;

??????? sbi_system_reset_add_device(&sunxi_wdt_reset);

lib/utils/reset/fdt_reset_thead.c +0 -0
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,

???????????????????????????????? const struct fdt_match *match)
{
-?????? void *p;
+?????? char *p;
??????? const fdt64_t *val;
??????? const fdt32_t *val_w;
??????? int len, i;

lib/utils/reset/fdt_reset_thead.c +0 -0
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int
 nodeoff,

??????? /* Custom reset method for secondary harts */ ??????? val = fdt_getprop(fdt, nodeoff, "entry-reg", &len); ??????? if (len > 0 && val) {
-?????????????? p = (void *)(ulong)fdt64_to_cpu(*val); +?????????????? p = (char *)fdt64_to_cpu(*val);

??????????????? val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
??????????????? if (len > 0 && val_w) {

lib/utils/serial/gaisler-uart.c +1 -1
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base,

u32
in_freq, u32 baudrate)
{
??????? u32 ctrl;

-?????? uart_base = (volatile void *)base; +?????? uart_base = (volatile char *)base;

??????? /* Configure baudrate */
??????? if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +1 -1
@@ -21,7 +21,7 @@
 #define UART_TX_FULL? 0x2
 #define UART_RX_FULL? 0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device
 shakti_console = {
 

int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
{
-?????? uart_base = (volatile void *)base; +?????? uart_base = (volatile char *)base; ??????? u16 baud = (u16)(in_freq/(16 * baudrate)); ??????? writew(baud, uart_base + REG_BAUD);

lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +1 -1
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device
 sifive_console = {
 

int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
{
-?????? uart_base???? = (volatile void *)base; +?????? uart_base???? = (volatile char *)base; ??????? uart_in_freq? = in_freq;
??????? uart_baudrate = baudrate;

lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32
 in_freq,
 u32 baudrate, u32 reg_shift,
 {
 ??????? u16 bdiv;
 
-?????? uart8250_base????? = (volatile void *)base;
+?????? uart8250_base????? = (volatile char *)base;
 ??????? uart8250_reg_shift = reg_shift;

??????? uart8250_reg_width = reg_width; ??????? uart8250_in_freq?? = in_freq;

lib/utils/timer/aclint_mtimer.c +0 -0
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64
 *addr)

static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64
*addr)
{
??????? writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr)); -?????? writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+?????? writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
??????? writel_relaxed((u32)value, (void *)(addr)); }

Signature · 1 line
2.25.1
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

In reply to Jukka Laitinen

I think I missed the decision on this patch, was it approved or rejected, or was there still modifications requested?

Thanks,

Jukka

#7 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

In reply to Jessica Clarke

? 2022-01-13???? 16:07 +0000?Jessica Clarke???

Quoted 25 lines · Xiang W
Quoted 8 lines

? 2022-01-13???? 14:55 +0200?Jukka Laitinen???

Quoted 6 lines

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [- Werror=pointer-
arith]"

Quoted 6 lines
Quoted 3 lines

Avoid these by calculating on "char *" where 1-byte data size is assumed.

char has a specific meaning, such modification is not conducive to code
reading.

This is extremely idiomatic, you see it everywhere in systems code.

Quoted 6 lines

I suggest adding an inline function

inline void * ptr_with_offset(void *p, unsigned long off) {
??? return (void *)((uintptr_t)p + off);
}

Quoted 5 lines

This only serves to complicate, and using uintptr_t when you don?t need
to is bad practice. Plus your version won?t work with volatile and/or const qualified pointers without warning if the relevant warnings are enabled.

Yes, the type conversion when passing parameters does report a warning. We can turn it into a macro so there are no warnings. In addition, sizeof(void*) should be equal to sizeof(uintptr_t) on common platforms, so it is appropriate to convert the pointer to uintptr_t for calculation

Regards?
Xiang W

Quoted 371 lines

Jess

Quoted 366 lines

Regards,
Xiang W

Quoted 357 lines

---

?include/sbi/sbi_scratch.h???????????? | 4 ++--
?lib/sbi/sbi_fifo.c??????????????????? | 6 +++---
?lib/sbi/sbi_string.c????????????????? | 4 ++--
?lib/utils/i2c/fdt_i2c_sifive.c??????? | 4 ++--
?lib/utils/irqchip/fdt_irqchip_plic.c? | 2 +-
?lib/utils/irqchip/plic.c????????????? | 8 ++++----
?lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
?lib/utils/reset/fdt_reset_thead.c???? | 4 ++--
?lib/utils/serial/gaisler-uart.c?????? | 4 ++--
?lib/utils/serial/shakti-uart.c??????? | 4 ++--
?lib/utils/serial/sifive-uart.c??????? | 4 ++--
?lib/utils/serial/uart8250.c?????????? | 4 ++--
?lib/utils/timer/aclint_mtimer.c?????? | 2 +-

?13 files changed, 27 insertions(+), 27 deletions(-)

include/sbi/sbi_scratch.h +0 -0
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long

sbi_scratch_alloc_offset(unsigned
long size);
?void sbi_scratch_free_offset(unsigned long offset); ?
?/** Get pointer from offset in sbi_scratch */ -#define sbi_scratch_offset_ptr(scratch, offset)??????? ((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)??????? (void *)((char
*)(scratch) + (offset))
?
?/** Get pointer from offset in sbi_scratch for current HART */ ?#define sbi_scratch_thishart_offset_ptr(offset)??????? \
-?????? ((void *)sbi_scratch_thishart_ptr() + (offset)) +?????? (void *)((char *)sbi_scratch_thishart_ptr() + (offset)) ?
?/** HART id to scratch table */
?extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +0 -0
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void? __sbi_fifo_enqueue(struct
 sbi_fifo *fifo, void *data)
 ??????? if (head >= fifo->num_entries)
 ??????????????? head = head - fifo->num_entries;

?
-?????? sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo-

Quoted 1 line

entry_size);

+?????? sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
?
??????? fifo->avail++;
?}

lib/sbi/sbi_fifo.c +1 -1
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo
 *fifo,
 void *in,
 ??????????????? index = fifo->tail + i;
 ??????????????? if (index >= fifo->num_entries)
 ??????????????????????? index -= fifo->num_entries;
-?????????????? entry = (void *)fifo->queue + (u32)index * fifo-
 > entry_size;
+?????????????? entry = (char *)fifo->queue + (u32)index * fifo-
Quoted 1 line

entry_size;

??????????????? ret = fptr(in, entry);
?
??????????????? if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {

lib/sbi/sbi_fifo.c +0 -0
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo,

void
*data)
??????????????? return SBI_ENOENT;
??????? }
?
-?????? sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo-

Quoted 1 line

entry_size,

+?????? sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo-

Quoted 1 line

entry_size,

?????????????? fifo->entry_size);
?
??????? fifo->avail--;

lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src,
 size_t count)
 ??????????????????????? count--;
 ??????????????? }
 ??????? } else {
-?????????????? temp1 = dest + count - 1;
-?????????????? temp2 = src + count - 1;
+?????????????? temp1 = (char *)dest + count - 1;
+?????????????? temp2 = (char *)src + count - 1;

?
??????????????? while (count > 0) {
??????????????????????? *temp1-- = *temp2--;

lib/utils/i2c/fdt_i2c_sifive.c +0 -0
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter
 fdt_i2c_adapter_sifive;

?static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
???????????????????????????????????? uint8_t reg, uint8_t value) ?{
-?????? writel(value, (volatile void *)adap->addr + reg); +?????? writel(value, (volatile char *)adap->addr + reg); ?}
?
?static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
??????????????????????????????????????? uint8_t reg)
?{
-?????? return readl((volatile void *)adap->addr + reg); +?????? return readl((volatile char *)adap->addr + reg); ?}
?
?static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)

lib/utils/irqchip/fdt_irqchip_plic.c +0 -0
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt,

int
nodeoff,
?
?static void thead_plic_plat_init(struct plic_data *pd) ?{
-?????? writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+?????? writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG);
?}
?
?static const struct fdt_match irqchip_plic_match[] = {

lib/utils/irqchip/plic.c +0 -0
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@

?
?static void plic_set_priority(struct plic_data *plic, u32 source, u32
val)
?{
-?????? volatile void *plic_priority = (void *)plic->addr + +?????? volatile void *plic_priority = (char *)plic->addr + ??????????????????????? PLIC_PRIORITY_BASE + 4 * source; ??????? writel(val, plic_priority);
?}

lib/utils/irqchip/plic.c +0 -0
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic,

u32
cntxid, u32 val)
??????? if (!plic)
??????????????? return;
?
-?????? plic_thresh = (void *)plic->addr +
+?????? plic_thresh = (char *)plic->addr + ????????????????????? PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
??????? writel(val, plic_thresh);
?}
?
?void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index,
u32 val)
?{
-?????? volatile void *plic_ie;
+?????? volatile char *plic_ie;
?
??????? if (!plic)
??????????????? return;
?
-?????? plic_ie = (void *)plic->addr +
+?????? plic_ie = (char *)plic->addr + ?????????????????? PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid; ??????? writel(val, plic_ie + word_index * 4);
?}

lib/utils/reset/fdt_reset_sunxi_wdt.c +0 -0
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@

?
?#define WDT_MODE_REG?????????????????? 0x18
?

lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;

?
?static int sunxi_wdt_system_reset_check(u32 type, u32 reason) ?{

lib/utils/reset/fdt_reset_sunxi_wdt.c +0 -0
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int
 nodeoff,
 ??????? if (rc < 0 || !reg_addr)
 ??????????????? return SBI_ENODEV;

?
-?????? sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr; +?????? sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr; ?
??????? sbi_system_reset_add_device(&sunxi_wdt_reset); ?

lib/utils/reset/fdt_reset_thead.c +1 -1
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 ?static int thead_reset_init(void *fdt, int nodeoff,
 ???????????????????????????????? const struct fdt_match *match)
 ?{
-?????? void *p;
+?????? char *p;
 ??????? const fdt64_t *val;
 ??????? const fdt32_t *val_w;
 ??????? int len, i;
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int
 nodeoff,

??????? /* Custom reset method for secondary harts */ ??????? val = fdt_getprop(fdt, nodeoff, "entry-reg", &len); ??????? if (len > 0 && val) {
-?????????????? p = (void *)(ulong)fdt64_to_cpu(*val); +?????????????? p = (char *)fdt64_to_cpu(*val);
?
??????????????? val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
??????????????? if (len > 0 && val_w) {

lib/utils/serial/gaisler-uart.c +0 -0
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@

?
?/* clang-format on */
?

lib/utils/serial/gaisler-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?
?static u32 get_reg(u32 num)
?{

lib/utils/serial/gaisler-uart.c +0 -0
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32
 in_freq, u32 baudrate)
 ?{
 ??????? u32 ctrl;

?
-?????? uart_base = (volatile void *)base;
+?????? uart_base = (volatile char *)base;
?
??????? /* Configure baudrate */
??????? if (in_freq)

lib/utils/serial/shakti- renamed from lib/utils/serial/shakti-uart.c +0 -0

uart.c
index e77a985..5f2fe75 100644

lib/utils/serial/shakti-uart.c +0 -0
@@ -21,7 +21,7 @@

?#define UART_TX_FULL? 0x2
?#define UART_RX_FULL? 0x8
?

lib/utils/serial/shakti-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?
?static void shakti_uart_putc(char ch)
?{

lib/utils/serial/shakti-uart.c +0 -0
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console
 = {

?
?int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
?{
-?????? uart_base = (volatile void *)base; +?????? uart_base = (volatile char *)base; ??????? u16 baud = (u16)(in_freq/(16 * baudrate)); ??????? writew(baud, uart_base + REG_BAUD);
?

lib/utils/serial/sifive- renamed from lib/utils/serial/sifive-uart.c +0 -0

uart.c
index 57d80fa..9478a77 100644

lib/utils/serial/sifive-uart.c +0 -0
@@ -29,7 +29,7 @@

?
?/* clang-format on */
?

lib/utils/serial/sifive-uart.c +1 -1
-static volatile void *uart_base;
+static volatile char *uart_base;

?static u32 uart_in_freq;
?static u32 uart_baudrate;
?

lib/utils/serial/sifive-uart.c +0 -0
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console
 = {

?
?int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
?{
-?????? uart_base???? = (volatile void *)base; +?????? uart_base???? = (volatile char *)base; ??????? uart_in_freq? = in_freq;
??????? uart_baudrate = baudrate;
?

lib/utils/serial/uart8250.c +0 -0
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@

?
?/* clang-format on */
?

lib/utils/serial/uart8250.c +1 -1
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;

?static u32 uart8250_in_freq;
?static u32 uart8250_baudrate;
?static u32 uart8250_reg_width;

lib/utils/serial/uart8250.c +0 -0
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32
 in_freq,
 u32 baudrate, u32 reg_shift,
 ?{
 ??????? u16 bdiv;

?
-?????? uart8250_base????? = (volatile void *)base; +?????? uart8250_base????? = (volatile char *)base; ??????? uart8250_reg_shift = reg_shift; ??????? uart8250_reg_width = reg_width; ??????? uart8250_in_freq?? = in_freq;

lib/utils/timer/aclint_mtimer.c +0 -0
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)

?static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64
*addr)
?{
??????? writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr)); -?????? writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04); +?????? writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04); ??????? writel_relaxed((u32)value, (void *)(addr));
?}
?

Signature · 1 line
2.25.1
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
#8 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

In reply to Jukka Laitinen
Quoted 199 lines · Jukka Laitinen jukka.laitinen at iki.fi

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]"

Avoid these by calculating on "char *" where 1-byte data size is assumed.

---

include/sbi/sbi_scratch.h             | 4 ++--
lib/sbi/sbi_fifo.c                    | 6 +++---
lib/sbi/sbi_string.c                  | 4 ++--
lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
lib/utils/irqchip/plic.c              | 8 ++++----
lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
lib/utils/reset/fdt_reset_thead.c     | 4 ++--
lib/utils/serial/gaisler-uart.c       | 4 ++--
lib/utils/serial/shakti-uart.c        | 4 ++--
lib/utils/serial/sifive-uart.c        | 4 ++--
lib/utils/serial/uart8250.c           | 4 ++--
lib/utils/timer/aclint_mtimer.c       | 2 +-
13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned long
 size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)	((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)	(void *)((char *)(scratch) +
 (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)	\
-	((void *)sbi_scratch_thishart_ptr() + (offset))
+	(void *)((char *)sbi_scratch_thishart_ptr() + (offset))
 

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +1 -1
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct sbi_fifo *fifo,
 void *data)
 	if (head >= fifo->num_entries)
 		head = head - fifo->num_entries;
 
-	sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
+	sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data,
 fifo->entry_size);
 
	fifo->avail++;
}
lib/sbi/sbi_fifo.c +2 -2
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
 		index = fifo->tail + i;
 		if (index >= fifo->num_entries)
 			index -= fifo->num_entries;
-		entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
+		entry = (char *)fifo->queue + (u32)index * fifo->entry_size;
 		ret = fptr(in, entry);
 
 		if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
 		return SBI_ENOENT;
 	}
 
-	sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size,
+	sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size,
 	       fifo->entry_size);
 
 	fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src, size_t count)
 			count--;
 		}
 	} else {
-		temp1 = dest + count - 1;
-		temp2 = src + count - 1;
+		temp1 = (char *)dest + count - 1;
+		temp2 = (char *)src + count - 1;
 
 		while (count > 0) {
 			*temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +2 -2
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
 				     uint8_t reg, uint8_t value)
 {
-	writel(value, (volatile void *)adap->addr + reg);
+	writel(value, (volatile char *)adap->addr + reg);
 }
 
 static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
 					uint8_t reg)
 {
-	return readl((volatile void *)adap->addr + reg);
+	return readl((volatile char *)adap->addr + reg);
 }
 
 static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)
lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-	writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+	writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG);
 }
 
 static const struct fdt_match irqchip_plic_match[] = {
lib/utils/irqchip/plic.c +4 -4
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 
 static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
 {
-	volatile void *plic_priority = (void *)plic->addr +
+	volatile void *plic_priority = (char *)plic->addr +
 			PLIC_PRIORITY_BASE + 4 * source;
 	writel(val, plic_priority);
 }
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32 cntxid, u32
 val)
 	if (!plic)
 		return;
 
-	plic_thresh = (void *)plic->addr +
+	plic_thresh = (char *)plic->addr +
 		      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
 	writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val)
 {
-	volatile void *plic_ie;
+	volatile char *plic_ie;
 
 	if (!plic)
 		return;
 
-	plic_ie = (void *)plic->addr +
+	plic_ie = (char *)plic->addr +
 		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
 	writel(val, plic_ie + word_index * 4);

}

lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG			0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int nodeoff,
 	if (rc < 0 || !reg_addr)
 		return SBI_ENODEV;
 
-	sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+	sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
 	sbi_system_reset_add_device(&sunxi_wdt_reset);
 
lib/utils/reset/fdt_reset_thead.c +1 -1
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
 				 const struct fdt_match *match)
 {
-	void *p;
+	char *p;
 	const fdt64_t *val;
 	const fdt32_t *val_w;
 	int len, i;

lib/utils/reset/fdt_reset_thead.c static int thead_reset_init(void *fdt, int nodeoff, · line 94

Quoted 5 lines
lib/utils/reset/fdt_reset_thead.c +1 -1
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
 	/* Custom reset method for secondary harts */
 	val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
 	if (len > 0 && val) {
-		p = (void *)(ulong)fdt64_to_cpu(*val);
+		p = (char *)fdt64_to_cpu(*val);

The ulong must be kept for RV32.

Regards,
Dong

Quoted 114 lines
lib/utils/reset/fdt_reset_thead.c +0 -0
 		val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
 		if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32 in_freq, u32
 baudrate)
 {
 	u32 ctrl;
 
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 
 	/* Configure baudrate */

if (in_freq)

lib/utils/serial/shakti-uart.c +2 -2
index e77a985..5f2fe75 100644
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 	u16 baud = (u16)(in_freq/(16 * baudrate));
 	writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive-uart.c +2 -2
index 57d80fa..9478a77 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base     = (volatile void *)base;
+	uart_base     = (volatile char *)base;
 	uart_in_freq  = in_freq;
 	uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32
 baudrate, u32 reg_shift,
 {
 	u16 bdiv;
 
-	uart8250_base      = (volatile void *)base;
+	uart8250_base      = (volatile char *)base;
 	uart8250_reg_shift = reg_shift;
 	uart8250_reg_width = reg_width;
	uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +1 -2
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)
 static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)
 {
 	writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
-	writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+	writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
 	writel_relaxed((u32)value, (void *)(addr));
 }
 
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#9 lore raw

PATCH v4 1/1 lib: fix pointer of type 'void *' used in arithmetic

Quoted 209 lines · Dong Du
Quoted 199 lines · Jukka Laitinen jukka.laitinen at iki.fi

Using "void *" in arithmetic causes errors with strict compiler settings:
"error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]"

Avoid these by calculating on "char *" where 1-byte data size is assumed.

---

include/sbi/sbi_scratch.h             | 4 ++--
lib/sbi/sbi_fifo.c                    | 6 +++---
lib/sbi/sbi_string.c                  | 4 ++--
lib/utils/i2c/fdt_i2c_sifive.c        | 4 ++--
lib/utils/irqchip/fdt_irqchip_plic.c  | 2 +-
lib/utils/irqchip/plic.c              | 8 ++++----
lib/utils/reset/fdt_reset_sunxi_wdt.c | 4 ++--
lib/utils/reset/fdt_reset_thead.c     | 4 ++--
lib/utils/serial/gaisler-uart.c       | 4 ++--
lib/utils/serial/shakti-uart.c        | 4 ++--
lib/utils/serial/sifive-uart.c        | 4 ++--
lib/utils/serial/uart8250.c           | 4 ++--
lib/utils/timer/aclint_mtimer.c       | 2 +-
13 files changed, 27 insertions(+), 27 deletions(-)
include/sbi/sbi_scratch.h +2 -2
index 186a40c..0c27307 100644
@@ -104,11 +104,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned long
 size);
 void sbi_scratch_free_offset(unsigned long offset);
 
 /** Get pointer from offset in sbi_scratch */
-#define sbi_scratch_offset_ptr(scratch, offset)	((void *)scratch + (offset))
+#define sbi_scratch_offset_ptr(scratch, offset)	(void *)((char *)(scratch) +
 (offset))
 
 /** Get pointer from offset in sbi_scratch for current HART */
 #define sbi_scratch_thishart_offset_ptr(offset)	\
-	((void *)sbi_scratch_thishart_ptr() + (offset))
+	(void *)((char *)sbi_scratch_thishart_ptr() + (offset))
 

/** HART id to scratch table */
extern struct sbi_scratch *hartid_to_scratch_table[];

lib/sbi/sbi_fifo.c +1 -1
index 589cc18..68d6039 100644
@@ -66,7 +66,7 @@ static inline void  __sbi_fifo_enqueue(struct sbi_fifo *fifo,
 void *data)
 	if (head >= fifo->num_entries)
 		head = head - fifo->num_entries;
 
-	sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
+	sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data,
 fifo->entry_size);
 
	fifo->avail++;
}
lib/sbi/sbi_fifo.c +2 -2
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
 		index = fifo->tail + i;
 		if (index >= fifo->num_entries)
 			index -= fifo->num_entries;
-		entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
+		entry = (char *)fifo->queue + (u32)index * fifo->entry_size;
 		ret = fptr(in, entry);
 
 		if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
 		return SBI_ENOENT;
 	}
 
-	sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size,
+	sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size,
 	       fifo->entry_size);
 
 	fifo->avail--;
lib/sbi/sbi_string.c +2 -2
index c87bce9..c163f31 100644
@@ -149,8 +149,8 @@ void *sbi_memmove(void *dest, const void *src, size_t count)
 			count--;
 		}
 	} else {
-		temp1 = dest + count - 1;
-		temp2 = src + count - 1;
+		temp1 = (char *)dest + count - 1;
+		temp2 = (char *)src + count - 1;
 
 		while (count > 0) {
 			*temp1-- = *temp2--;
lib/utils/i2c/fdt_i2c_sifive.c +2 -2
index 871241a..195541c 100644
@@ -56,13 +56,13 @@ extern struct fdt_i2c_adapter fdt_i2c_adapter_sifive;
 static inline void sifive_i2c_setreg(struct sifive_i2c_adapter *adap,
 				     uint8_t reg, uint8_t value)
 {
-	writel(value, (volatile void *)adap->addr + reg);
+	writel(value, (volatile char *)adap->addr + reg);
 }
 
 static inline uint8_t sifive_i2c_getreg(struct sifive_i2c_adapter *adap,
 					uint8_t reg)
 {
-	return readl((volatile void *)adap->addr + reg);
+	return readl((volatile char *)adap->addr + reg);
 }
 
 static int sifive_i2c_adapter_rxack(struct sifive_i2c_adapter *adap)
lib/utils/irqchip/fdt_irqchip_plic.c +1 -1
index 8d375be..b2d2a1b 100644
@@ -116,7 +116,7 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
 
 static void thead_plic_plat_init(struct plic_data *pd)
 {
-	writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+	writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG);
 }
 
 static const struct fdt_match irqchip_plic_match[] = {
lib/utils/irqchip/plic.c +4 -4
index 7665c62..0f58f3e 100644
@@ -23,7 +23,7 @@
 
 static void plic_set_priority(struct plic_data *plic, u32 source, u32 val)
 {
-	volatile void *plic_priority = (void *)plic->addr +
+	volatile void *plic_priority = (char *)plic->addr +
 			PLIC_PRIORITY_BASE + 4 * source;
 	writel(val, plic_priority);
 }
@@ -35,19 +35,19 @@ void plic_set_thresh(struct plic_data *plic, u32 cntxid, u32
 val)
 	if (!plic)
 		return;
 
-	plic_thresh = (void *)plic->addr +
+	plic_thresh = (char *)plic->addr +
 		      PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
 	writel(val, plic_thresh);
 }
 
 void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val)
 {
-	volatile void *plic_ie;
+	volatile char *plic_ie;
 
 	if (!plic)
 		return;
 
-	plic_ie = (void *)plic->addr +
+	plic_ie = (char *)plic->addr +
 		   PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
 	writel(val, plic_ie + word_index * 4);

}

lib/utils/reset/fdt_reset_sunxi_wdt.c +2 -2
index 6d1b5b7..446d32b 100644
@@ -19,7 +19,7 @@
 
 #define WDT_MODE_REG			0x18
 
-static volatile void *sunxi_wdt_base;
+static volatile char *sunxi_wdt_base;
 
 static int sunxi_wdt_system_reset_check(u32 type, u32 reason)
 {
@@ -59,7 +59,7 @@ static int sunxi_wdt_reset_init(void *fdt, int nodeoff,
 	if (rc < 0 || !reg_addr)
 		return SBI_ENODEV;
 
-	sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
+	sunxi_wdt_base = (volatile char *)(unsigned long)reg_addr;
 
 	sbi_system_reset_add_device(&sunxi_wdt_reset);
 
lib/utils/reset/fdt_reset_thead.c +1 -1
index d491687..def4997 100644
@@ -59,7 +59,7 @@ extern void __thead_pre_start_warm(void);
 static int thead_reset_init(void *fdt, int nodeoff,
 				 const struct fdt_match *match)
 {
-	void *p;
+	char *p;
 	const fdt64_t *val;
 	const fdt32_t *val_w;
 	int len, i;

lib/utils/reset/fdt_reset_thead.c static int thead_reset_init(void *fdt, int nodeoff, · line 94

Quoted 5 lines
lib/utils/reset/fdt_reset_thead.c +1 -1
@@ -91,7 +91,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
 	/* Custom reset method for secondary harts */
 	val = fdt_getprop(fdt, nodeoff, "entry-reg", &len);
 	if (len > 0 && val) {
-		p = (void *)(ulong)fdt64_to_cpu(*val);
+		p = (char *)fdt64_to_cpu(*val);

The ulong must be kept for RV32.

Quoted 2 lines

Regards,
Dong

Thanks for pointing this out, sent the patchset v5, which fixes only this.

Quoted 113 lines
Quoted 113 lines
lib/utils/reset/fdt_reset_thead.c +0 -0
 		val_w = fdt_getprop(fdt, nodeoff, "entry-cnt", &len);
 		if (len > 0 && val_w) {
lib/utils/serial/gaisler-uart.c +2 -2
index 49298e9..5f30ee4 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static u32 get_reg(u32 num)
 {
@@ -67,7 +67,7 @@ int gaisler_uart_init(unsigned long base, u32 in_freq, u32
 baudrate)
 {
 	u32 ctrl;
 
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 
 	/* Configure baudrate */

if (in_freq)

lib/utils/serial/shakti-uart.c +2 -2
index e77a985..5f2fe75 100644
@@ -21,7 +21,7 @@
 #define UART_TX_FULL  0x2
 #define UART_RX_FULL  0x8
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 
 static void shakti_uart_putc(char ch)
 {
@@ -46,7 +46,7 @@ static struct sbi_console_device shakti_console = {
 
 int shakti_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base = (volatile void *)base;
+	uart_base = (volatile char *)base;
 	u16 baud = (u16)(in_freq/(16 * baudrate));
 	writew(baud, uart_base + REG_BAUD);
 
lib/utils/serial/sifive-uart.c +2 -2
index 57d80fa..9478a77 100644
@@ -29,7 +29,7 @@
 
 /* clang-format on */
 
-static volatile void *uart_base;
+static volatile char *uart_base;
 static u32 uart_in_freq;
 static u32 uart_baudrate;
 
@@ -90,7 +90,7 @@ static struct sbi_console_device sifive_console = {
 
 int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 {
-	uart_base     = (volatile void *)base;
+	uart_base     = (volatile char *)base;
 	uart_in_freq  = in_freq;
 	uart_baudrate = baudrate;
 
lib/utils/serial/uart8250.c +2 -2
index 1cf6624..142f8dc 100644
@@ -39,7 +39,7 @@
 
 /* clang-format on */
 
-static volatile void *uart8250_base;
+static volatile char *uart8250_base;
 static u32 uart8250_in_freq;
 static u32 uart8250_baudrate;
 static u32 uart8250_reg_width;
@@ -95,7 +95,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32
 baudrate, u32 reg_shift,
 {
 	u16 bdiv;
 
-	uart8250_base      = (volatile void *)base;
+	uart8250_base      = (volatile char *)base;
 	uart8250_reg_shift = reg_shift;
 	uart8250_reg_width = reg_width;
	uart8250_in_freq   = in_freq;
lib/utils/timer/aclint_mtimer.c +1 -2
index 62e87f7..2532b63 100644
@@ -47,7 +47,7 @@ static u64 mtimer_time_rd32(volatile u64 *addr)
 static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr)
 {
 	writel_relaxed((timecmp) ? -1U : 0U, (void *)(addr));
-	writel_relaxed((u32)(value >> 32), (void *)(addr) + 0x04);
+	writel_relaxed((u32)(value >> 32), (char *)(addr) + 0x04);
 	writel_relaxed((u32)value, (void *)(addr));
 }
 
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi