[OpenBIOS] [PATCH 3/5] Fix gcc 4.4 warnings about strict aliasing
Pavel Roskin
proski at gnu.org
Sun May 17 02:16:26 CEST 2009
Rather than cast char arrays to other types, use correct types and cast
them to char pointers when needed.
---
drivers/fw_cfg.c | 18 +++++++++---------
modules/pc-parts.c | 18 +++++++++---------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/drivers/fw_cfg.c b/drivers/fw_cfg.c
index 0ca4a43..3c5e267 100644
--- a/drivers/fw_cfg.c
+++ b/drivers/fw_cfg.c
@@ -34,31 +34,31 @@ fw_cfg_read(uint16_t cmd, char *buf, unsigned int nbytes)
uint64_t
fw_cfg_read_i64(uint16_t cmd)
{
- char buf[sizeof(uint64_t)];
+ uint64_t buf;
- fw_cfg_read(cmd, buf, sizeof(uint64_t));
+ fw_cfg_read(cmd, (char *)&buf, sizeof(uint64_t));
- return __le64_to_cpu(*(uint64_t *)buf);
+ return __le64_to_cpu(buf);
}
uint32_t
fw_cfg_read_i32(uint16_t cmd)
{
- char buf[sizeof(uint32_t)];
+ uint32_t buf;
- fw_cfg_read(cmd, buf, sizeof(uint32_t));
+ fw_cfg_read(cmd, (char *)&buf, sizeof(uint32_t));
- return __le32_to_cpu(*(uint32_t *)buf);
+ return __le32_to_cpu(buf);
}
uint16_t
fw_cfg_read_i16(uint16_t cmd)
{
- char buf[sizeof(uint16_t)];
+ uint16_t buf;
- fw_cfg_read(cmd, buf, sizeof(uint16_t));
+ fw_cfg_read(cmd, (char *)&buf, sizeof(uint16_t));
- return __le16_to_cpu(*(uint16_t *)buf);
+ return __le16_to_cpu(buf);
}
void
diff --git a/modules/pc-parts.c b/modules/pc-parts.c
index 3cececb..bc3109a 100644
--- a/modules/pc-parts.c
+++ b/modules/pc-parts.c
@@ -58,8 +58,8 @@ pcparts_open( pcparts_info_t *di )
unsigned char e_head;
unsigned char e_sector;
unsigned char e_cyl;
- unsigned char start_sect[4]; /* unaligned little endian */
- unsigned char nr_sects[4]; /* ditto */
+ u32 start_sect; /* unaligned little endian */
+ u32 nr_sects; /* ditto */
} *p;
unsigned char buf[512];
@@ -96,11 +96,11 @@ pcparts_open( pcparts_info_t *di )
printk("partition %d does not exist\n", parnum+1 );
RET( 0 );
}
- di->offs = (llong)(__le32_to_cpu(*((u32 *)p->start_sect))) * bs;
- di->size = (llong)(__le32_to_cpu(*((u32 *)p->nr_sects))) * bs;
+ di->offs = (llong)(__le32_to_cpu(p->start_sect)) * bs;
+ di->size = (llong)(__le32_to_cpu(p->nr_sects)) * bs;
/* printk("Primary partition at sector %x\n",
- __le32_to_cpu(*((u32 *)p->start_sect))); */
+ __le32_to_cpu(p->start_sect)); */
RET( -1 );
} else {
@@ -123,7 +123,7 @@ pcparts_open( pcparts_info_t *di )
printk("Extended partition at %d\n", i+1);
/* Visit each logical partition labels */
- ext_start = __le32_to_cpu(*((u32 *)p[i].start_sect));
+ ext_start = __le32_to_cpu(p[i].start_sect);
cur_table = ext_start;
cur_part = 4;
@@ -147,8 +147,8 @@ pcparts_open( pcparts_info_t *di )
RET( 0 );
}
di->offs =
- (llong)(cur_table+__le32_to_cpu(*((u32 *)p->start_sect))) * bs;
- di->size = (llong)__le32_to_cpu(*((u32 *)p->nr_sects)) * bs;
+ (llong)(cur_table+__le32_to_cpu(p->start_sect)) * bs;
+ di->size = (llong)__le32_to_cpu(p->nr_sects) * bs;
RET ( -1 );
}
@@ -157,7 +157,7 @@ pcparts_open( pcparts_info_t *di )
printk("no link\n");
break;
}
- cur_table = ext_start + __le32_to_cpu(*((u32 *)p[1].start_sect));
+ cur_table = ext_start + __le32_to_cpu(p[1].start_sect);
cur_part++;
}
More information about the OpenBIOS
mailing list