forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/net/hamradio/6pack.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * 6pack.c This module implements the 6pack protocol for kernel-based
34 * devices like TTY. It interfaces between a raw TTY and the
....@@ -34,7 +35,6 @@
3435 #include <linux/ip.h>
3536 #include <linux/tcp.h>
3637 #include <linux/semaphore.h>
37
-#include <linux/compat.h>
3838 #include <linux/refcount.h>
3939
4040 #define SIXPACK_VERSION "Revision: 0.3.0"
....@@ -121,7 +121,7 @@
121121 struct timer_list tx_t;
122122 struct timer_list resync_t;
123123 refcount_t refcnt;
124
- struct semaphore dead_sem;
124
+ struct completion dead;
125125 spinlock_t lock;
126126 };
127127
....@@ -311,7 +311,6 @@
311311 {
312312 /* Finish setting up the DEVICE info. */
313313 dev->netdev_ops = &sp_netdev_ops;
314
- dev->needs_free_netdev = true;
315314 dev->mtu = SIXP_MTU;
316315 dev->hard_header_len = AX25_MAX_HEADER_LEN;
317316 dev->header_ops = &ax25_header_ops;
....@@ -344,10 +343,10 @@
344343
345344 sp->dev->stats.rx_bytes += count;
346345
347
- if ((skb = dev_alloc_skb(count)) == NULL)
346
+ if ((skb = dev_alloc_skb(count + 1)) == NULL)
348347 goto out_mem;
349348
350
- ptr = skb_put(skb, count);
349
+ ptr = skb_put(skb, count + 1);
351350 *ptr++ = cmd; /* KISS command */
352351
353352 memcpy(ptr, sp->cooked_buf + 1, count);
....@@ -390,7 +389,7 @@
390389 static void sp_put(struct sixpack *sp)
391390 {
392391 if (refcount_dec_and_test(&sp->refcnt))
393
- up(&sp->dead_sem);
392
+ complete(&sp->dead);
394393 }
395394
396395 /*
....@@ -572,7 +571,7 @@
572571
573572 spin_lock_init(&sp->lock);
574573 refcount_set(&sp->refcnt, 1);
575
- sema_init(&sp->dead_sem, 0);
574
+ init_completion(&sp->dead);
576575
577576 /* !!! length of the buffers. MTU is IP MTU, not PACLEN! */
578577
....@@ -666,22 +665,24 @@
666665 * we have to wait for all existing users to finish.
667666 */
668667 if (!refcount_dec_and_test(&sp->refcnt))
669
- down(&sp->dead_sem);
668
+ wait_for_completion(&sp->dead);
670669
671670 /* We must stop the queue to avoid potentially scribbling
672
- * on the free buffers. The sp->dead_sem is not sufficient
671
+ * on the free buffers. The sp->dead completion is not sufficient
673672 * to protect us from sp->xbuff access.
674673 */
675674 netif_stop_queue(sp->dev);
676675
676
+ unregister_netdev(sp->dev);
677
+
677678 del_timer_sync(&sp->tx_t);
678679 del_timer_sync(&sp->resync_t);
679680
680
- /* Free all 6pack frame buffers. */
681
+ /* Free all 6pack frame buffers after unreg. */
681682 kfree(sp->rbuff);
682683 kfree(sp->xbuff);
683684
684
- unregister_netdev(sp->dev);
685
+ free_netdev(sp->dev);
685686 }
686687
687688 /* Perform I/O control on an active 6pack channel. */
....@@ -747,23 +748,6 @@
747748 return err;
748749 }
749750
750
-#ifdef CONFIG_COMPAT
751
-static long sixpack_compat_ioctl(struct tty_struct * tty, struct file * file,
752
- unsigned int cmd, unsigned long arg)
753
-{
754
- switch (cmd) {
755
- case SIOCGIFNAME:
756
- case SIOCGIFENCAP:
757
- case SIOCSIFENCAP:
758
- case SIOCSIFHWADDR:
759
- return sixpack_ioctl(tty, file, cmd,
760
- (unsigned long)compat_ptr(arg));
761
- }
762
-
763
- return -ENOIOCTLCMD;
764
-}
765
-#endif
766
-
767751 static struct tty_ldisc_ops sp_ldisc = {
768752 .owner = THIS_MODULE,
769753 .magic = TTY_LDISC_MAGIC,
....@@ -771,9 +755,6 @@
771755 .open = sixpack_open,
772756 .close = sixpack_close,
773757 .ioctl = sixpack_ioctl,
774
-#ifdef CONFIG_COMPAT
775
- .compat_ioctl = sixpack_compat_ioctl,
776
-#endif
777758 .receive_buf = sixpack_receive_buf,
778759 .write_wakeup = sixpack_write_wakeup,
779760 };