Skip to contentSkip to conversation

Typecast problems in SKFP driver

PATCH NAK Loic Grenie 2 participants 3 messages Jul 17, 2008 Network drivers

lore
Share & tools
lore
#0 lore raw

I've just compiled the 2.6.26-git5 kernel and the SKFP driver compilation produces complaints about typecasts. These complaints disappear with the following patch.

Thanks,

Loïc Grenié

drivers/net/skfp/ess.c +3 -3
index 889f987..d3a8afc 100644
@@ -510,7 +510,7 @@ static void ess_send_response(struct s_smc *smc, struct smt_header *sm,
 	chg->path.para.p_type = SMT_P320B ;
 	chg->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
 	chg->path.mib_index = SBAPATHINDEX ;
-	chg->path.path_pad = (u_short)NULL ;
+	chg->path.path_pad = (u_short)(long)NULL ;
 	chg->path.path_index = PRIMARY_RING ;
 
 	/* set P320F */
@@ -606,7 +606,7 @@ static void ess_send_alc_req(struct s_smc *smc)
 	req->path.para.p_type = SMT_P320B ;
 	req->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
 	req->path.mib_index = SBAPATHINDEX ;
-	req->path.path_pad = (u_short)NULL ;
+	req->path.path_pad = (u_short)(long)NULL ;
 	req->path.path_index = PRIMARY_RING ;
 
 	/* set P0017 */
@@ -636,7 +636,7 @@ static void ess_send_alc_req(struct s_smc *smc)
 	/* set P19 */
 	req->a_addr.para.p_type = SMT_P0019 ;
 	req->a_addr.para.p_len = sizeof(struct smt_p_0019) - PARA_LEN ;
-	req->a_addr.sba_pad = (u_short)NULL ;
+	req->a_addr.sba_pad = (u_short)(long)NULL ;
 	req->a_addr.alloc_addr = null_addr ;
 
 	/* set P1A */
drivers/net/skfp/pmf.c +8 -8
index ea85de9..5798be4 100644
@@ -44,17 +44,17 @@ static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
 				     int set, int local);
 static int port_to_mib(struct s_smc *smc, int p);
 
-#define MOFFSS(e)	((int)&(((struct fddi_mib *)0)->e))
-#define MOFFSA(e)	((int) (((struct fddi_mib *)0)->e))
+#define MOFFSS(e)	((long)&(((struct fddi_mib *)0)->e))
+#define MOFFSA(e)	((long) (((struct fddi_mib *)0)->e))
 
-#define MOFFMS(e)	((int)&(((struct fddi_mib_m *)0)->e))
-#define MOFFMA(e)	((int) (((struct fddi_mib_m *)0)->e))
+#define MOFFMS(e)	((long)&(((struct fddi_mib_m *)0)->e))
+#define MOFFMA(e)	((long) (((struct fddi_mib_m *)0)->e))
 
-#define MOFFAS(e)	((int)&(((struct fddi_mib_a *)0)->e))
-#define MOFFAA(e)	((int) (((struct fddi_mib_a *)0)->e))
+#define MOFFAS(e)	((long)&(((struct fddi_mib_a *)0)->e))
+#define MOFFAA(e)	((long) (((struct fddi_mib_a *)0)->e))
 
-#define MOFFPS(e)	((int)&(((struct fddi_mib_p *)0)->e))
-#define MOFFPA(e)	((int) (((struct fddi_mib_p *)0)->e))
+#define MOFFPS(e)	((long)&(((struct fddi_mib_p *)0)->e))
+#define MOFFPA(e)	((long) (((struct fddi_mib_p *)0)->e))
 
 
 #define AC_G	0x01		/* Get */
#1 lore raw
Quoted 3 lines · Loic Grenie

I've just compiled the 2.6.26-git5 kernel and the SKFP driver compilation produces complaints about typecasts. These complaints disappear with the following patch.

NAK, this needs to be done by someone with better understanding of C.

Quoted 9 lines

Thanks,

Loïc Grenié

drivers/net/skfp/ess.c +0 -0
index 889f987..d3a8afc 100644

drivers/net/skfp/ess.c static void ess_send_response(struct s_smc *smc, struct smt_header *sm, · line 514

Quoted 6 lines
drivers/net/skfp/ess.c +1 -1
@@ -510,7 +510,7 @@ static void ess_send_response(struct s_smc *smc, struct smt_header *sm,
 	chg->path.para.p_type = SMT_P320B ;
 	chg->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
 	chg->path.mib_index = SBAPATHINDEX ;
-	chg->path.path_pad = (u_short)NULL ;
+	chg->path.path_pad = (u_short)(long)NULL ;
 	chg->path.path_index = PRIMARY_RING ;

Putting NULL (a pointer type) in an u_short field is utterly and completely broken. My guess is that the code really wants:

	chg->path.path_pad = 0;

drivers/net/skfp/ess.c static void ess_send_alc_req(struct s_smc *smc) · line 610

Quoted 8 lines
drivers/net/skfp/ess.c +1 -1
 	/* set P320F */
@@ -606,7 +606,7 @@ static void ess_send_alc_req(struct s_smc *smc)
 	req->path.para.p_type = SMT_P320B ;
 	req->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
 	req->path.mib_index = SBAPATHINDEX ;
-	req->path.path_pad = (u_short)NULL ;
+	req->path.path_pad = (u_short)(long)NULL ;
 	req->path.path_index = PRIMARY_RING ;

ditto

drivers/net/skfp/ess.c static void ess_send_alc_req(struct s_smc *smc) · line 640

Quoted 9 lines
drivers/net/skfp/ess.c +1 -1
 	/* set P0017 */
@@ -636,7 +636,7 @@ static void ess_send_alc_req(struct s_smc *smc)
 	/* set P19 */
 	req->a_addr.para.p_type = SMT_P0019 ;
 	req->a_addr.para.p_len = sizeof(struct smt_p_0019) - PARA_LEN ;
-	req->a_addr.sba_pad = (u_short)NULL ;
+	req->a_addr.sba_pad = (u_short)(long)NULL ;
 	req->a_addr.alloc_addr = null_addr ;

ditto

Quoted 7 lines
drivers/net/skfp/ess.c +0 -0
 	/* set P1A */
drivers/net/skfp/pmf.c +0 -0
index ea85de9..5798be4 100644

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 48

Quoted 7 lines
drivers/net/skfp/pmf.c +2 -2
@@ -44,17 +44,17 @@ static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
 				     int set, int local);
 static int port_to_mib(struct s_smc *smc, int p);
 
-#define MOFFSS(e)	((int)&(((struct fddi_mib *)0)->e))
-#define MOFFSA(e)	((int) (((struct fddi_mib *)0)->e))
+#define MOFFSS(e)	((long)&(((struct fddi_mib *)0)->e))
+#define MOFFSA(e)	((long) (((struct fddi_mib *)0)->e))

NAK, use offsetof().

How is the MOFFSA() used? As written it makes no sense at all as evaluating it as an r-value will oops.

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 51

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFMS(e)	((int)&(((struct fddi_mib_m *)0)->e))
-#define MOFFMA(e)	((int) (((struct fddi_mib_m *)0)->e))
+#define MOFFMS(e)	((long)&(((struct fddi_mib_m *)0)->e))
+#define MOFFMA(e)	((long) (((struct fddi_mib_m *)0)->e))

ditto

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 54

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFAS(e)	((int)&(((struct fddi_mib_a *)0)->e))
-#define MOFFAA(e)	((int) (((struct fddi_mib_a *)0)->e))
+#define MOFFAS(e)	((long)&(((struct fddi_mib_a *)0)->e))
+#define MOFFAA(e)	((long) (((struct fddi_mib_a *)0)->e))

ditto

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 57

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFPS(e)	((int)&(((struct fddi_mib_p *)0)->e))
-#define MOFFPA(e)	((int) (((struct fddi_mib_p *)0)->e))
+#define MOFFPS(e)	((long)&(((struct fddi_mib_p *)0)->e))
+#define MOFFPA(e)	((long) (((struct fddi_mib_p *)0)->e))

ditto

To be fair, the original code is crap, but your changes don't make it any better.

#2 lore raw

2008/7/17 Mikael Pettersson <[email protected]>:

Quoted 6 lines
Quoted 3 lines · Loic Grenie

I've just compiled the 2.6.26-git5 kernel and the SKFP driver compilation produces complaints about typecasts. These complaints disappear with the following patch.

NAK, this needs to be done by someone with better understanding of C.

or, better, by someone with a better understanding of the driver.

Quoted 19 lines
Quoted 9 lines

Thanks,

Loïc Grenié

drivers/net/skfp/ess.c +0 -0
index 889f987..d3a8afc 100644

drivers/net/skfp/ess.c static void ess_send_response(struct s_smc *smc, struct smt_header *sm, · line 514

Quoted 6 lines
drivers/net/skfp/ess.c +1 -1
@@ -510,7 +510,7 @@ static void ess_send_response(struct s_smc *smc, struct smt_header *sm,
     chg->path.para.p_type = SMT_P320B ;
     chg->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
     chg->path.mib_index = SBAPATHINDEX ;
-    chg->path.path_pad = (u_short)NULL ;
+    chg->path.path_pad = (u_short)(long)NULL ;
     chg->path.path_index = PRIMARY_RING ;

Putting NULL (a pointer type) in an u_short field is utterly and completely broken. My guess is that the code really wants:

Quoted 1 line
       chg->path.path_pad = 0;

Indeed. I do not even understand why it was done that way in the
first place.

Quoted 40 lines

drivers/net/skfp/ess.c static void ess_send_alc_req(struct s_smc *smc) · line 610

Quoted 8 lines
drivers/net/skfp/ess.c +1 -1
     /* set P320F */
@@ -606,7 +606,7 @@ static void ess_send_alc_req(struct s_smc *smc)
     req->path.para.p_type = SMT_P320B ;
     req->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
     req->path.mib_index = SBAPATHINDEX ;
-    req->path.path_pad = (u_short)NULL ;
+    req->path.path_pad = (u_short)(long)NULL ;
     req->path.path_index = PRIMARY_RING ;

ditto

drivers/net/skfp/ess.c static void ess_send_alc_req(struct s_smc *smc) · line 640

Quoted 9 lines
drivers/net/skfp/ess.c +1 -1
     /* set P0017 */
@@ -636,7 +636,7 @@ static void ess_send_alc_req(struct s_smc *smc)
     /* set P19 */
     req->a_addr.para.p_type = SMT_P0019 ;
     req->a_addr.para.p_len = sizeof(struct smt_p_0019) - PARA_LEN ;
-    req->a_addr.sba_pad = (u_short)NULL ;
+    req->a_addr.sba_pad = (u_short)(long)NULL ;
     req->a_addr.alloc_addr = null_addr ;

ditto

Quoted 7 lines
drivers/net/skfp/ess.c +0 -0
     /* set P1A */
drivers/net/skfp/pmf.c +0 -0
index ea85de9..5798be4 100644

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 48

Quoted 7 lines
drivers/net/skfp/pmf.c +2 -2
@@ -44,17 +44,17 @@ static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req,
                                  int set, int local);
 static int port_to_mib(struct s_smc *smc, int p);
 
-#define MOFFSS(e)   ((int)&(((struct fddi_mib *)0)->e))
-#define MOFFSA(e)   ((int) (((struct fddi_mib *)0)->e))
+#define MOFFSS(e)   ((long)&(((struct fddi_mib *)0)->e))
+#define MOFFSA(e)   ((long) (((struct fddi_mib *)0)->e))

NAK, use offsetof().

Quoted 2 lines

How is the MOFFSA() used? As written it makes no sense at all as evaluating it as an r-value will oops.

I think it is used when e is an array (unchecked).

Quoted 24 lines

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 51

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFMS(e)   ((int)&(((struct fddi_mib_m *)0)->e))
-#define MOFFMA(e)   ((int) (((struct fddi_mib_m *)0)->e))
+#define MOFFMS(e)   ((long)&(((struct fddi_mib_m *)0)->e))
+#define MOFFMA(e)   ((long) (((struct fddi_mib_m *)0)->e))

ditto

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 54

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFAS(e)   ((int)&(((struct fddi_mib_a *)0)->e))
-#define MOFFAA(e)   ((int) (((struct fddi_mib_a *)0)->e))
+#define MOFFAS(e)   ((long)&(((struct fddi_mib_a *)0)->e))
+#define MOFFAA(e)   ((long) (((struct fddi_mib_a *)0)->e))

ditto

drivers/net/skfp/pmf.c static SMbuf *smt_build_pmf_response(struct s_smc *smc, struct smt_header *req, · line 57

Quoted 5 lines
drivers/net/skfp/pmf.c +2 -2
-#define MOFFPS(e)   ((int)&(((struct fddi_mib_p *)0)->e))
-#define MOFFPA(e)   ((int) (((struct fddi_mib_p *)0)->e))
+#define MOFFPS(e)   ((long)&(((struct fddi_mib_p *)0)->e))
+#define MOFFPA(e)   ((long) (((struct fddi_mib_p *)0)->e))

ditto

Quoted 3 lines

To be fair, the original code is crap, but your changes don't make it any better.

I agree... Maybe someone with stronger guts than mine will have
read about it and will correct it for some next release.

Thanks once again,

Loïc