6pack.c-2.4.0-test12-patch-v1

From: Hans Grobler (terhi.victor@logonet.com)
Date: Wed Dec 13 2000 - 16:29:41 EET

  • Next message: Iain Young: "Re: bpqether.c-2.4.0-test12-patch-v1"

    6pack.c-2.4.0-test12-patch-v1:
      - sp_alloc,sixpack_cleanup_driver: removed check for NULL sixpack_ctrls.
          sixpack_ctrls will != NULL if the module loaded.
      - sixpack_init_driver: fixed memory leak if module failed to load.

    6pack.c-2.4.0-test12-pre8-patch-v1:
      - commented out userspace includes: removed... was for early testing?
      - banner,sixpack_init_ctrl_dev: converted initialization message to
          form suitable for __initdata tagging. will now be ejected by kernel
          after use.
      - sixpack_ctrls,sixpack_init_ctrl_dev: removed explicit clearing of
          variables as per linux2.4
      - sp_xmit: kernel network layer will never pass NULL skb, check
          unnecessary
      - removed stray endif comment
      - sixpack_maxdev: added missing support for module parameter

    6pack.c-2.4.0-test12-pre7-patch-v1:
      - sp_open: removed comment about cbuf (accidently copied from slip.c)
      - sp_set_mac_address,sixpack_ioctl: converted to linux2.4 to/from
          userspace functions
      - sp_set_mac_address,sixpack_init,sixpack_decode,decode_std_command,
          decode_data: made static functions

    diff -u3Nr -X dontdiff linux-2.4.0-test12.orig/drivers/net/hamradio/6pack.c linux-2.4.0-test12/drivers/net/hamradio/6pack.c
    --- linux-2.4.0-test12.orig/drivers/net/hamradio/6pack.c Thu May 4 20:31:21 2000
    +++ linux-2.4.0-test12/drivers/net/hamradio/6pack.c Wed Dec 13 11:35:59 2000
    @@ -37,16 +37,11 @@
     #include <linux/init.h>
     #include <linux/ip.h>
     #include <linux/tcp.h>
    -/*
    -#include <sys/types.h>
    -#include <sys/stat.h>
    -#include <fcntl.h>
    -#include <stdio.h>
    -#include <unistd.h>
    -*/

     #include "6pack.h"

    +static const char banner[] __initdata = KERN_INFO "AX.25: 6pack driver, " SIXPACK_VERSION " (dynamic channels, max=%d)\n";
    +
     typedef unsigned char byte;

    @@ -54,7 +49,7 @@
             struct sixpack ctrl; /* 6pack things */
             struct net_device dev; /* the device */
     } sixpack_ctrl_t;
    -static sixpack_ctrl_t **sixpack_ctrls = NULL;
    +static sixpack_ctrl_t **sixpack_ctrls;
     int sixpack_maxdev = SIXP_NRUNIT; /* Can be overridden with insmod! */

     static struct tty_ldisc sp_ldisc;
    @@ -62,12 +57,13 @@
     static void sp_start_tx_timer(struct sixpack *);
     static void sp_xmit_on_air(unsigned long);
     static void resync_tnc(unsigned long);
    -void sixpack_decode(struct sixpack *, unsigned char[], int);
    -int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char);
    -
    -void decode_prio_command(byte, struct sixpack *);
    -void decode_std_command(byte, struct sixpack *);
    -void decode_data(byte, struct sixpack *);
    +static void sixpack_decode(struct sixpack *, unsigned char[], int);
    +static int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char);
    +static int sixpack_init(struct net_device *dev);
    +
    +static void decode_prio_command(byte, struct sixpack *);
    +static void decode_std_command(byte, struct sixpack *);
    +static void decode_data(byte, struct sixpack *);

     static int tnc_init(struct sixpack *);

    @@ -78,8 +74,6 @@
             sixpack_ctrl_t *spp = NULL;
             int i;

    - if (sixpack_ctrls == NULL) return NULL; /* Master array missing ! */
    -
             for (i = 0; i < sixpack_maxdev; i++)
             {
                     spp = sixpack_ctrls[i];
    @@ -313,15 +307,12 @@
             struct sixpack *sp = (struct sixpack*)(dev->priv);

             /* We were not busy, so we are now... :-) */
    - if (skb != NULL) {
    - netif_stop_queue(dev);
    - sp->tx_bytes+=skb->len; /*---2.1.x---*/
    - sp_encaps(sp, skb->data, skb->len);
    - dev_kfree_skb(skb);
    - }
    + netif_stop_queue(dev);
    + sp->tx_bytes+=skb->len;
    + sp_encaps(sp, skb->data, skb->len);
    + dev_kfree_skb(skb);
             return 0;
     }
    -/* #endif */

     /* perform the persistence/slottime algorithm for CSMA access. If the persistence
    @@ -351,7 +342,6 @@
                     sp_start_tx_timer(sp);
     } /* sp_xmit */

    -/* #if defined(CONFIG_6PACK) || defined(CONFIG_6PACK_MODULE) */

     /* Return the frame type ID */
     static int sp_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
    @@ -374,7 +364,6 @@
     #endif
     }

    -/* #endif */ /* CONFIG_{AX25,AX25_MODULE} */

     /* Open the low-level part of the 6pack channel. */
     static int
    @@ -391,7 +380,6 @@
              *
              * rbuff Receive buffer.
              * xbuff Transmit buffer.
    - * cbuff Temporary compression buffer.
              */

             /* !!! length of the buffers. MTU is IP MTU, not PACLEN!
    @@ -603,19 +591,10 @@
     }

    -int
    +static int
     sp_set_mac_address(struct net_device *dev, void *addr)
     {
    - int err;
    -
    - err = verify_area(VERIFY_READ, addr, AX25_ADDR_LEN);
    - if (err) {
    - return err;
    - }
    -
    - copy_from_user(dev->dev_addr, addr, AX25_ADDR_LEN); /* addr is an AX.25 shifted ASCII mac address */
    -
    - return 0;
    + return copy_from_user(dev->dev_addr, addr, AX25_ADDR_LEN) ? -EFAULT : 0;
     }

     static int
    @@ -632,7 +611,6 @@
     sixpack_ioctl(struct tty_struct *tty, void *file, int cmd, void *arg)
     {
             struct sixpack *sp = (struct sixpack *) tty->disc_data;
    - int err;
             unsigned int tmp;

             /* First make sure we're connected. */
    @@ -642,29 +620,16 @@

             switch(cmd) {
              case SIOCGIFNAME:
    - err = verify_area(VERIFY_WRITE, arg, strlen(sp->dev->name) + 1);
    - if (err) {
    - return err;
    - }
    - copy_to_user(arg, sp->dev->name, strlen(sp->dev->name) + 1);
    - return 0;
    + return copy_to_user(arg, sp->dev->name, strlen(sp->dev->name) + 1) ? -EFAULT : 0;

             case SIOCGIFENCAP:
    - err = verify_area(VERIFY_WRITE, arg, sizeof(int));
    - if (err) {
    - return err;
    - }
    - put_user(0, (int *)arg);
    - return 0;
    + return put_user(0, (int *)arg);

             case SIOCSIFENCAP:
    - err = verify_area(VERIFY_READ, arg, sizeof(int));
    - if (err) {
    - return err;
    - }
    - get_user(tmp,(int *)arg);
    + if (get_user(tmp, (int *) arg))
    + return -EFAULT;

    - sp->mode = tmp;
    + sp->mode = tmp;
                     sp->dev->addr_len = AX25_ADDR_LEN; /* sizeof an AX.25 addr */
                     sp->dev->hard_header_len = AX25_KISS_HEADER_LEN + AX25_MAX_HEADER_LEN + 3;
                     sp->dev->type = ARPHRD_AX25;
    @@ -694,14 +659,13 @@

     /* Initialize 6pack control device -- register 6pack line discipline */

    -static int __init sixpack_init_ctrl_dev(void)
    +static int __init sixpack_init_driver(void)
     {
             int status;

             if (sixpack_maxdev < 4) sixpack_maxdev = 4; /* Sanity */

    - printk(KERN_INFO "AX.25: 6pack driver, %s (dynamic channels, max=%d)\n",
    - SIXPACK_VERSION, sixpack_maxdev);
    + printk(banner, sixpack_maxdev);

             sixpack_ctrls = (sixpack_ctrl_t **) kmalloc(sizeof(void*)*sixpack_maxdev, GFP_KERNEL);
             if (sixpack_ctrls == NULL)
    @@ -715,7 +679,6 @@

             /* Fill in our line protocol discipline, and register it */
    - memset(&sp_ldisc, 0, sizeof(sp_ldisc));
             sp_ldisc.magic = TTY_LDISC_MAGIC;
             sp_ldisc.name = "6pack";
             sp_ldisc.flags = 0;
    @@ -731,6 +694,7 @@
             sp_ldisc.write_wakeup = sixpack_write_wakeup;
             if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0) {
                     printk(KERN_WARNING "6pack: can't register line discipline (err = %d)\n", status);
    + kfree(sixpack_ctrls);
             }

             return status;
    @@ -740,27 +704,23 @@
     {
             int i;

    - if (sixpack_ctrls != NULL)
    - {
    - for (i = 0; i < sixpack_maxdev; i++)
    - {
    - if (sixpack_ctrls[i])
    - {
    - /*
    - * VSV = if dev->start==0, then device
    - * unregistered while close proc.
    - */
    - if (netif_running(&sixpack_ctrls[i]->dev))
    - unregister_netdev(&sixpack_ctrls[i]->dev);
    -
    - kfree(sixpack_ctrls[i]);
    - sixpack_ctrls[i] = NULL;
    - }
    - }
    - kfree(sixpack_ctrls);
    - sixpack_ctrls = NULL;
    - }
    - if ((i = tty_register_ldisc(N_6PACK, NULL)))
    + for (i = 0; i < sixpack_maxdev; i++)
    + {
    + if (sixpack_ctrls[i])
    + {
    + /*
    + * VSV = if dev->start==0, then device
    + * unregistered while close proc.
    + */
    + if (netif_running(&sixpack_ctrls[i]->dev))
    + unregister_netdev(&sixpack_ctrls[i]->dev);
    +
    + kfree(sixpack_ctrls[i]);
    + }
    + }
    + kfree(sixpack_ctrls);
    + sixpack_ctrls = NULL;
    + if ((i = tty_register_ldisc(N_6PACK, NULL)))
             {
                     printk(KERN_WARNING "6pack: can't unregister line discipline (err = %d)\n", i);
             }
    @@ -768,7 +728,7 @@

     /* Initialize the 6pack driver. Called by DDI. */
    -int
    +static int
     sixpack_init(struct net_device *dev)
     {
             struct sixpack *sp = (struct sixpack*)(dev->priv);
    @@ -832,7 +792,7 @@

     /* encode an AX.25 packet into 6pack */

    -int encode_sixpack(byte *tx_buf, byte *tx_buf_raw, int length, byte tx_delay)
    +static int encode_sixpack(byte *tx_buf, byte *tx_buf_raw, int length, byte tx_delay)
     {
             int count = 0;
             byte checksum = 0, buf[400];
    @@ -873,7 +833,7 @@

     /* decode a 6pack packet */

    -void
    +static void
     sixpack_decode(struct sixpack *sp, unsigned char pre_rbuff[], int count)
     {
             byte inbyte;
    @@ -917,7 +877,7 @@

     /* identify and execute a 6pack priority command byte */

    -void decode_prio_command(byte cmd, struct sixpack *sp)
    +static void decode_prio_command(byte cmd, struct sixpack *sp)
     {
             byte channel;
             int actual;
    @@ -1016,7 +976,7 @@

     /* identify and execute a standard 6pack command byte */

    -void decode_std_command(byte cmd, struct sixpack *sp)
    +static void decode_std_command(byte cmd, struct sixpack *sp)
     {
             byte checksum = 0, rest = 0, channel;
             short i;
    @@ -1064,7 +1024,7 @@

     /* decode 4 sixpack-encoded bytes into 3 data bytes */

    -void decode_data(byte inbyte, struct sixpack *sp)
    +static void decode_data(byte inbyte, struct sixpack *sp)
     {

             unsigned char *buf;
    @@ -1086,5 +1046,9 @@

     MODULE_AUTHOR("Andreas Könsgen <yixw.cengx@mtu.ru>");
     MODULE_DESCRIPTION("6pack driver for AX.25");
    -module_init(sixpack_init_ctrl_dev);
    +
    +MODULE_PARM(sixpack_maxdev, "i");
    +MODULE_PARM_DESC(sixpack_maxdev, "number of 6PACK devices");
    +
    +module_init(sixpack_init_driver);
     module_exit(sixpack_cleanup_driver);

    -
    To unsubscribe from this list: send the line "unsubscribe linux-hams" in
    the body of a message to cwjbw.esmamavlkx@ntt.net.au



    This archive was generated by hypermail 2b30 : Wed Dec 13 2000 - 16:42:30 EET