[U-Boot] [PATCH v2] board/linkstation/ide.c: Fix compile warning
Guennadi Liakhovetski
g.liakhovetski at gmx.de
Tue Sep 15 22:42:47 CEST 2009
On Tue, 15 Sep 2009, Wolfgang Denk wrote:
> Fix warning: ide.c:60: warning: dereferencing type-punned pointer will
> break strict-aliasing rules
>
> Signed-off-by: Wolfgang Denk <wd at denx.de>
> Cc: Guennadi Liakhovetski <lg at denx.de>
>
> ---
> v2: Better implementation as suggested by Scott Wood in
> http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/67840/focus=67891
>
> board/linkstation/ide.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/board/linkstation/ide.c b/board/linkstation/ide.c
> index 2c89d62..568fdf5 100644
> --- a/board/linkstation/ide.c
> +++ b/board/linkstation/ide.c
> @@ -54,11 +54,13 @@ int ide_preinit (void)
> if (devbusfn == -1)
> devbusfn = pci_find_device(PCI_VENDOR_ID_ITE,PCI_DEVICE_ID_ITE_8212,0);
> if (devbusfn != -1) {
> + u32 ide_bus_offset32;
> +
> status = 0;
>
> pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0,
> - (u32 *) &ide_bus_offset[0]);
> - ide_bus_offset[0] &= 0xfffffffe;
> + &ide_bus_offset32);
> + ide_bus_offset[0] = ide_bus_offset32 & 0xfffffffe;
> ide_bus_offset[0] = pci_hose_bus_to_phys(&hose,
> ide_bus_offset[0] & 0xfffffffe,
> PCI_REGION_IO);
Ok, yes, this looks much better now without casts, but - the double " &
0xfffffffe" above seems completely redundant to me. I understand, that
that's not the problem you're fixing with this patch, and I will perfectly
understand if you refuse to mix these two fixes, but... Another thing -
why doesn't the compiler complain about exactly identical cast (ok,
almost) a couple of lines down for ide_bus_offset[1]? So, how about this
diff instead (only compile-tested) (not for submission yet, so, no Sob's,
no patch header):
diff --git a/board/linkstation/ide.c b/board/linkstation/ide.c
index 2c89d62..f96af74 100644
--- a/board/linkstation/ide.c
+++ b/board/linkstation/ide.c
@@ -54,20 +54,23 @@ int ide_preinit (void)
if (devbusfn == -1)
devbusfn = pci_find_device(PCI_VENDOR_ID_ITE,PCI_DEVICE_ID_ITE_8212,0);
if (devbusfn != -1) {
+ u32 ide_bus_offset32;
+
status = 0;
- pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0,
- (u32 *) &ide_bus_offset[0]);
- ide_bus_offset[0] &= 0xfffffffe;
+ pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0,
+ &ide_bus_offset32);
+ ide_bus_offset[0] = ide_bus_offset32 & 0xfffffffe;
ide_bus_offset[0] = pci_hose_bus_to_phys(&hose,
- ide_bus_offset[0] & 0xfffffffe,
- PCI_REGION_IO);
- pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_2,
- (u32 *) &ide_bus_offset[1]);
- ide_bus_offset[1] &= 0xfffffffe;
- ide_bus_offset[1] = pci_hose_bus_to_phys(&hose,
- ide_bus_offset[1] & 0xfffffffe,
- PCI_REGION_IO);
+ ide_bus_offset[0], PCI_REGION_IO);
+
+ if (CONFIG_SYS_IDE_MAXBUS > 1) {
+ pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_2,
+ &ide_bus_offset32);
+ ide_bus_offset[1] = ide_bus_offset32 & 0xfffffffe;
+ ide_bus_offset[1] = pci_hose_bus_to_phys(&hose,
+ ide_bus_offset[1], PCI_REGION_IO);
+ }
}
if (pci_find_device (PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8212, 0) != -1) {
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
More information about the U-Boot
mailing list