Skip to contentSkip to conversation

caif: fix a signedness bug in cfpkt_iterate()

PATCH Applied Dan Carpenter 3 participants 5 messages Feb 19, 2015 – Feb 20, 2015

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

PATCH 1/1 caif: fix a signedness bug in cfpkt_iterate()

The cfpkt_iterate() function can return -EPROTO on error, but the function is a u16 so the negative value gets truncated to a positive unsigned short. This causes a static checker warning.

The only caller which might care is cffrml_receive(), when it's checking the frame checksum. I modified cffrml_receive() so that it never says -EPROTO is a valid checksum.

Also this isn't ever going to be inlined so I removed the "inline".

include/net/caif/cfpkt.h +1 -1
index 1c1ad46..fe328c5 100644
@@ -171,7 +171,7 @@ struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos);
  * @return    Checksum of buffer.
  */
 
-u16 cfpkt_iterate(struct cfpkt *pkt,
+int cfpkt_iterate(struct cfpkt *pkt,
 		u16 (*iter_func)(u16 chks, void *buf, u16 len),
 		u16 data);
 
net/caif/cfpkt_skbuff.c +3 -3
index 1be0b52..f6c3b21 100644
@@ -255,9 +255,9 @@ inline u16 cfpkt_getlen(struct cfpkt *pkt)
 	return skb->len;
 }
 
-inline u16 cfpkt_iterate(struct cfpkt *pkt,
-			 u16 (*iter_func)(u16, void *, u16),
-			 u16 data)
+int cfpkt_iterate(struct cfpkt *pkt,
+		  u16 (*iter_func)(u16, void *, u16),
+		  u16 data)
 {
 	/*
 	 * Don't care about the performance hit of linearizing,
net/caif/cffrml.c +1 -1
index 8bc7caa..434ba85 100644
@@ -84,7 +84,7 @@ static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt)
 	u16 tmp;
 	u16 len;
 	u16 hdrchks;
-	u16 pktchks;
+	int pktchks;
 	struct cffrml *this;
 	this = container_obj(layr);
 
#1 lore raw

From: Dan Carpenter
...

Quoted 1 line

Also this isn't ever going to be inlined so I removed the "inline".

...

net/caif/cfpkt_skbuff.c inline u16 cfpkt_getlen(struct cfpkt *pkt) · line 260

Quoted 3 lines
net/caif/cfpkt_skbuff.c +0 -3
-inline u16 cfpkt_iterate(struct cfpkt *pkt,
-			 u16 (*iter_func)(u16, void *, u16),
-			 u16 data)

static ??

net/caif/cfpkt_skbuff.c inline u16 cfpkt_getlen(struct cfpkt *pkt) · line 260

Quoted 3 lines
net/caif/cfpkt_skbuff.c +3 -0
+int cfpkt_iterate(struct cfpkt *pkt,
+		  u16 (*iter_func)(u16, void *, u16),
+		  u16 data)

David

#2 lore raw
Quoted 9 lines · David Laight

From: Dan Carpenter
...

Quoted 1 line

Also this isn't ever going to be inlined so I removed the "inline".

...

net/caif/cfpkt_skbuff.c inline u16 cfpkt_getlen(struct cfpkt *pkt) · line 260

Quoted 3 lines
net/caif/cfpkt_skbuff.c +0 -3
-inline u16 cfpkt_iterate(struct cfpkt *pkt,
-			 u16 (*iter_func)(u16, void *, u16),
-			 u16 data)

static ??

There are some words missing in this sentence.

We could move this function to the header file and make it static inline if we wanted but checksums aren't used on the fast path anyway so that's a bit pointless.

regards,
dan carpenter

#3 lore raw

From: Dan Carpenter

Quoted 12 lines · David Laight
Quoted 9 lines

From: Dan Carpenter
...

Quoted 1 line

Also this isn't ever going to be inlined so I removed the "inline".

...

net/caif/cfpkt_skbuff.c inline u16 cfpkt_getlen(struct cfpkt *pkt) · line 260

Quoted 3 lines
net/caif/cfpkt_skbuff.c +0 -3
-inline u16 cfpkt_iterate(struct cfpkt *pkt,
-			 u16 (*iter_func)(u16, void *, u16),
-			 u16 data)

static ??

There are some words missing in this sentence.

I should have drunk some coffee first.

David

maintainer Applied
#4 lore raw
In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Thu, 19 Feb 2015 12:13:13 +0300

Quoted 11 lines

The cfpkt_iterate() function can return -EPROTO on error, but the function is a u16 so the negative value gets truncated to a positive unsigned short. This causes a static checker warning.

The only caller which might care is cffrml_receive(), when it's checking the frame checksum. I modified cffrml_receive() so that it never says -EPROTO is a valid checksum.

Also this isn't ever going to be inlined so I removed the "inline".

Applied, thanks Dan.