Skip to content

Commit

Permalink
lib: Remove warnings from -Wcast-align
Browse files Browse the repository at this point in the history
There were several places in the library where a char* was used to point
to a wider type (uint32_t or a struct). Casting the char* to the wider
type resulted in a compiler warning.

This commit changes some simple casts to (void *) to silence compiler
warnings. In rsc_table_parser.c, replace casts and pointer arithmetic
with explicit uses of fw_rsc_hdr.

Signed-off-by: Ed Mooring <ed.mooring@gmail.com>
  • Loading branch information
edmooring authored and arnopo committed May 24, 2022
1 parent e5988ab commit 0107a28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/proxy/rpmsg_retarget.c
Expand Up @@ -178,7 +178,7 @@ int _open(const char *filename, int flags, int mode)
return -EINVAL;

/* Construct rpc payload */
syscall = (struct rpmsg_rpc_syscall *)tmpbuf;
syscall = (void *)tmpbuf;
syscall->id = OPEN_SYSCALL_ID;
syscall->args.int_field1 = flags;
syscall->args.int_field2 = mode;
Expand Down Expand Up @@ -228,7 +228,7 @@ int _read(int fd, char *buffer, int buflen)
syscall.args.int_field2 = buflen;
syscall.args.data_len = 0; /*not used */

resp = (struct rpmsg_rpc_syscall *)tmpbuf;
resp = (void *)tmpbuf;
resp->id = 0;
ret = rpmsg_rpc_send(rpc, (void *)&syscall, payload_size,
tmpbuf, sizeof(tmpbuf));
Expand Down Expand Up @@ -281,7 +281,7 @@ int _write(int fd, const char *ptr, int len)
if (fd == 1)
null_term = 1;

syscall = (struct rpmsg_rpc_syscall *)tmpbuf;
syscall = (void *)tmpbuf;
syscall->id = WRITE_SYSCALL_ID;
syscall->args.int_field1 = fd;
syscall->args.int_field2 = len;
Expand Down
24 changes: 10 additions & 14 deletions lib/remoteproc/rsc_table_parser.c
Expand Up @@ -23,8 +23,8 @@ int handle_rsc_table(struct remoteproc *rproc,
struct resource_table *rsc_table, size_t size,
struct metal_io_region *io)
{
char *rsc_start;
unsigned int rsc_type;
struct fw_rsc_hdr *hdr;
uint32_t rsc_type;
unsigned int idx, offset;
int status = 0;

Expand Down Expand Up @@ -55,18 +55,15 @@ int handle_rsc_table(struct remoteproc *rproc,

/* Loop through the offset array and parse each resource entry */
for (idx = 0; idx < rsc_table->num; idx++) {
rsc_start = (char *)rsc_table;
rsc_start += rsc_table->offset[idx];
if (io &&
metal_io_virt_to_offset(io, rsc_start) == METAL_BAD_OFFSET)
hdr = (void *)((char *)rsc_table + rsc_table->offset[idx]);
if (io && metal_io_virt_to_offset(io, hdr) == METAL_BAD_OFFSET)
return -RPROC_ERR_RSC_TAB_TRUNC;
rsc_type = *((uint32_t *)rsc_start);
rsc_type = hdr->type;
if (rsc_type < RSC_LAST)
status = rsc_handler_table[rsc_type](rproc,
rsc_start);
status = rsc_handler_table[rsc_type](rproc, hdr);
else if (rsc_type >= RSC_VENDOR_START &&
rsc_type <= RSC_VENDOR_END)
status = handle_vendor_rsc(rproc, rsc_start);
status = handle_vendor_rsc(rproc, hdr);
if (status == -RPROC_ERR_RSC_TAB_NS) {
status = 0;
continue;
Expand Down Expand Up @@ -199,17 +196,16 @@ static int handle_dummy_rsc(struct remoteproc *rproc, void *rsc)
size_t find_rsc(void *rsc_table, unsigned int rsc_type, unsigned int index)
{
struct resource_table *r_table = rsc_table;
struct fw_rsc_hdr *hdr;
unsigned int i, rsc_index;
unsigned int lrsc_type;
char *rsc_start;

metal_assert(r_table);
/* Loop through the offset array and parse each resource entry */
rsc_index = 0;
for (i = 0; i < r_table->num; i++) {
rsc_start = (char *)r_table;
rsc_start += r_table->offset[i];
lrsc_type = *((uint32_t *)rsc_start);
hdr = (void *)((char *)r_table + r_table->offset[i]);
lrsc_type = hdr->type;
if (lrsc_type == rsc_type) {
if (rsc_index++ == index)
return r_table->offset[i];
Expand Down

0 comments on commit 0107a28

Please sign in to comment.