Skip to contentSkip to conversation

ATA: Squash warnings in mxc_ata.

PATCH Superseded Marek Vasut 2 participants 6 messages Sep 23, 2011 – Sep 25, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ATA: Squash warnings in mxc_ata.

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---
 drivers/block/mxc_ata.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/block/mxc_ata.c +7 -3
index f22f4f4..d94ec9c 100644
@@ -98,6 +98,7 @@ static void set_ata_bus_timing(unsigned char mode)
 {
 	uint32_t val;
 	uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
+	uint32_t reg;
 
 	struct mxc_ata_config_regs *ata_regs;
 	ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
@@ -106,22 +107,25 @@ static void set_ata_bus_timing(unsigned char mode)
 		return;
 
 	/* Write TIME_OFF/ON/1/2W */
+	reg = (uint32_t)&ata_regs->time_off;
 	val =	(3 << REG2OFF(&ata_regs->time_off)) |
 		(3 << REG2OFF(&ata_regs->time_on)) |
 		(((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
 		(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
-	writel(val, &ata_regs->time_off);
+	writel(val, reg);
 
 	/* Write TIME_2R/AX/RDX/4 */
+	reg = (uint32_t)&ata_regs->time_2r;
 	val =	(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2r)) |
 		(((pio_tA[mode] + T) / T + 2) << REG2OFF(&ata_regs->time_ax)) |
 		(1 << REG2OFF(&ata_regs->time_pio_rdx)) |
 		(((pio_t4[mode] + T) / T) << REG2OFF(&ata_regs->time_4));
-	writel(val, &ata_regs->time_2r);
+	writel(val, reg);
 
 	/* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
+	reg = (uint32_t)&ata_regs->time_9;
 	val =	(((pio_t9[mode] + T) / T) << REG2OFF(&ata_regs->time_9));
-	writel(val, &ata_regs->time_9);
+	writel(val, reg);
 }
 
 int ide_preinit(void)
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/1 ATA: Squash warnings in mxc_ata.

On 09/23/2011 11:12 AM, Marek Vasut wrote:

Hi Marek,

Quoted 27 lines

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---
 drivers/block/mxc_ata.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/block/mxc_ata.c +1 -0
index f22f4f4..d94ec9c 100644
@@ -98,6 +98,7 @@ static void set_ata_bus_timing(unsigned char mode)
 {
 	uint32_t val;
 	uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
+	uint32_t reg;
 
 	struct mxc_ata_config_regs *ata_regs;
 	ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;

drivers/block/mxc_ata.c static void set_ata_bus_timing(unsigned char mode) · line 110

Quoted 4 lines
drivers/block/mxc_ata.c +1 -0
@@ -106,22 +107,25 @@ static void set_ata_bus_timing(unsigned char mode)
 		return;
 
 	/* Write TIME_OFF/ON/1/2W */
+	reg = (uint32_t)&ata_regs->time_off;

You drop the warnings using casting, but is it correct ? time_off is defined as u8 (correctly, because this is the size of the register). If you write 32bit, you risk to overwrite the time_on, time_1 and time_2w registers.
Why do not use writeb ?

drivers/block/mxc_ata.c static void set_ata_bus_timing(unsigned char mode) · line 115

Quoted 6 lines
drivers/block/mxc_ata.c +1 -1
 	val =	(3 << REG2OFF(&ata_regs->time_off)) |
 		(3 << REG2OFF(&ata_regs->time_on)) |
 		(((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
 		(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
-	writel(val, &ata_regs->time_off);
+	writel(val, reg);

Understood. You *want* to write all registers in one shot. However this is hackish. Or you write each register separetely, or you use a union to access the register block with a 32 bit access. Everybody reading "writel(val, &ata_regs->time_off)" expects that time_off is 32bit wide.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#2 lore raw

PATCH v2 1/1 ATA: Squash warnings in mxc_ata.

In reply to Marek Vasut

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---
 drivers/block/mxc_ata.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

V2: Use writeb() access

drivers/block/mxc_ata.c +9 -13
index f22f4f4..b05e3c9 100644
@@ -96,7 +96,6 @@ static uint16_t pio_tA[NR_PIO_SPECS]	= { 50,  50,  50,  50,  50 };
 #define	REG2OFF(reg)	((((uint32_t)reg) & 0x3) * 8)
 static void set_ata_bus_timing(unsigned char mode)
 {
-	uint32_t val;
 	uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
 
 	struct mxc_ata_config_regs *ata_regs;
@@ -106,22 +105,19 @@ static void set_ata_bus_timing(unsigned char mode)
 		return;
 
 	/* Write TIME_OFF/ON/1/2W */
-	val =	(3 << REG2OFF(&ata_regs->time_off)) |
-		(3 << REG2OFF(&ata_regs->time_on)) |
-		(((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
-		(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
-	writel(val, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_off);
+	writeb((pio_t1[mode] + T) / T, &ata_regs->time_1);
+	writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2w);
 
 	/* Write TIME_2R/AX/RDX/4 */
-	val =	(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2r)) |
-		(((pio_tA[mode] + T) / T + 2) << REG2OFF(&ata_regs->time_ax)) |
-		(1 << REG2OFF(&ata_regs->time_pio_rdx)) |
-		(((pio_t4[mode] + T) / T) << REG2OFF(&ata_regs->time_4));
-	writel(val, &ata_regs->time_2r);
+	writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2r);
+	writeb((pio_tA[mode] + T) / T + 2, &ata_regs->time_ax);
+	writeb(1, &ata_regs->time_pio_rdx);
+	writeb((pio_t4[mode] + T) / T, &ata_regs->time_4);
 
 	/* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
-	val =	(((pio_t9[mode] + T) / T) << REG2OFF(&ata_regs->time_9));
-	writel(val, &ata_regs->time_9);
+	writeb((pio_t9[mode] + T) / T, &ata_regs->time_9);
 }
 
 int ide_preinit(void)
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH v2 1/1 ATA: Squash warnings in mxc_ata.

Quoted 29 lines · Marek Vasut

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---
 drivers/block/mxc_ata.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

V2: Use writeb() access

drivers/block/mxc_ata.c +0 -1
index f22f4f4..b05e3c9 100644
@@ -96,7 +96,6 @@ static uint16_t pio_tA[NR_PIO_SPECS]	= { 50,  50,  50,  50,  50 };
 #define	REG2OFF(reg)	((((uint32_t)reg) & 0x3) * 8)
 static void set_ata_bus_timing(unsigned char mode)
 {
-	uint32_t val;
 	uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
 
 	struct mxc_ata_config_regs *ata_regs;

drivers/block/mxc_ata.c static void set_ata_bus_timing(unsigned char mode) · line 109

Quoted 10 lines
drivers/block/mxc_ata.c +2 -5
@@ -106,22 +105,19 @@ static void set_ata_bus_timing(unsigned char mode)
 		return;
 
 	/* Write TIME_OFF/ON/1/2W */
-	val =	(3 << REG2OFF(&ata_regs->time_off)) |
-		(3 << REG2OFF(&ata_regs->time_on)) |
-		(((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
-		(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
-	writel(val, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_off);
                                   ^----- should be time_on

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#4 lore raw

PATCH v3 1/1 ATA: Squash warnings in mxc_ata.

In reply to Marek Vasut

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---
 drivers/block/mxc_ata.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

V2: Use writeb() access
V3: Fix time_on

drivers/block/mxc_ata.c +9 -13
index f22f4f4..35bc656 100644
@@ -96,7 +96,6 @@ static uint16_t pio_tA[NR_PIO_SPECS]	= { 50,  50,  50,  50,  50 };
 #define	REG2OFF(reg)	((((uint32_t)reg) & 0x3) * 8)
 static void set_ata_bus_timing(unsigned char mode)
 {
-	uint32_t val;
 	uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
 
 	struct mxc_ata_config_regs *ata_regs;
@@ -106,22 +105,19 @@ static void set_ata_bus_timing(unsigned char mode)
 		return;
 
 	/* Write TIME_OFF/ON/1/2W */
-	val =	(3 << REG2OFF(&ata_regs->time_off)) |
-		(3 << REG2OFF(&ata_regs->time_on)) |
-		(((pio_t1[mode] + T) / T) << REG2OFF(&ata_regs->time_1)) |
-		(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2w));
-	writel(val, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_off);
+	writeb(3, &ata_regs->time_on);
+	writeb((pio_t1[mode] + T) / T, &ata_regs->time_1);
+	writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2w);
 
 	/* Write TIME_2R/AX/RDX/4 */
-	val =	(((pio_t2_8[mode] + T) / T) << REG2OFF(&ata_regs->time_2r)) |
-		(((pio_tA[mode] + T) / T + 2) << REG2OFF(&ata_regs->time_ax)) |
-		(1 << REG2OFF(&ata_regs->time_pio_rdx)) |
-		(((pio_t4[mode] + T) / T) << REG2OFF(&ata_regs->time_4));
-	writel(val, &ata_regs->time_2r);
+	writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2r);
+	writeb((pio_tA[mode] + T) / T + 2, &ata_regs->time_ax);
+	writeb(1, &ata_regs->time_pio_rdx);
+	writeb((pio_t4[mode] + T) / T, &ata_regs->time_4);
 
 	/* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
-	val =	(((pio_t9[mode] + T) / T) << REG2OFF(&ata_regs->time_9));
-	writel(val, &ata_regs->time_9);
+	writeb((pio_t9[mode] + T) / T, &ata_regs->time_9);
 }
 
 int ide_preinit(void)
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH v3 1/1 ATA: Squash warnings in mxc_ata.

Quoted 11 lines · Marek Vasut

mxc_ata.c: In function ?set_ata_bus_timing?:
mxc_ata.c:118: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:125: warning: dereferencing type-punned pointer will break strict-aliasing rules
mxc_ata.c:129: warning: dereferencing type-punned pointer will break strict-aliasing rules

---

Applied to u-boot-imx, next branch, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================