From 0459d70add3f7ca5d433d4b2334cc6ec9ddab05b Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Fri, 17 Nov 2006 12:43:07 -0200 Subject: [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 --- net/ax25/af_ax25.c | 6 +++--- net/ax25/ax25_out.c | 4 ++-- net/ax25/ax25_route.c | 5 +++-- net/ax25/sysctl_net_ax25.c | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'net/ax25') diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index 000695c485..6cabf6d8a7 100644 --- a/net/ax25/af_ax25.c +++ b/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; 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); ax25_cb_put(ax25); return NULL; } - - memcpy(ax25->digipeat, oax25->digipeat, sizeof(ax25_digi)); } sk->sk_protinfo = ax25; diff --git a/net/ax25/ax25_out.c b/net/ax25/ax25_out.c index d7736e5853..f84047d1e8 100644 --- a/net/ax25/ax25_out.c +++ b/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; 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); return NULL; } - memcpy(ax25->digipeat, digi, sizeof(ax25_digi)); } switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c index 51b7bdaf27..8580356ace 100644 --- a/net/ax25/ax25_route.c +++ b/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->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; goto put; } - memcpy(ax25->digipeat, ax25_rt->digipeat, sizeof(ax25_digi)); ax25_adjust_path(addr, ax25->digipeat); } diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c index 867d425379..d23a27f25d 100644 --- a/net/ax25/sysctl_net_ax25.c +++ b/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) { - 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) { while (n--) kfree(ax25_table[n].child); @@ -217,7 +219,6 @@ void ax25_register_sysctl(void) spin_unlock_bh(&ax25_dev_lock); return; } - memcpy(child, ax25_param_table, sizeof(ax25_param_table)); ax25_table[n].child = ax25_dev->systable = child; ax25_table[n].ctl_name = n + 1; ax25_table[n].procname = ax25_dev->dev->name; -- cgit v1.2.2 From e8cc49bb0fdb9e18a99e6780073d1400ba2b0d1f Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 7 Dec 2006 15:43:13 -0800 Subject: [AX.25]: Constify ax25 utility functions Signed-off-by: Ralf Baechle Signed-off-by: David S. Miller --- net/ax25/ax25_addr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'net/ax25') diff --git a/net/ax25/ax25_addr.c b/net/ax25/ax25_addr.c index 5f0896ad00..5524f9cb7b 100644 --- a/net/ax25/ax25_addr.c +++ b/net/ax25/ax25_addr.c @@ -39,7 +39,7 @@ EXPORT_SYMBOL(null_ax25_address); /* * ax25 -> ascii conversion */ -char *ax2asc(char *buf, ax25_address *a) +char *ax2asc(char *buf, const ax25_address *a) { char c, *s; int n; @@ -72,7 +72,7 @@ EXPORT_SYMBOL(ax2asc); /* * ascii -> ax25 conversion */ -void asc2ax(ax25_address *addr, char *callsign) +void asc2ax(ax25_address *addr, const char *callsign) { char *s; int n; @@ -107,7 +107,7 @@ EXPORT_SYMBOL(asc2ax); /* * Compare two ax.25 addresses */ -int ax25cmp(ax25_address *a, ax25_address *b) +int ax25cmp(const ax25_address *a, const ax25_address *b) { int ct = 0; @@ -128,7 +128,7 @@ EXPORT_SYMBOL(ax25cmp); /* * Compare two AX.25 digipeater paths. */ -int ax25digicmp(ax25_digi *digi1, ax25_digi *digi2) +int ax25digicmp(const ax25_digi *digi1, const ax25_digi *digi2) { int i; @@ -149,7 +149,9 @@ int ax25digicmp(ax25_digi *digi1, ax25_digi *digi2) * Given an AX.25 address pull of to, from, digi list, command/response and the start of data * */ -unsigned char *ax25_addr_parse(unsigned char *buf, int len, ax25_address *src, ax25_address *dest, ax25_digi *digi, int *flags, int *dama) +const unsigned char *ax25_addr_parse(const unsigned char *buf, int len, + ax25_address *src, ax25_address *dest, ax25_digi *digi, int *flags, + int *dama) { int d = 0; @@ -204,7 +206,8 @@ unsigned char *ax25_addr_parse(unsigned char *buf, int len, ax25_address *src, a /* * Assemble an AX.25 header from the bits */ -int ax25_addr_build(unsigned char *buf, ax25_address *src, ax25_address *dest, ax25_digi *d, int flag, int modulus) +int ax25_addr_build(unsigned char *buf, const ax25_address *src, + const ax25_address *dest, const ax25_digi *d, int flag, int modulus) { int len = 0; int ct = 0; @@ -261,7 +264,7 @@ int ax25_addr_build(unsigned char *buf, ax25_address *src, ax25_address *dest, a return len; } -int ax25_addr_size(ax25_digi *dp) +int ax25_addr_size(const ax25_digi *dp) { if (dp == NULL) return 2 * AX25_ADDR_LEN; @@ -272,7 +275,7 @@ int ax25_addr_size(ax25_digi *dp) /* * Reverse Digipeat List. May not pass both parameters as same struct */ -void ax25_digi_invert(ax25_digi *in, ax25_digi *out) +void ax25_digi_invert(const ax25_digi *in, ax25_digi *out) { int ct; -- cgit v1.2.2 From 15b1c0e822f578306332d4f4c449250db5c5dceb Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 7 Dec 2006 15:47:08 -0800 Subject: [AX.25]: Fix default address and broadcast address initialization. Only the callsign but not the SSID part of an AX.25 address is ASCII based but Linux by initializes the SSID which should be just a 4-bit number from ASCII anyway. Fix that and convert the code to use a shared constant for both default addresses. While at it, use the same style for null_ax25_address also. Signed-off-by: Ralf Baechle Signed-off-by: David S. Miller --- net/ax25/ax25_addr.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'net/ax25') diff --git a/net/ax25/ax25_addr.c b/net/ax25/ax25_addr.c index 5524f9cb7b..21a0616152 100644 --- a/net/ax25/ax25_addr.c +++ b/net/ax25/ax25_addr.c @@ -29,11 +29,20 @@ #include /* - * The null address is defined as a callsign of all spaces with an - * SSID of zero. + * The default broadcast address of an interface is QST-0; the default address + * is LINUX-1. The null address is defined as a callsign of all spaces with + * an SSID of zero. */ -ax25_address null_ax25_address = {{0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00}}; +const ax25_address ax25_bcast = + {{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}}; +const ax25_address ax25_defaddr = + {{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, 1 << 1}}; +const ax25_address null_ax25_address = + {{' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}}; + +EXPORT_SYMBOL_GPL(ax25_bcast); +EXPORT_SYMBOL_GPL(ax25_defaddr); EXPORT_SYMBOL(null_ax25_address); /* -- cgit v1.2.2 From f654c854d1d4e0aca5389ace541647237eb7f753 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Sun, 10 Dec 2006 13:46:45 -0800 Subject: [HAMRADIO]: Fix baycom_epp.c compile failure. Fix foobar in 15b1c0e822f578306332d4f4c449250db5c5dceb and e8cc49bb0fdb9e18a99e6780073d1400ba2b0d1f patch series. Signed-off-by: Ralf Baechle Signed-off-by: David S. Miller --- net/ax25/ax25_addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/ax25') diff --git a/net/ax25/ax25_addr.c b/net/ax25/ax25_addr.c index 21a0616152..97a49c79c6 100644 --- a/net/ax25/ax25_addr.c +++ b/net/ax25/ax25_addr.c @@ -83,7 +83,7 @@ EXPORT_SYMBOL(ax2asc); */ void asc2ax(ax25_address *addr, const char *callsign) { - char *s; + const char *s; int n; for (s = callsign, n = 0; n < 6; n++) { -- cgit v1.2.2