diff mbox series

lib: fwts_coreboot_cbmem: don't use void * pointer arithmetic

Message ID 20181113123928.16491-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_coreboot_cbmem: don't use void * pointer arithmetic | expand

Commit Message

Colin Ian King Nov. 13, 2018, 12:39 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

void * pointer arithmetic is a GCC'ism and the behaviour is undefined,
so use char * pointer arithmetic instead. Cleans up clang warnings.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_coreboot_cbmem.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Alex Hung Nov. 13, 2018, 12:52 p.m. UTC | #1
On 2018-11-13 8:39 p.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> void * pointer arithmetic is a GCC'ism and the behaviour is undefined,
> so use char * pointer arithmetic instead. Cleans up clang warnings.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_coreboot_cbmem.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
> index 53e57136..e02c523c 100644
> --- a/src/lib/src/fwts_coreboot_cbmem.c
> +++ b/src/lib/src/fwts_coreboot_cbmem.c
> @@ -144,11 +144,11 @@ static int parse_cbtable_entries(
>  	off_t *cbmem_console_addr)
>  {
>  	size_t i;
> -	const struct lb_record* lbr_p;
>  	int forwarding_table_found = 0;
> +	const struct lb_record *lbr_p;
>  
>  	for (i = 0; i < table_size; i += lbr_p->size) {
> -		lbr_p = lbtable + i;
> +		lbr_p = (struct lb_record*)((char *)lbtable + i);
>  		switch (lbr_p->tag) {
>  		case LB_TAG_CBMEM_CONSOLE: {
>  			*cbmem_console_addr = (off_t)parse_cbmem_ref((const struct lb_cbmem_ref *) lbr_p).cbmem_addr;
> @@ -205,11 +205,9 @@ static int parse_cbtable(
>  	/* look at every 16 bytes */
>  	for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) {
>  		int ret;
> -		const struct lb_header *lbh;
> +		const struct lb_header *lbh = (struct lb_header *)((char *)buf + i);
>  		void *map;
>  
> -		lbh = buf + i;
> -
>  		if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
>  		    !lbh->header_bytes ||
>  		    ipchcksum(lbh, sizeof(*lbh))) {
> @@ -262,7 +260,7 @@ static ssize_t memory_read_from_buffer(
>  	if (count > available - pos)
>  		count = available - pos;
>  
> -	memcpy(to, from + pos, count);
> +	memcpy(to, (char *)from + pos, count);
>  
>  	*ppos = pos + count;
>  
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Nov. 14, 2018, 2:22 a.m. UTC | #2
On 11/13/18 8:39 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> void * pointer arithmetic is a GCC'ism and the behaviour is undefined,
> so use char * pointer arithmetic instead. Cleans up clang warnings.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_coreboot_cbmem.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
> index 53e57136..e02c523c 100644
> --- a/src/lib/src/fwts_coreboot_cbmem.c
> +++ b/src/lib/src/fwts_coreboot_cbmem.c
> @@ -144,11 +144,11 @@ static int parse_cbtable_entries(
>  	off_t *cbmem_console_addr)
>  {
>  	size_t i;
> -	const struct lb_record* lbr_p;
>  	int forwarding_table_found = 0;
> +	const struct lb_record *lbr_p;
>  
>  	for (i = 0; i < table_size; i += lbr_p->size) {
> -		lbr_p = lbtable + i;
> +		lbr_p = (struct lb_record*)((char *)lbtable + i);
>  		switch (lbr_p->tag) {
>  		case LB_TAG_CBMEM_CONSOLE: {
>  			*cbmem_console_addr = (off_t)parse_cbmem_ref((const struct lb_cbmem_ref *) lbr_p).cbmem_addr;
> @@ -205,11 +205,9 @@ static int parse_cbtable(
>  	/* look at every 16 bytes */
>  	for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) {
>  		int ret;
> -		const struct lb_header *lbh;
> +		const struct lb_header *lbh = (struct lb_header *)((char *)buf + i);
>  		void *map;
>  
> -		lbh = buf + i;
> -
>  		if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
>  		    !lbh->header_bytes ||
>  		    ipchcksum(lbh, sizeof(*lbh))) {
> @@ -262,7 +260,7 @@ static ssize_t memory_read_from_buffer(
>  	if (count > available - pos)
>  		count = available - pos;
>  
> -	memcpy(to, from + pos, count);
> +	memcpy(to, (char *)from + pos, count);
>  
>  	*ppos = pos + count;
>  

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
index 53e57136..e02c523c 100644
--- a/src/lib/src/fwts_coreboot_cbmem.c
+++ b/src/lib/src/fwts_coreboot_cbmem.c
@@ -144,11 +144,11 @@  static int parse_cbtable_entries(
 	off_t *cbmem_console_addr)
 {
 	size_t i;
-	const struct lb_record* lbr_p;
 	int forwarding_table_found = 0;
+	const struct lb_record *lbr_p;
 
 	for (i = 0; i < table_size; i += lbr_p->size) {
-		lbr_p = lbtable + i;
+		lbr_p = (struct lb_record*)((char *)lbtable + i);
 		switch (lbr_p->tag) {
 		case LB_TAG_CBMEM_CONSOLE: {
 			*cbmem_console_addr = (off_t)parse_cbmem_ref((const struct lb_cbmem_ref *) lbr_p).cbmem_addr;
@@ -205,11 +205,9 @@  static int parse_cbtable(
 	/* look at every 16 bytes */
 	for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) {
 		int ret;
-		const struct lb_header *lbh;
+		const struct lb_header *lbh = (struct lb_header *)((char *)buf + i);
 		void *map;
 
-		lbh = buf + i;
-
 		if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
 		    !lbh->header_bytes ||
 		    ipchcksum(lbh, sizeof(*lbh))) {
@@ -262,7 +260,7 @@  static ssize_t memory_read_from_buffer(
 	if (count > available - pos)
 		count = available - pos;
 
-	memcpy(to, from + pos, count);
+	memcpy(to, (char *)from + pos, count);
 
 	*ppos = pos + count;