Browse Source

[AX25]: Use kmemdup

Code diff stats:

[acme@newtoy net-2.6.20]$ codiff /tmp/ax25.ko.before /tmp/ax25.ko.after
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ax25/ax25_out.c:
  ax25_send_frame |   -8
 1 function changed, 8 bytes removed

/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ax25/ax25_route.c:
  ax25_rt_autobind |  -15
 1 function changed, 15 bytes removed

/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ax25/af_ax25.c:
  ax25_make_new |  -33
 1 function changed, 33 bytes removed

/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ax25/sysctl_net_ax25.c:
  ax25_register_sysctl |  -21
 1 function changed, 21 bytes removed

/tmp/ax25.ko.after:
 4 functions changed, 77 bytes removed
[acme@newtoy net-2.6.20]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Arnaldo Carvalho de Melo 18 years ago
parent
commit
0459d70add
4 changed files with 11 additions and 9 deletions
  1. 3 3
      net/ax25/af_ax25.c
  2. 2 2
      net/ax25/ax25_out.c
  3. 3 2
      net/ax25/ax25_route.c
  4. 3 2
      net/ax25/sysctl_net_ax25.c

+ 3 - 3
net/ax25/af_ax25.c

@@ -906,13 +906,13 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
 	ax25->source_addr = oax25->source_addr;
 	ax25->source_addr = oax25->source_addr;
 
 
 	if (oax25->digipeat != NULL) {
 	if (oax25->digipeat != NULL) {
-		if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
+		ax25->digipeat = kmemdup(oax25->digipeat, sizeof(ax25_digi),
+					 GFP_ATOMIC);
+		if (ax25->digipeat == NULL) {
 			sk_free(sk);
 			sk_free(sk);
 			ax25_cb_put(ax25);
 			ax25_cb_put(ax25);
 			return NULL;
 			return NULL;
 		}
 		}
-
-		memcpy(ax25->digipeat, oax25->digipeat, sizeof(ax25_digi));
 	}
 	}
 
 
 	sk->sk_protinfo = ax25;
 	sk->sk_protinfo = ax25;

+ 2 - 2
net/ax25/ax25_out.c

@@ -70,11 +70,11 @@ ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, ax25_address *src, ax2
 	ax25->dest_addr   = *dest;
 	ax25->dest_addr   = *dest;
 
 
 	if (digi != NULL) {
 	if (digi != NULL) {
-		if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
+		ax25->digipeat = kmemdup(digi, sizeof(*digi), GFP_ATOMIC);
+		if (ax25->digipeat == NULL) {
 			ax25_cb_put(ax25);
 			ax25_cb_put(ax25);
 			return NULL;
 			return NULL;
 		}
 		}
-		memcpy(ax25->digipeat, digi, sizeof(ax25_digi));
 	}
 	}
 
 
 	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
 	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {

+ 3 - 2
net/ax25/ax25_route.c

@@ -432,11 +432,12 @@ int ax25_rt_autobind(ax25_cb *ax25, ax25_address *addr)
 	}
 	}
 
 
 	if (ax25_rt->digipeat != NULL) {
 	if (ax25_rt->digipeat != NULL) {
-		if ((ax25->digipeat = kmalloc(sizeof(ax25_digi), GFP_ATOMIC)) == NULL) {
+		ax25->digipeat = kmemdup(ax25_rt->digipeat, sizeof(ax25_digi),
+					 GFP_ATOMIC);
+		if (ax25->digipeat == NULL) {
 			err = -ENOMEM;
 			err = -ENOMEM;
 			goto put;
 			goto put;
 		}
 		}
-		memcpy(ax25->digipeat, ax25_rt->digipeat, sizeof(ax25_digi));
 		ax25_adjust_path(addr, ax25->digipeat);
 		ax25_adjust_path(addr, ax25->digipeat);
 	}
 	}
 
 

+ 3 - 2
net/ax25/sysctl_net_ax25.c

@@ -209,7 +209,9 @@ void ax25_register_sysctl(void)
 	}
 	}
 
 
 	for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
 	for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
-		ctl_table *child = kmalloc(sizeof(ax25_param_table), GFP_ATOMIC);
+		struct ctl_table *child = kmemdup(ax25_param_table,
+						  sizeof(ax25_param_table),
+						  GFP_ATOMIC);
 		if (!child) {
 		if (!child) {
 			while (n--)
 			while (n--)
 				kfree(ax25_table[n].child);
 				kfree(ax25_table[n].child);
@@ -217,7 +219,6 @@ void ax25_register_sysctl(void)
 			spin_unlock_bh(&ax25_dev_lock);
 			spin_unlock_bh(&ax25_dev_lock);
 			return;
 			return;
 		}
 		}
-		memcpy(child, ax25_param_table, sizeof(ax25_param_table));
 		ax25_table[n].child = ax25_dev->systable = child;
 		ax25_table[n].child = ax25_dev->systable = child;
 		ax25_table[n].ctl_name     = n + 1;
 		ax25_table[n].ctl_name     = n + 1;
 		ax25_table[n].procname     = ax25_dev->dev->name;
 		ax25_table[n].procname     = ax25_dev->dev->name;