hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/net/wan/x25_asy.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Things to sort out:
34 *
....@@ -33,7 +34,6 @@
3334 #include <linux/lapb.h>
3435 #include <linux/init.h>
3536 #include <linux/rtnetlink.h>
36
-#include <linux/compat.h>
3737 #include <linux/slab.h>
3838 #include <net/x25device.h>
3939 #include "x25_asy.h"
....@@ -202,8 +202,7 @@
202202 return;
203203 }
204204 skb_put_data(skb, sl->rbuff, count);
205
- skb->protocol = x25_type_trans(skb, sl->dev);
206
- err = lapb_data_received(skb->dev, skb);
205
+ err = lapb_data_received(sl->dev, skb);
207206 if (err != LAPB_OK) {
208207 kfree_skb(skb);
209208 printk(KERN_DEBUG "x25_asy: data received err - %d\n", err);
....@@ -243,8 +242,6 @@
243242 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
244243 sl->xleft = count - actual;
245244 sl->xhead = sl->xbuff + actual;
246
- /* VSV */
247
- clear_bit(SLF_OUTWAIT, &sl->flags); /* reset outfill flag */
248245 }
249246
250247 /*
....@@ -274,7 +271,7 @@
274271 sl->xhead += actual;
275272 }
276273
277
-static void x25_asy_timeout(struct net_device *dev)
274
+static void x25_asy_timeout(struct net_device *dev, unsigned int txqueue)
278275 {
279276 struct x25_asy *sl = netdev_priv(dev);
280277
....@@ -307,6 +304,14 @@
307304 return NETDEV_TX_OK;
308305 }
309306
307
+ /* There should be a pseudo header of 1 byte added by upper layers.
308
+ * Check to make sure it is there before reading it.
309
+ */
310
+ if (skb->len < 1) {
311
+ kfree_skb(skb);
312
+ return NETDEV_TX_OK;
313
+ }
314
+
310315 switch (skb->data[0]) {
311316 case X25_IFACE_DATA:
312317 break;
....@@ -322,7 +327,7 @@
322327 if (err != LAPB_OK)
323328 netdev_err(dev, "lapb_disconnect_request error: %d\n",
324329 err);
325
- /* fall through */
330
+ fallthrough;
326331 default:
327332 kfree_skb(skb);
328333 return NETDEV_TX_OK;
....@@ -456,7 +461,6 @@
456461 {
457462 struct x25_asy *sl = netdev_priv(dev);
458463 unsigned long len;
459
- int err;
460464
461465 if (sl->tty == NULL)
462466 return -ENODEV;
....@@ -482,14 +486,7 @@
482486 sl->xleft = 0;
483487 sl->flags &= (1 << SLF_INUSE); /* Clear ESCAPE & ERROR flags */
484488
485
- netif_start_queue(dev);
486
-
487
- /*
488
- * Now attach LAPB
489
- */
490
- err = lapb_register(dev, &x25_asy_callbacks);
491
- if (err == LAPB_OK)
492
- return 0;
489
+ return 0;
493490
494491 /* Cleanup */
495492 kfree(sl->xbuff);
....@@ -511,7 +508,6 @@
511508 if (sl->tty)
512509 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
513510
514
- netif_stop_queue(dev);
515511 sl->rcount = 0;
516512 sl->xleft = 0;
517513 spin_unlock(&sl->lock);
....@@ -596,7 +592,6 @@
596592 static void x25_asy_close_tty(struct tty_struct *tty)
597593 {
598594 struct x25_asy *sl = tty->disc_data;
599
- int err;
600595
601596 /* First make sure we're connected. */
602597 if (!sl || sl->magic != X25_ASY_MAGIC)
....@@ -606,11 +601,6 @@
606601 if (sl->dev->flags & IFF_UP)
607602 dev_close(sl->dev);
608603 rtnl_unlock();
609
-
610
- err = lapb_unregister(sl->dev);
611
- if (err != LAPB_OK)
612
- pr_err("x25_asy_close: lapb_unregister error: %d\n",
613
- err);
614604
615605 tty->disc_data = NULL;
616606 sl->tty = NULL;
....@@ -712,32 +702,41 @@
712702 }
713703 }
714704
715
-#ifdef CONFIG_COMPAT
716
-static long x25_asy_compat_ioctl(struct tty_struct *tty, struct file *file,
717
- unsigned int cmd, unsigned long arg)
718
-{
719
- switch (cmd) {
720
- case SIOCGIFNAME:
721
- case SIOCSIFHWADDR:
722
- return x25_asy_ioctl(tty, file, cmd,
723
- (unsigned long)compat_ptr(arg));
724
- }
725
-
726
- return -ENOIOCTLCMD;
727
-}
728
-#endif
729
-
730705 static int x25_asy_open_dev(struct net_device *dev)
731706 {
707
+ int err;
732708 struct x25_asy *sl = netdev_priv(dev);
733709 if (sl->tty == NULL)
734710 return -ENODEV;
711
+
712
+ err = lapb_register(dev, &x25_asy_callbacks);
713
+ if (err != LAPB_OK)
714
+ return -ENOMEM;
715
+
716
+ netif_start_queue(dev);
717
+
718
+ return 0;
719
+}
720
+
721
+static int x25_asy_close_dev(struct net_device *dev)
722
+{
723
+ int err;
724
+
725
+ netif_stop_queue(dev);
726
+
727
+ err = lapb_unregister(dev);
728
+ if (err != LAPB_OK)
729
+ pr_err("%s: lapb_unregister error: %d\n",
730
+ __func__, err);
731
+
732
+ x25_asy_close(dev);
733
+
735734 return 0;
736735 }
737736
738737 static const struct net_device_ops x25_asy_netdev_ops = {
739738 .ndo_open = x25_asy_open_dev,
740
- .ndo_stop = x25_asy_close,
739
+ .ndo_stop = x25_asy_close_dev,
741740 .ndo_start_xmit = x25_asy_xmit,
742741 .ndo_tx_timeout = x25_asy_timeout,
743742 .ndo_change_mtu = x25_asy_change_mtu,
....@@ -767,6 +766,12 @@
767766 dev->type = ARPHRD_X25;
768767 dev->tx_queue_len = 10;
769768
769
+ /* When transmitting data:
770
+ * first this driver removes a pseudo header of 1 byte,
771
+ * then the lapb module prepends an LAPB header of at most 3 bytes.
772
+ */
773
+ dev->needed_headroom = 3 - 1;
774
+
770775 /* New-style flags. */
771776 dev->flags = IFF_NOARP;
772777 }
....@@ -778,9 +783,6 @@
778783 .open = x25_asy_open_tty,
779784 .close = x25_asy_close_tty,
780785 .ioctl = x25_asy_ioctl,
781
-#ifdef CONFIG_COMPAT
782
- .compat_ioctl = x25_asy_compat_ioctl,
783
-#endif
784786 .receive_buf = x25_asy_receive_buf,
785787 .write_wakeup = x25_asy_write_wakeup,
786788 };