| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * This program is free software; you can distribute it and/or modify it |
|---|
| 3 | | - * under the terms of the GNU General Public License (Version 2) as |
|---|
| 4 | | - * published by the Free Software Foundation. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 7 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 8 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 9 | | - * for more details. |
|---|
| 10 | | - * |
|---|
| 11 | | - * You should have received a copy of the GNU General Public License along |
|---|
| 12 | | - * with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 13 | 3 | * |
|---|
| 14 | 4 | * Copyright (C) Hans Alblas PE1AYX <hans@esrac.ele.tue.nl> |
|---|
| 15 | 5 | * Copyright (C) 2004, 05 Ralf Baechle DL5RB <ralf@linux-mips.org> |
|---|
| .. | .. |
|---|
| 35 | 25 | #include <linux/skbuff.h> |
|---|
| 36 | 26 | #include <linux/if_arp.h> |
|---|
| 37 | 27 | #include <linux/jiffies.h> |
|---|
| 38 | | -#include <linux/compat.h> |
|---|
| 28 | +#include <linux/refcount.h> |
|---|
| 39 | 29 | |
|---|
| 40 | 30 | #include <net/ax25.h> |
|---|
| 41 | 31 | |
|---|
| 42 | 32 | #define AX_MTU 236 |
|---|
| 43 | 33 | |
|---|
| 34 | +/* some arch define END as assembly function ending, just undef it */ |
|---|
| 35 | +#undef END |
|---|
| 44 | 36 | /* SLIP/KISS protocol characters. */ |
|---|
| 45 | 37 | #define END 0300 /* indicates end of frame */ |
|---|
| 46 | 38 | #define ESC 0333 /* indicates byte stuffing */ |
|---|
| .. | .. |
|---|
| 81 | 73 | #define CRC_MODE_FLEX_TEST 3 |
|---|
| 82 | 74 | #define CRC_MODE_SMACK_TEST 4 |
|---|
| 83 | 75 | |
|---|
| 84 | | - atomic_t refcnt; |
|---|
| 85 | | - struct semaphore dead_sem; |
|---|
| 76 | + refcount_t refcnt; |
|---|
| 77 | + struct completion dead; |
|---|
| 86 | 78 | }; |
|---|
| 87 | 79 | |
|---|
| 88 | 80 | /*---------------------------------------------------------------------------*/ |
|---|
| .. | .. |
|---|
| 492 | 484 | case CRC_MODE_SMACK_TEST: |
|---|
| 493 | 485 | ax->crcmode = CRC_MODE_FLEX_TEST; |
|---|
| 494 | 486 | printk(KERN_INFO "mkiss: %s: Trying crc-smack\n", ax->dev->name); |
|---|
| 495 | | - // fall through |
|---|
| 487 | + fallthrough; |
|---|
| 496 | 488 | case CRC_MODE_SMACK: |
|---|
| 497 | 489 | *p |= 0x80; |
|---|
| 498 | 490 | crc = swab16(crc16(0, p, len)); |
|---|
| .. | .. |
|---|
| 501 | 493 | case CRC_MODE_FLEX_TEST: |
|---|
| 502 | 494 | ax->crcmode = CRC_MODE_NONE; |
|---|
| 503 | 495 | printk(KERN_INFO "mkiss: %s: Trying crc-flexnet\n", ax->dev->name); |
|---|
| 504 | | - // fall through |
|---|
| 496 | + fallthrough; |
|---|
| 505 | 497 | case CRC_MODE_FLEX: |
|---|
| 506 | 498 | *p |= 0x20; |
|---|
| 507 | 499 | crc = calc_crc_flex(p, len); |
|---|
| .. | .. |
|---|
| 679 | 671 | read_lock(&disc_data_lock); |
|---|
| 680 | 672 | ax = tty->disc_data; |
|---|
| 681 | 673 | if (ax) |
|---|
| 682 | | - atomic_inc(&ax->refcnt); |
|---|
| 674 | + refcount_inc(&ax->refcnt); |
|---|
| 683 | 675 | read_unlock(&disc_data_lock); |
|---|
| 684 | 676 | |
|---|
| 685 | 677 | return ax; |
|---|
| .. | .. |
|---|
| 687 | 679 | |
|---|
| 688 | 680 | static void mkiss_put(struct mkiss *ax) |
|---|
| 689 | 681 | { |
|---|
| 690 | | - if (atomic_dec_and_test(&ax->refcnt)) |
|---|
| 691 | | - up(&ax->dead_sem); |
|---|
| 682 | + if (refcount_dec_and_test(&ax->refcnt)) |
|---|
| 683 | + complete(&ax->dead); |
|---|
| 692 | 684 | } |
|---|
| 693 | 685 | |
|---|
| 694 | 686 | static int crc_force = 0; /* Can be overridden with insmod */ |
|---|
| .. | .. |
|---|
| 715 | 707 | ax->dev = dev; |
|---|
| 716 | 708 | |
|---|
| 717 | 709 | spin_lock_init(&ax->buflock); |
|---|
| 718 | | - atomic_set(&ax->refcnt, 1); |
|---|
| 719 | | - sema_init(&ax->dead_sem, 0); |
|---|
| 710 | + refcount_set(&ax->refcnt, 1); |
|---|
| 711 | + init_completion(&ax->dead); |
|---|
| 720 | 712 | |
|---|
| 721 | 713 | ax->tty = tty; |
|---|
| 722 | 714 | tty->disc_data = ax; |
|---|
| .. | .. |
|---|
| 754 | 746 | ax->dev->name); |
|---|
| 755 | 747 | break; |
|---|
| 756 | 748 | case 0: |
|---|
| 757 | | - /* fall through */ |
|---|
| 758 | 749 | default: |
|---|
| 759 | 750 | crc_force = 0; |
|---|
| 760 | 751 | printk(KERN_INFO "mkiss: %s: crc mode is auto.\n", |
|---|
| .. | .. |
|---|
| 795 | 786 | * We have now ensured that nobody can start using ap from now on, but |
|---|
| 796 | 787 | * we have to wait for all existing users to finish. |
|---|
| 797 | 788 | */ |
|---|
| 798 | | - if (!atomic_dec_and_test(&ax->refcnt)) |
|---|
| 799 | | - down(&ax->dead_sem); |
|---|
| 789 | + if (!refcount_dec_and_test(&ax->refcnt)) |
|---|
| 790 | + wait_for_completion(&ax->dead); |
|---|
| 800 | 791 | /* |
|---|
| 801 | 792 | * Halt the transmit queue so that a new transmit cannot scribble |
|---|
| 802 | 793 | * on our buffers |
|---|
| .. | .. |
|---|
| 877 | 868 | return err; |
|---|
| 878 | 869 | } |
|---|
| 879 | 870 | |
|---|
| 880 | | -#ifdef CONFIG_COMPAT |
|---|
| 881 | | -static long mkiss_compat_ioctl(struct tty_struct *tty, struct file *file, |
|---|
| 882 | | - unsigned int cmd, unsigned long arg) |
|---|
| 883 | | -{ |
|---|
| 884 | | - switch (cmd) { |
|---|
| 885 | | - case SIOCGIFNAME: |
|---|
| 886 | | - case SIOCGIFENCAP: |
|---|
| 887 | | - case SIOCSIFENCAP: |
|---|
| 888 | | - case SIOCSIFHWADDR: |
|---|
| 889 | | - return mkiss_ioctl(tty, file, cmd, |
|---|
| 890 | | - (unsigned long)compat_ptr(arg)); |
|---|
| 891 | | - } |
|---|
| 892 | | - |
|---|
| 893 | | - return -ENOIOCTLCMD; |
|---|
| 894 | | -} |
|---|
| 895 | | -#endif |
|---|
| 896 | | - |
|---|
| 897 | 871 | /* |
|---|
| 898 | 872 | * Handle the 'receiver data ready' interrupt. |
|---|
| 899 | 873 | * This function is called by the 'tty_io' module in the kernel when |
|---|
| .. | .. |
|---|
| 968 | 942 | .open = mkiss_open, |
|---|
| 969 | 943 | .close = mkiss_close, |
|---|
| 970 | 944 | .ioctl = mkiss_ioctl, |
|---|
| 971 | | -#ifdef CONFIG_COMPAT |
|---|
| 972 | | - .compat_ioctl = mkiss_compat_ioctl, |
|---|
| 973 | | -#endif |
|---|
| 974 | 945 | .receive_buf = mkiss_receive_buf, |
|---|
| 975 | 946 | .write_wakeup = mkiss_write_wakeup |
|---|
| 976 | 947 | }; |
|---|