[PATCH 3/6] read-cis: fix type-punning pointers

Wolfram Sang w.sang at pengutronix.de
Sun Jan 30 05:05:26 EST 2011


Use the proper type instead of int. Fixes:

 src/read-cis.c:62: warning: dereferencing type-punned pointer will break strict-aliasing rules
 src/read-cis.c:62: warning: dereferencing type-punned pointer will break strict-aliasing rules
 src/read-cis.c:85: warning: dereferencing type-punned pointer will break strict-aliasing rules
 src/read-cis.c:87: warning: dereferencing type-punned pointer will break strict-aliasing rules
[...]

Reported-by: Alexander Mansurov <alexander.mansurov at gmail.com>
Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
---
 src/cistpl.h   |   16 ++++++++--------
 src/read-cis.c |   20 ++++++++++----------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/cistpl.h b/src/cistpl.h
index 8b833ab..79dd0a2 100644
--- a/src/cistpl.h
+++ b/src/cistpl.h
@@ -552,10 +552,17 @@ typedef union cisparse_t {
     cistpl_format_t		format;
 } cisparse_t;
 
+typedef struct tuple_flags {
+    unsigned int               link_space:4;
+    unsigned int               has_link:1;
+    unsigned int               mfc_fn:3;
+    unsigned int               space:4;
+} tuple_flags;
+
 typedef struct tuple_t {
     unsigned int	Attributes;
     unsigned char 	DesiredTuple;
-    unsigned int	Flags;		/* internal use */
+    tuple_flags		Flags;		/* internal use */
     unsigned int	LinkOffset;	/* internal use */
     unsigned int	CISOffset;	/* internal use */
     unsigned char	TupleCode;
@@ -586,13 +593,6 @@ typedef struct cisdump_t {
     unsigned char	Data[CISTPL_MAX_CIS_SIZE];
 } cisdump_t;
 
-typedef struct tuple_flags {
-    unsigned int               link_space:4;
-    unsigned int               has_link:1;
-    unsigned int               mfc_fn:3;
-    unsigned int               space:4;
-} tuple_flags;
-
 #define BIND_FN_ALL        0xff
 
 int read_out_cis (unsigned int socket_no, FILE *fd);
diff --git a/src/read-cis.c b/src/read-cis.c
index 43cc1cc..7c51825 100644
--- a/src/read-cis.c
+++ b/src/read-cis.c
@@ -36,10 +36,10 @@ static unsigned char cis_copy[MAX_TUPLES];
 static unsigned int cis_length = MAX_TUPLES;
 
 
-#define SPACE(f)       (((tuple_flags *)(&(f)))->space)
-#define HAS_LINK(f)    (((tuple_flags *)(&(f)))->has_link)
-#define LINK_SPACE(f)  (((tuple_flags *)(&(f)))->link_space)
-#define MFC_FN(f)      (((tuple_flags *)(&(f)))->mfc_fn)
+#define SPACE(f)       ((f).space)
+#define HAS_LINK(f)    ((f).has_link)
+#define LINK_SPACE(f)  ((f).link_space)
+#define MFC_FN(f)      ((f).mfc_fn)
 
 
 static void read_cis(int attr, unsigned int addr, unsigned int len, void *ptr)
@@ -55,12 +55,12 @@ int pcmcia_get_next_tuple(unsigned int function, tuple_t *tuple);
 
 int pcmcia_get_first_tuple(unsigned int function, tuple_t *tuple)
 {
-	tuple->TupleLink = tuple->Flags = 0;
-	{
-		/* Assume presence of a LONGLINK_C to address 0 */
-		tuple->CISOffset = tuple->LinkOffset = 0;
-		SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
-	}
+	tuple->TupleLink = 0;
+	LINK_SPACE(tuple->Flags) = MFC_FN(tuple->Flags) = 0;
+	/* Assume presence of a LONGLINK_C to address 0 */
+	tuple->CISOffset = tuple->LinkOffset = 0;
+	SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
+
 	if ((functions > 1) &&
 	    !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
 		unsigned char req = tuple->DesiredTuple;
-- 
1.7.2.3




More information about the linux-pcmcia mailing list