Skip to contentSkip to conversation

ebtables: clean up vmalloc usage in net/bridge/netfilter/ebtables.c

PATCH RESEND In review Jayachandran C 3 participants 6 messages Apr 19, 2006 – Apr 20, 2006

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

PATCH RESEND 1/1 ebtables: clean up vmalloc usage in net/bridge/netfilter/ebtables.c

Second try, added netdev to the cc: list this time.

This cleans up other usages of of vmalloc in ebtables.c. The changes are similar to the cleanup done in ebtables-fix-allocation-in-net-bridge-netfilter-ebtablesc.patch

Patch Description:

This patch makes all the vmalloc calls in net/bridge/netfilter/ebtables.c follow the standard convention. Remove unnecessary casts, and use '*object' instead of 'type'.

Signed-off-by Jayachandran C. <c.jayachandran at gmail.com>

---

 net/bridge/netfilter/ebtables.c |   20 +++++++-------------
 1 files changed, 7 insertions(+), 13 deletions(-)
net/bridge/netfilter/ebtables.c +7 -13
diff -ur linux-2.6.16-rc6.clean/net/bridge/netfilter/ebtables.c linux-2.6.16-rc6/net/bridge/netfilter/ebtables.c
@@ -830,7 +830,7 @@
 			return -ENOMEM;
 		for_each_cpu(i) {
 			newinfo->chainstack[i] =
-			   vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
+			  vmalloc(udc_cnt * sizeof(*(newinfo->chainstack[0])));
 			if (!newinfo->chainstack[i]) {
 				while (i)
 					vfree(newinfo->chainstack[--i]);
@@ -840,8 +840,7 @@
 			}
 		}
 
-		cl_s = (struct ebt_cl_stack *)
-		   vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
+		cl_s = vmalloc(udc_cnt * sizeof(*cl_s));
 		if (!cl_s)
 			return -ENOMEM;
 		i = 0; /* the i'th udc */
@@ -943,8 +942,7 @@
 
 	countersize = COUNTER_OFFSET(tmp.nentries) * 
 					(highest_possible_processor_id()+1);
-	newinfo = (struct ebt_table_info *)
-	   vmalloc(sizeof(struct ebt_table_info) + countersize);
+	newinfo = vmalloc(sizeof(*newinfo) + countersize);
 	if (!newinfo)
 		return -ENOMEM;
 
@@ -966,8 +964,7 @@
 	/* the user wants counters back
 	   the check on the size is done later, when we have the lock */
 	if (tmp.num_counters) {
-		counterstmp = (struct ebt_counter *)
-		   vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
+		counterstmp = vmalloc(tmp.num_counters * sizeof(*counterstmp));
 		if (!counterstmp) {
 			ret = -ENOMEM;
 			goto free_entries;
@@ -1147,8 +1144,7 @@
 
 	countersize = COUNTER_OFFSET(table->table->nentries) *
 					(highest_possible_processor_id()+1);
-	newinfo = (struct ebt_table_info *)
-	   vmalloc(sizeof(struct ebt_table_info) + countersize);
+	newinfo = vmalloc(sizeof(*newinfo) + countersize);
 	ret = -ENOMEM;
 	if (!newinfo)
 		return -ENOMEM;
@@ -1246,8 +1242,7 @@
 	if (hlp.num_counters == 0)
 		return -EINVAL;
 
-	if ( !(tmp = (struct ebt_counter *)
-	   vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
+	if ( !(tmp = vmalloc(hlp.num_counters * sizeof(*tmp))) ){
 		MEMPRINT("Update_counters && nomemory\n");
 		return -ENOMEM;
 	}
@@ -1376,8 +1371,7 @@
 			BUGPRINT("Num_counters wrong\n");
 			return -EINVAL;
 		}
-		counterstmp = (struct ebt_counter *)
-		   vmalloc(nentries * sizeof(struct ebt_counter));
+		counterstmp = vmalloc(nentries * sizeof(*counterstmp));
 		if (!counterstmp) {
 			MEMPRINT("Couldn't copy counters, out of memory\n");
 			return -ENOMEM;

----- End forwarded message -----

maintainer
#1 lore raw

An earlier variant of your patch was applied already, included below. You'll need to submit the newer parts relative to the current tree.

diff-tree 7ad4d2f6901437ba4717a26d395a73ea362d25c6 (from b8282dcf0417bbc8a0786c129fdff9cc768f8f3c)

Author: Jayachandran C <[email protected]>
Date:   Tue Apr 11 17:25:38 2006 -0700

[BRIDGE] ebtables: fix allocation in net/bridge/netfilter/ebtables.c

Allocate an array of 'struct ebt_chainstack *', the current code allocates array of 'struct ebt_chainstack'.

akpm: converted to use the

foo = alloc(sizeof(*foo))

form. Which would have prevented this from happening in the first place.

akpm: also removed unneeded typecast.

akpm: what on earth is this code doing anyway? cpu_possible_map can be sparse..

net/bridge/netfilter/ebtables.c +3 -3
index 66bd932..84b9af7 100644
@@ -824,9 +824,9 @@ static int translate_table(struct ebt_re
 	if (udc_cnt) {
 		/* this will get free'd in do_replace()/ebt_register_table()
 		   if an error occurs */
-		newinfo->chainstack = (struct ebt_chainstack **)
-		   vmalloc((highest_possible_processor_id()+1) 
-				   		* sizeof(struct ebt_chainstack));
+		newinfo->chainstack =
+			vmalloc((highest_possible_processor_id()+1)
+				   	* sizeof(*(newinfo->chainstack)));
 		if (!newinfo->chainstack)
 			return -ENOMEM;
 		for_each_possible_cpu(i) {
#2 lore raw
Quoted 3 lines · David S. Miller

An earlier variant of your patch was applied already, included below. You'll need to submit the newer parts relative to the current tree.

This is a similar-but-different patch. It applies OK.

I reviewed it (mostly - it's somewhat non-trivial to do this) and queued it up and was planning on sending it to you for post-2.6.17.

maintainer
#3 lore raw

From: Andrew Morton <[email protected]>
Date: Wed, 19 Apr 2006 15:59:25 -0700

Quoted 9 lines
Quoted 3 lines · David S. Miller

An earlier variant of your patch was applied already, included below. You'll need to submit the newer parts relative to the current tree.

This is a similar-but-different patch. It applies OK.

I reviewed it (mostly - it's somewhat non-trivial to do this) and queued it up and was planning on sending it to you for post-2.6.17.

It's at least fixing a few bugs, and the parts which are cleanups undoubtedly should prevent bugs in the future, so I think we should consider it for 2.6.17 right?

#4 lore raw
Quoted 9 lines · David S. Miller

From: Andrew Morton <[email protected]>
Date: Wed, 19 Apr 2006 15:59:25 -0700

Quoted 5 lines
Quoted 3 lines · David S. Miller

An earlier variant of your patch was applied already, included below. You'll need to submit the newer parts relative to the current tree.

Quoted 8 lines
Quoted 4 lines

This is a similar-but-different patch. It applies OK.

I reviewed it (mostly - it's somewhat non-trivial to do this) and queued it up and was planning on sending it to you for post-2.6.17.

It's at least fixing a few bugs, and the parts which are cleanups undoubtedly should prevent bugs in the future, so I think we should consider it for 2.6.17 right?

afaict it's just a cleanup, but whatever - I'll send it over now.

#5 lore raw
Quoted 12 lines · Andrew Morton
Quoted 11 lines · David S. Miller

From: Andrew Morton <[email protected]>
Date: Wed, 19 Apr 2006 15:59:25 -0700

Quoted 7 lines
Quoted 3 lines · David S. Miller

An earlier variant of your patch was applied already, included below. You'll need to submit the newer parts relative to the current tree.

This is a similar-but-different patch. It applies OK.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I reviewed it (mostly - it's somewhat non-trivial to do this) and queued it up and was planning on sending it to you for post-2.6.17.

It's at least fixing a few bugs, and the parts which are cleanups undoubtedly should prevent bugs in the future, so I think we should consider it for 2.6.17 right?

afaict it's just a cleanup, but whatever - I'll send it over now.

The first patch (which is already applied) was a bug fix. This one is just a clean up, it makes the same clean-up that Andrew did to the original patch, in other places in the same file.

This is not at all critical, so it can be moved post-2.6.17 without any problem.

Regards,
JC.