Skip to contentSkip to conversation

enic: cleanup vic_provinfo_alloc()

PATCH Applied Dan Carpenter 4 participants 5 messages Jun 10, 2010 – Jun 12, 2010

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

PATCH 1/1 enic: cleanup vic_provinfo_alloc()

If oui were a null variable then vic_provinfo_alloc() would leak memory. But this function is only called from one place and oui is not null so I removed the check.

I also moved the memory allocation down a line so it was easier to spot. (No one ever reads variable declarations).

drivers/net/enic/vnic_vic.c +3 -2
index d769772..0a35085 100644
@@ -25,9 +25,10 @@
 
 struct vic_provinfo *vic_provinfo_alloc(gfp_t flags, u8 *oui, u8 type)
 {
-	struct vic_provinfo *vp = kzalloc(VIC_PROVINFO_MAX_DATA, flags);
+	struct vic_provinfo *vp;
 
-	if (!vp || !oui)
+	vp = kzalloc(VIC_PROVINFO_MAX_DATA, flags);
+	if (!vp)
 		return NULL;
 
 	memcpy(vp->oui, oui, sizeof(vp->oui));
#1 lore raw
Quoted 17 lines · Dan Carpenter

If oui were a null variable then vic_provinfo_alloc() would leak memory. But this function is only called from one place and oui is not null so I removed the check.

I also moved the memory allocation down a line so it was easier to spot. (No one ever reads variable declarations).

drivers/net/enic/vnic_vic.c +0 -0
index d769772..0a35085 100644
@@ -25,9 +25,10 @@
 
 struct vic_provinfo *vic_provinfo_alloc(gfp_t flags, u8 *oui, u8 type)
 {

drivers/net/enic/vnic_vic.c

Quoted 10 lines
drivers/net/enic/vnic_vic.c +3 -3
-	struct vic_provinfo *vp = kzalloc(VIC_PROVINFO_MAX_DATA, flags);
+	struct vic_provinfo *vp;
 
-	if (!vp || !oui)
+	vp = kzalloc(VIC_PROVINFO_MAX_DATA, flags);
+	if (!vp)
 		return NULL;
 
 	memcpy(vp->oui, oui, sizeof(vp->oui));
--

This looks like memdup() ?

re,
wh

#2 lore raw
Quoted 10 lines · walter harms

drivers/net/enic/vnic_vic.c

Quoted 6 lines
drivers/net/enic/vnic_vic.c +2 -1
+	vp = kzalloc(VIC_PROVINFO_MAX_DATA, flags);
+	if (!vp)
 		return NULL;
 
 	memcpy(vp->oui, oui, sizeof(vp->oui));
--

This looks like memdup() ?

No. VIC_PROVINFO_MAX_DATA is larger than sizeof(vp->oui).

regards,
dan carpenter

Quoted 2 lines

re,
wh

#3 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

If oui were a null variable then vic_provinfo_alloc() would leak memory. But this function is only called from one place and oui is not null so I removed the check.

I also moved the memory allocation down a line so it was easier to spot. (No one ever reads variable declarations).

We'll pick this one up and resubmit with the next enic patch bomb. Thanks Dan.

-scott

maintainer Applied
#4 lore raw
In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Thu, 10 Jun 2010 09:59:03 +0200

Quoted 8 lines

If oui were a null variable then vic_provinfo_alloc() would leak memory. But this function is only called from one place and oui is not null so I removed the check.

I also moved the memory allocation down a line so it was easier to spot. (No one ever reads variable declarations).

Applied to net-next-2.6, thanks.