diff options
Diffstat (limited to 'drivers/net/hamradio/mkiss.c')
| -rw-r--r-- | drivers/net/hamradio/mkiss.c | 107 |
1 files changed, 37 insertions, 70 deletions
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index aec6c26563cf..5f38a002bd9e 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c @@ -1,15 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-only /* - * This program is free software; you can distribute it and/or modify it - * under the terms of the GNU General Public License (Version 2) as - * published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, see <http://www.gnu.org/licenses/>. * * Copyright (C) Hans Alblas PE1AYX <hans@esrac.ele.tue.nl> * Copyright (C) 2004, 05 Ralf Baechle DL5RB <ralf@linux-mips.org> @@ -35,12 +25,14 @@ #include <linux/skbuff.h> #include <linux/if_arp.h> #include <linux/jiffies.h> -#include <linux/compat.h> +#include <linux/refcount.h> #include <net/ax25.h> #define AX_MTU 236 +/* some arch define END as assembly function ending, just undef it */ +#undef END /* SLIP/KISS protocol characters. */ #define END 0300 /* indicates end of frame */ #define ESC 0333 /* indicates byte stuffing */ @@ -81,8 +73,8 @@ struct mkiss { #define CRC_MODE_FLEX_TEST 3 #define CRC_MODE_SMACK_TEST 4 - atomic_t refcnt; - struct semaphore dead_sem; + refcount_t refcnt; + struct completion dead; }; /*---------------------------------------------------------------------------*/ @@ -217,7 +209,7 @@ static int kiss_esc_crc(unsigned char *s, unsigned char *d, unsigned short crc, c = *s++; else if (len > 1) c = crc >> 8; - else if (len > 0) + else c = crc & 0xff; len--; @@ -286,7 +278,7 @@ static void ax_bump(struct mkiss *ax) */ *ax->rbuff &= ~0x20; } - } + } count = ax->rcount; @@ -354,7 +346,7 @@ static int ax_set_mac_address(struct net_device *dev, void *addr) netif_tx_lock_bh(dev); netif_addr_lock(dev); - memcpy(dev->dev_addr, &sa->sax25_call, AX25_ADDR_LEN); + __dev_addr_set(dev, &sa->sax25_call, AX25_ADDR_LEN); netif_addr_unlock(dev); netif_tx_unlock_bh(dev); @@ -440,7 +432,6 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len) ax_changedmtu(ax); if (len > ax->mtu) { /* Sigh, shouldn't occur BUT ... */ - len = ax->mtu; printk(KERN_ERR "mkiss: %s: truncating oversized transmit packet!\n", ax->dev->name); dev->stats.tx_dropped++; netif_start_queue(dev); @@ -477,7 +468,8 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len) cmd = 0; } ax->crcauto = (cmd ? 0 : 1); - printk(KERN_INFO "mkiss: %s: crc mode %s %d\n", ax->dev->name, (len) ? "set to" : "is", cmd); + printk(KERN_INFO "mkiss: %s: crc mode set to %d\n", + ax->dev->name, cmd); } spin_unlock_bh(&ax->buflock); netif_start_queue(dev); @@ -492,7 +484,7 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len) case CRC_MODE_SMACK_TEST: ax->crcmode = CRC_MODE_FLEX_TEST; printk(KERN_INFO "mkiss: %s: Trying crc-smack\n", ax->dev->name); - // fall through + fallthrough; case CRC_MODE_SMACK: *p |= 0x80; crc = swab16(crc16(0, p, len)); @@ -501,7 +493,7 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len) case CRC_MODE_FLEX_TEST: ax->crcmode = CRC_MODE_NONE; printk(KERN_INFO "mkiss: %s: Trying crc-flexnet\n", ax->dev->name); - // fall through + fallthrough; case CRC_MODE_FLEX: *p |= 0x20; crc = calc_crc_flex(p, len); @@ -511,7 +503,7 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len) default: count = kiss_esc(p, ax->xbuff, len); } - } + } spin_unlock_bh(&ax->buflock); set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); @@ -657,7 +649,7 @@ static void ax_setup(struct net_device *dev) memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN); - memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN); + dev_addr_set(dev, (u8 *)&ax25_defaddr); dev->flags = IFF_BROADCAST | IFF_MULTICAST; } @@ -679,7 +671,7 @@ static struct mkiss *mkiss_get(struct tty_struct *tty) read_lock(&disc_data_lock); ax = tty->disc_data; if (ax) - atomic_inc(&ax->refcnt); + refcount_inc(&ax->refcnt); read_unlock(&disc_data_lock); return ax; @@ -687,8 +679,8 @@ static struct mkiss *mkiss_get(struct tty_struct *tty) static void mkiss_put(struct mkiss *ax) { - if (atomic_dec_and_test(&ax->refcnt)) - up(&ax->dead_sem); + if (refcount_dec_and_test(&ax->refcnt)) + complete(&ax->dead); } static int crc_force = 0; /* Can be overridden with insmod */ @@ -715,8 +707,8 @@ static int mkiss_open(struct tty_struct *tty) ax->dev = dev; spin_lock_init(&ax->buflock); - atomic_set(&ax->refcnt, 1); - sema_init(&ax->dead_sem, 0); + refcount_set(&ax->refcnt, 1); + init_completion(&ax->dead); ax->tty = tty; tty->disc_data = ax; @@ -754,7 +746,6 @@ static int mkiss_open(struct tty_struct *tty) ax->dev->name); break; case 0: - /* fall through */ default: crc_force = 0; printk(KERN_INFO "mkiss: %s: crc mode is auto.\n", @@ -783,10 +774,10 @@ static void mkiss_close(struct tty_struct *tty) { struct mkiss *ax; - write_lock_bh(&disc_data_lock); + write_lock_irq(&disc_data_lock); ax = tty->disc_data; tty->disc_data = NULL; - write_unlock_bh(&disc_data_lock); + write_unlock_irq(&disc_data_lock); if (!ax) return; @@ -795,26 +786,28 @@ static void mkiss_close(struct tty_struct *tty) * We have now ensured that nobody can start using ap from now on, but * we have to wait for all existing users to finish. */ - if (!atomic_dec_and_test(&ax->refcnt)) - down(&ax->dead_sem); + if (!refcount_dec_and_test(&ax->refcnt)) + wait_for_completion(&ax->dead); /* * Halt the transmit queue so that a new transmit cannot scribble * on our buffers */ netif_stop_queue(ax->dev); - /* Free all AX25 frame buffers. */ + unregister_netdev(ax->dev); + + /* Free all AX25 frame buffers after unreg. */ kfree(ax->rbuff); kfree(ax->xbuff); ax->tty = NULL; - unregister_netdev(ax->dev); + free_netdev(ax->dev); } /* Perform I/O control on an active ax25 channel. */ -static int mkiss_ioctl(struct tty_struct *tty, struct file *file, - unsigned int cmd, unsigned long arg) +static int mkiss_ioctl(struct tty_struct *tty, unsigned int cmd, + unsigned long arg) { struct mkiss *ax = mkiss_get(tty); struct net_device *dev; @@ -826,7 +819,7 @@ static int mkiss_ioctl(struct tty_struct *tty, struct file *file, dev = ax->dev; switch (cmd) { - case SIOCGIFNAME: + case SIOCGIFNAME: err = copy_to_user((void __user *) arg, ax->dev->name, strlen(ax->dev->name) + 1) ? -EFAULT : 0; break; @@ -860,7 +853,7 @@ static int mkiss_ioctl(struct tty_struct *tty, struct file *file, } netif_tx_lock_bh(dev); - memcpy(dev->dev_addr, addr, AX25_ADDR_LEN); + __dev_addr_set(dev, addr, AX25_ADDR_LEN); netif_tx_unlock_bh(dev); err = 0; @@ -875,31 +868,14 @@ static int mkiss_ioctl(struct tty_struct *tty, struct file *file, return err; } -#ifdef CONFIG_COMPAT -static long mkiss_compat_ioctl(struct tty_struct *tty, struct file *file, - unsigned int cmd, unsigned long arg) -{ - switch (cmd) { - case SIOCGIFNAME: - case SIOCGIFENCAP: - case SIOCSIFENCAP: - case SIOCSIFHWADDR: - return mkiss_ioctl(tty, file, cmd, - (unsigned long)compat_ptr(arg)); - } - - return -ENOIOCTLCMD; -} -#endif - /* * Handle the 'receiver data ready' interrupt. * This function is called by the 'tty_io' module in the kernel when * a block of data has been received, which can now be decapsulated * and sent on to the AX.25 layer for further processing. */ -static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp, - char *fp, int count) +static void mkiss_receive_buf(struct tty_struct *tty, const u8 *cp, + const u8 *fp, size_t count) { struct mkiss *ax = mkiss_get(tty); @@ -961,14 +937,11 @@ out: static struct tty_ldisc_ops ax_ldisc = { .owner = THIS_MODULE, - .magic = TTY_LDISC_MAGIC, + .num = N_AX25, .name = "mkiss", .open = mkiss_open, .close = mkiss_close, .ioctl = mkiss_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = mkiss_compat_ioctl, -#endif .receive_buf = mkiss_receive_buf, .write_wakeup = mkiss_write_wakeup }; @@ -984,22 +957,16 @@ static int __init mkiss_init_driver(void) printk(banner); - status = tty_register_ldisc(N_AX25, &ax_ldisc); + status = tty_register_ldisc(&ax_ldisc); if (status != 0) printk(msg_regfail, status); return status; } -static const char msg_unregfail[] = KERN_ERR \ - "mkiss: can't unregister line discipline (err = %d)\n"; - static void __exit mkiss_exit_driver(void) { - int ret; - - if ((ret = tty_unregister_ldisc(N_AX25))) - printk(msg_unregfail, ret); + tty_unregister_ldisc(&ax_ldisc); } MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>"); |
