diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2007-11-19 10:03:38 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 18:04:01 -0500 |
commit | 9ce6cf25538de8036793a7e517674ede86e41f00 (patch) | |
tree | 7dbcb0b12d558d50136bdb2dcc19687ef49a1a29 /drivers | |
parent | a35f5de776cd2389603c2fd421eac7acaf07bd87 (diff) |
slip: Drag kicking and screaming into coding style compliance
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/slip.c | 367 |
1 files changed, 178 insertions, 189 deletions
diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 251a3ce376ac..5a55ede352f4 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c | |||
@@ -11,9 +11,11 @@ | |||
11 | * Fixes: | 11 | * Fixes: |
12 | * Alan Cox : Sanity checks and avoid tx overruns. | 12 | * Alan Cox : Sanity checks and avoid tx overruns. |
13 | * Has a new sl->mtu field. | 13 | * Has a new sl->mtu field. |
14 | * Alan Cox : Found cause of overrun. ifconfig sl0 mtu upwards. | 14 | * Alan Cox : Found cause of overrun. ifconfig sl0 |
15 | * Driver now spots this and grows/shrinks its buffers(hack!). | 15 | * mtu upwards. Driver now spots this |
16 | * Memory leak if you run out of memory setting up a slip driver fixed. | 16 | * and grows/shrinks its buffers(hack!). |
17 | * Memory leak if you run out of memory | ||
18 | * setting up a slip driver fixed. | ||
17 | * Matt Dillon : Printable slip (borrowed from NET2E) | 19 | * Matt Dillon : Printable slip (borrowed from NET2E) |
18 | * Pauline Middelink : Slip driver fixes. | 20 | * Pauline Middelink : Slip driver fixes. |
19 | * Alan Cox : Honours the old SL_COMPRESSED flag | 21 | * Alan Cox : Honours the old SL_COMPRESSED flag |
@@ -29,7 +31,8 @@ | |||
29 | * buffering from 4096 to 256 bytes. | 31 | * buffering from 4096 to 256 bytes. |
30 | * Improving SLIP response time. | 32 | * Improving SLIP response time. |
31 | * CONFIG_SLIP_MODE_SLIP6. | 33 | * CONFIG_SLIP_MODE_SLIP6. |
32 | * ifconfig sl? up & down now works correctly. | 34 | * ifconfig sl? up & down now works |
35 | * correctly. | ||
33 | * Modularization. | 36 | * Modularization. |
34 | * Alan Cox : Oops - fix AX.25 buffer lengths | 37 | * Alan Cox : Oops - fix AX.25 buffer lengths |
35 | * Dmitry Gorodchanin : Even more cleanups. Preserve CSLIP | 38 | * Dmitry Gorodchanin : Even more cleanups. Preserve CSLIP |
@@ -43,15 +46,18 @@ | |||
43 | * device entries, just reg./unreg. them | 46 | * device entries, just reg./unreg. them |
44 | * as they are needed. We kfree() them | 47 | * as they are needed. We kfree() them |
45 | * at module cleanup. | 48 | * at module cleanup. |
46 | * With MODULE-loading ``insmod'', user can | 49 | * With MODULE-loading ``insmod'', user |
47 | * issue parameter: slip_maxdev=1024 | 50 | * can issue parameter: slip_maxdev=1024 |
48 | * (Or how much he/she wants.. Default is 256) | 51 | * (Or how much he/she wants.. Default |
49 | * * Stanislav Voronyi : Slip line checking, with ideas taken | 52 | * is 256) |
50 | * from multislip BSDI driver which was written | 53 | * Stanislav Voronyi : Slip line checking, with ideas taken |
51 | * by Igor Chechik, RELCOM Corp. Only algorithms | 54 | * from multislip BSDI driver which was |
52 | * have been ported to Linux SLIP driver. | 55 | * written by Igor Chechik, RELCOM Corp. |
56 | * Only algorithms have been ported to | ||
57 | * Linux SLIP driver. | ||
53 | * Vitaly E. Lavrov : Sane behaviour on tty hangup. | 58 | * Vitaly E. Lavrov : Sane behaviour on tty hangup. |
54 | * Alexey Kuznetsov : Cleanup interfaces to tty&netdevice modules. | 59 | * Alexey Kuznetsov : Cleanup interfaces to tty & netdevice |
60 | * modules. | ||
55 | */ | 61 | */ |
56 | 62 | ||
57 | #define SL_CHECK_TRANSMIT | 63 | #define SL_CHECK_TRANSMIT |
@@ -99,7 +105,7 @@ static void slip_unesc6(struct slip *sl, unsigned char c); | |||
99 | #ifdef CONFIG_SLIP_SMART | 105 | #ifdef CONFIG_SLIP_SMART |
100 | static void sl_keepalive(unsigned long sls); | 106 | static void sl_keepalive(unsigned long sls); |
101 | static void sl_outfill(unsigned long sls); | 107 | static void sl_outfill(unsigned long sls); |
102 | static int sl_ioctl(struct net_device *dev,struct ifreq *rq,int cmd); | 108 | static int sl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
103 | #endif | 109 | #endif |
104 | 110 | ||
105 | /******************************** | 111 | /******************************** |
@@ -117,15 +123,14 @@ static int sl_ioctl(struct net_device *dev,struct ifreq *rq,int cmd); | |||
117 | Allocate channel buffers. | 123 | Allocate channel buffers. |
118 | */ | 124 | */ |
119 | 125 | ||
120 | static int | 126 | static int sl_alloc_bufs(struct slip *sl, int mtu) |
121 | sl_alloc_bufs(struct slip *sl, int mtu) | ||
122 | { | 127 | { |
123 | int err = -ENOBUFS; | 128 | int err = -ENOBUFS; |
124 | unsigned long len; | 129 | unsigned long len; |
125 | char * rbuff = NULL; | 130 | char *rbuff = NULL; |
126 | char * xbuff = NULL; | 131 | char *xbuff = NULL; |
127 | #ifdef SL_INCLUDE_CSLIP | 132 | #ifdef SL_INCLUDE_CSLIP |
128 | char * cbuff = NULL; | 133 | char *cbuff = NULL; |
129 | struct slcompress *slcomp = NULL; | 134 | struct slcompress *slcomp = NULL; |
130 | #endif | 135 | #endif |
131 | 136 | ||
@@ -195,8 +200,7 @@ err_exit: | |||
195 | } | 200 | } |
196 | 201 | ||
197 | /* Free a SLIP channel buffers. */ | 202 | /* Free a SLIP channel buffers. */ |
198 | static void | 203 | static void sl_free_bufs(struct slip *sl) |
199 | sl_free_bufs(struct slip *sl) | ||
200 | { | 204 | { |
201 | /* Free all SLIP frame buffers. */ | 205 | /* Free all SLIP frame buffers. */ |
202 | kfree(xchg(&sl->rbuff, NULL)); | 206 | kfree(xchg(&sl->rbuff, NULL)); |
@@ -248,7 +252,6 @@ static int sl_realloc_bufs(struct slip *sl, int mtu) | |||
248 | } | 252 | } |
249 | goto done; | 253 | goto done; |
250 | } | 254 | } |
251 | |||
252 | spin_lock_bh(&sl->lock); | 255 | spin_lock_bh(&sl->lock); |
253 | 256 | ||
254 | err = -ENODEV; | 257 | err = -ENODEV; |
@@ -298,23 +301,20 @@ done: | |||
298 | 301 | ||
299 | 302 | ||
300 | /* Set the "sending" flag. This must be atomic hence the set_bit. */ | 303 | /* Set the "sending" flag. This must be atomic hence the set_bit. */ |
301 | static inline void | 304 | static inline void sl_lock(struct slip *sl) |
302 | sl_lock(struct slip *sl) | ||
303 | { | 305 | { |
304 | netif_stop_queue(sl->dev); | 306 | netif_stop_queue(sl->dev); |
305 | } | 307 | } |
306 | 308 | ||
307 | 309 | ||
308 | /* Clear the "sending" flag. This must be atomic, hence the ASM. */ | 310 | /* Clear the "sending" flag. This must be atomic, hence the ASM. */ |
309 | static inline void | 311 | static inline void sl_unlock(struct slip *sl) |
310 | sl_unlock(struct slip *sl) | ||
311 | { | 312 | { |
312 | netif_wake_queue(sl->dev); | 313 | netif_wake_queue(sl->dev); |
313 | } | 314 | } |
314 | 315 | ||
315 | /* Send one completely decapsulated IP datagram to the IP layer. */ | 316 | /* Send one completely decapsulated IP datagram to the IP layer. */ |
316 | static void | 317 | static void sl_bump(struct slip *sl) |
317 | sl_bump(struct slip *sl) | ||
318 | { | 318 | { |
319 | struct sk_buff *skb; | 319 | struct sk_buff *skb; |
320 | int count; | 320 | int count; |
@@ -322,22 +322,22 @@ sl_bump(struct slip *sl) | |||
322 | count = sl->rcount; | 322 | count = sl->rcount; |
323 | #ifdef SL_INCLUDE_CSLIP | 323 | #ifdef SL_INCLUDE_CSLIP |
324 | if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) { | 324 | if (sl->mode & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) { |
325 | unsigned char c; | 325 | unsigned char c = sl->rbuff[0]; |
326 | if ((c = sl->rbuff[0]) & SL_TYPE_COMPRESSED_TCP) { | 326 | if (c & SL_TYPE_COMPRESSED_TCP) { |
327 | /* ignore compressed packets when CSLIP is off */ | 327 | /* ignore compressed packets when CSLIP is off */ |
328 | if (!(sl->mode & SL_MODE_CSLIP)) { | 328 | if (!(sl->mode & SL_MODE_CSLIP)) { |
329 | printk(KERN_WARNING "%s: compressed packet ignored\n", sl->dev->name); | 329 | printk(KERN_WARNING "%s: compressed packet ignored\n", sl->dev->name); |
330 | return; | 330 | return; |
331 | } | 331 | } |
332 | /* make sure we've reserved enough space for uncompress to use */ | 332 | /* make sure we've reserved enough space for uncompress |
333 | to use */ | ||
333 | if (count + 80 > sl->buffsize) { | 334 | if (count + 80 > sl->buffsize) { |
334 | sl->rx_over_errors++; | 335 | sl->rx_over_errors++; |
335 | return; | 336 | return; |
336 | } | 337 | } |
337 | count = slhc_uncompress(sl->slcomp, sl->rbuff, count); | 338 | count = slhc_uncompress(sl->slcomp, sl->rbuff, count); |
338 | if (count <= 0) { | 339 | if (count <= 0) |
339 | return; | 340 | return; |
340 | } | ||
341 | } else if (c >= SL_TYPE_UNCOMPRESSED_TCP) { | 341 | } else if (c >= SL_TYPE_UNCOMPRESSED_TCP) { |
342 | if (!(sl->mode & SL_MODE_CSLIP)) { | 342 | if (!(sl->mode & SL_MODE_CSLIP)) { |
343 | /* turn on header compression */ | 343 | /* turn on header compression */ |
@@ -346,33 +346,31 @@ sl_bump(struct slip *sl) | |||
346 | printk(KERN_INFO "%s: header compression turned on\n", sl->dev->name); | 346 | printk(KERN_INFO "%s: header compression turned on\n", sl->dev->name); |
347 | } | 347 | } |
348 | sl->rbuff[0] &= 0x4f; | 348 | sl->rbuff[0] &= 0x4f; |
349 | if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0) { | 349 | if (slhc_remember(sl->slcomp, sl->rbuff, count) <= 0) |
350 | return; | 350 | return; |
351 | } | ||
352 | } | 351 | } |
353 | } | 352 | } |
354 | #endif /* SL_INCLUDE_CSLIP */ | 353 | #endif /* SL_INCLUDE_CSLIP */ |
355 | 354 | ||
356 | sl->rx_bytes+=count; | 355 | sl->rx_bytes += count; |
357 | 356 | ||
358 | skb = dev_alloc_skb(count); | 357 | skb = dev_alloc_skb(count); |
359 | if (skb == NULL) { | 358 | if (skb == NULL) { |
360 | printk(KERN_WARNING "%s: memory squeeze, dropping packet.\n", sl->dev->name); | 359 | printk(KERN_WARNING "%s: memory squeeze, dropping packet.\n", sl->dev->name); |
361 | sl->rx_dropped++; | 360 | sl->rx_dropped++; |
362 | return; | 361 | return; |
363 | } | 362 | } |
364 | skb->dev = sl->dev; | 363 | skb->dev = sl->dev; |
365 | memcpy(skb_put(skb,count), sl->rbuff, count); | 364 | memcpy(skb_put(skb, count), sl->rbuff, count); |
366 | skb_reset_mac_header(skb); | 365 | skb_reset_mac_header(skb); |
367 | skb->protocol=htons(ETH_P_IP); | 366 | skb->protocol = htons(ETH_P_IP); |
368 | netif_rx(skb); | 367 | netif_rx(skb); |
369 | sl->dev->last_rx = jiffies; | 368 | sl->dev->last_rx = jiffies; |
370 | sl->rx_packets++; | 369 | sl->rx_packets++; |
371 | } | 370 | } |
372 | 371 | ||
373 | /* Encapsulate one IP datagram and stuff into a TTY queue. */ | 372 | /* Encapsulate one IP datagram and stuff into a TTY queue. */ |
374 | static void | 373 | static void sl_encaps(struct slip *sl, unsigned char *icp, int len) |
375 | sl_encaps(struct slip *sl, unsigned char *icp, int len) | ||
376 | { | 374 | { |
377 | unsigned char *p; | 375 | unsigned char *p; |
378 | int actual, count; | 376 | int actual, count; |
@@ -386,12 +384,11 @@ sl_encaps(struct slip *sl, unsigned char *icp, int len) | |||
386 | 384 | ||
387 | p = icp; | 385 | p = icp; |
388 | #ifdef SL_INCLUDE_CSLIP | 386 | #ifdef SL_INCLUDE_CSLIP |
389 | if (sl->mode & SL_MODE_CSLIP) { | 387 | if (sl->mode & SL_MODE_CSLIP) |
390 | len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1); | 388 | len = slhc_compress(sl->slcomp, p, len, sl->cbuff, &p, 1); |
391 | } | ||
392 | #endif | 389 | #endif |
393 | #ifdef CONFIG_SLIP_MODE_SLIP6 | 390 | #ifdef CONFIG_SLIP_MODE_SLIP6 |
394 | if(sl->mode & SL_MODE_SLIP6) | 391 | if (sl->mode & SL_MODE_SLIP6) |
395 | count = slip_esc6(p, (unsigned char *) sl->xbuff, len); | 392 | count = slip_esc6(p, (unsigned char *) sl->xbuff, len); |
396 | else | 393 | else |
397 | #endif | 394 | #endif |
@@ -425,12 +422,12 @@ sl_encaps(struct slip *sl, unsigned char *icp, int len) | |||
425 | static void slip_write_wakeup(struct tty_struct *tty) | 422 | static void slip_write_wakeup(struct tty_struct *tty) |
426 | { | 423 | { |
427 | int actual; | 424 | int actual; |
428 | struct slip *sl = (struct slip *) tty->disc_data; | 425 | struct slip *sl = tty->disc_data; |
429 | 426 | ||
430 | /* First make sure we're connected. */ | 427 | /* First make sure we're connected. */ |
431 | if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) { | 428 | if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) |
432 | return; | 429 | return; |
433 | } | 430 | |
434 | if (sl->xleft <= 0) { | 431 | if (sl->xleft <= 0) { |
435 | /* Now serial buffer is almost free & we can start | 432 | /* Now serial buffer is almost free & we can start |
436 | * transmission of another packet */ | 433 | * transmission of another packet */ |
@@ -463,15 +460,15 @@ static void sl_tx_timeout(struct net_device *dev) | |||
463 | /* 20 sec timeout not reached */ | 460 | /* 20 sec timeout not reached */ |
464 | goto out; | 461 | goto out; |
465 | } | 462 | } |
466 | printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, | 463 | printk(KERN_WARNING "%s: transmit timed out, %s?\n", |
467 | (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? | 464 | dev->name, |
468 | "bad line quality" : "driver error"); | 465 | (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? |
466 | "bad line quality" : "driver error"); | ||
469 | sl->xleft = 0; | 467 | sl->xleft = 0; |
470 | sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); | 468 | sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); |
471 | sl_unlock(sl); | 469 | sl_unlock(sl); |
472 | #endif | 470 | #endif |
473 | } | 471 | } |
474 | |||
475 | out: | 472 | out: |
476 | spin_unlock(&sl->lock); | 473 | spin_unlock(&sl->lock); |
477 | } | 474 | } |
@@ -484,7 +481,7 @@ sl_xmit(struct sk_buff *skb, struct net_device *dev) | |||
484 | struct slip *sl = netdev_priv(dev); | 481 | struct slip *sl = netdev_priv(dev); |
485 | 482 | ||
486 | spin_lock(&sl->lock); | 483 | spin_lock(&sl->lock); |
487 | if (!netif_running(dev)) { | 484 | if (!netif_running(dev)) { |
488 | spin_unlock(&sl->lock); | 485 | spin_unlock(&sl->lock); |
489 | printk(KERN_WARNING "%s: xmit call when iface is down\n", dev->name); | 486 | printk(KERN_WARNING "%s: xmit call when iface is down\n", dev->name); |
490 | dev_kfree_skb(skb); | 487 | dev_kfree_skb(skb); |
@@ -497,7 +494,7 @@ sl_xmit(struct sk_buff *skb, struct net_device *dev) | |||
497 | } | 494 | } |
498 | 495 | ||
499 | sl_lock(sl); | 496 | sl_lock(sl); |
500 | sl->tx_bytes+=skb->len; | 497 | sl->tx_bytes += skb->len; |
501 | sl_encaps(sl, skb->data, skb->len); | 498 | sl_encaps(sl, skb->data, skb->len); |
502 | spin_unlock(&sl->lock); | 499 | spin_unlock(&sl->lock); |
503 | 500 | ||
@@ -536,7 +533,7 @@ static int sl_open(struct net_device *dev) | |||
536 | { | 533 | { |
537 | struct slip *sl = netdev_priv(dev); | 534 | struct slip *sl = netdev_priv(dev); |
538 | 535 | ||
539 | if (sl->tty==NULL) | 536 | if (sl->tty == NULL) |
540 | return -ENODEV; | 537 | return -ENODEV; |
541 | 538 | ||
542 | sl->flags &= (1 << SLF_INUSE); | 539 | sl->flags &= (1 << SLF_INUSE); |
@@ -657,20 +654,19 @@ static void sl_setup(struct net_device *dev) | |||
657 | * in parallel | 654 | * in parallel |
658 | */ | 655 | */ |
659 | 656 | ||
660 | static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) | 657 | static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, |
658 | char *fp, int count) | ||
661 | { | 659 | { |
662 | struct slip *sl = (struct slip *) tty->disc_data; | 660 | struct slip *sl = tty->disc_data; |
663 | 661 | ||
664 | if (!sl || sl->magic != SLIP_MAGIC || | 662 | if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) |
665 | !netif_running(sl->dev)) | ||
666 | return; | 663 | return; |
667 | 664 | ||
668 | /* Read the characters out of the buffer */ | 665 | /* Read the characters out of the buffer */ |
669 | while (count--) { | 666 | while (count--) { |
670 | if (fp && *fp++) { | 667 | if (fp && *fp++) { |
671 | if (!test_and_set_bit(SLF_ERROR, &sl->flags)) { | 668 | if (!test_and_set_bit(SLF_ERROR, &sl->flags)) |
672 | sl->rx_errors++; | 669 | sl->rx_errors++; |
673 | } | ||
674 | cp++; | 670 | cp++; |
675 | continue; | 671 | continue; |
676 | } | 672 | } |
@@ -688,7 +684,6 @@ static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ch | |||
688 | ************************************/ | 684 | ************************************/ |
689 | 685 | ||
690 | /* Collect hanged up channels */ | 686 | /* Collect hanged up channels */ |
691 | |||
692 | static void sl_sync(void) | 687 | static void sl_sync(void) |
693 | { | 688 | { |
694 | int i; | 689 | int i; |
@@ -696,21 +691,21 @@ static void sl_sync(void) | |||
696 | struct slip *sl; | 691 | struct slip *sl; |
697 | 692 | ||
698 | for (i = 0; i < slip_maxdev; i++) { | 693 | for (i = 0; i < slip_maxdev; i++) { |
699 | if ((dev = slip_devs[i]) == NULL) | 694 | dev = slip_devs[i]; |
695 | if (dev == NULL) | ||
700 | break; | 696 | break; |
701 | 697 | ||
702 | sl = netdev_priv(dev); | 698 | sl = netdev_priv(dev); |
703 | if (sl->tty || sl->leased) | 699 | if (sl->tty || sl->leased) |
704 | continue; | 700 | continue; |
705 | if (dev->flags&IFF_UP) | 701 | if (dev->flags & IFF_UP) |
706 | dev_close(dev); | 702 | dev_close(dev); |
707 | } | 703 | } |
708 | } | 704 | } |
709 | 705 | ||
710 | 706 | ||
711 | /* Find a free SLIP channel, and link in this `tty' line. */ | 707 | /* Find a free SLIP channel, and link in this `tty' line. */ |
712 | static struct slip * | 708 | static struct slip *sl_alloc(dev_t line) |
713 | sl_alloc(dev_t line) | ||
714 | { | 709 | { |
715 | int i; | 710 | int i; |
716 | int sel = -1; | 711 | int sel = -1; |
@@ -805,15 +800,15 @@ sl_alloc(dev_t line) | |||
805 | spin_lock_init(&sl->lock); | 800 | spin_lock_init(&sl->lock); |
806 | sl->mode = SL_MODE_DEFAULT; | 801 | sl->mode = SL_MODE_DEFAULT; |
807 | #ifdef CONFIG_SLIP_SMART | 802 | #ifdef CONFIG_SLIP_SMART |
808 | init_timer(&sl->keepalive_timer); /* initialize timer_list struct */ | 803 | /* initialize timer_list struct */ |
809 | sl->keepalive_timer.data=(unsigned long)sl; | 804 | init_timer(&sl->keepalive_timer); |
810 | sl->keepalive_timer.function=sl_keepalive; | 805 | sl->keepalive_timer.data = (unsigned long)sl; |
806 | sl->keepalive_timer.function = sl_keepalive; | ||
811 | init_timer(&sl->outfill_timer); | 807 | init_timer(&sl->outfill_timer); |
812 | sl->outfill_timer.data=(unsigned long)sl; | 808 | sl->outfill_timer.data = (unsigned long)sl; |
813 | sl->outfill_timer.function=sl_outfill; | 809 | sl->outfill_timer.function = sl_outfill; |
814 | #endif | 810 | #endif |
815 | slip_devs[i] = dev; | 811 | slip_devs[i] = dev; |
816 | |||
817 | return sl; | 812 | return sl; |
818 | } | 813 | } |
819 | 814 | ||
@@ -832,7 +827,7 @@ static int slip_open(struct tty_struct *tty) | |||
832 | struct slip *sl; | 827 | struct slip *sl; |
833 | int err; | 828 | int err; |
834 | 829 | ||
835 | if(!capable(CAP_NET_ADMIN)) | 830 | if (!capable(CAP_NET_ADMIN)) |
836 | return -EPERM; | 831 | return -EPERM; |
837 | 832 | ||
838 | /* RTnetlink lock is misused here to serialize concurrent | 833 | /* RTnetlink lock is misused here to serialize concurrent |
@@ -844,7 +839,7 @@ static int slip_open(struct tty_struct *tty) | |||
844 | /* Collect hanged up channels. */ | 839 | /* Collect hanged up channels. */ |
845 | sl_sync(); | 840 | sl_sync(); |
846 | 841 | ||
847 | sl = (struct slip *) tty->disc_data; | 842 | sl = tty->disc_data; |
848 | 843 | ||
849 | err = -EEXIST; | 844 | err = -EEXIST; |
850 | /* First make sure we're not already connected. */ | 845 | /* First make sure we're not already connected. */ |
@@ -853,7 +848,8 @@ static int slip_open(struct tty_struct *tty) | |||
853 | 848 | ||
854 | /* OK. Find a free SLIP channel to use. */ | 849 | /* OK. Find a free SLIP channel to use. */ |
855 | err = -ENFILE; | 850 | err = -ENFILE; |
856 | if ((sl = sl_alloc(tty_devnum(tty))) == NULL) | 851 | sl = sl_alloc(tty_devnum(tty)); |
852 | if (sl == NULL) | ||
857 | goto err_exit; | 853 | goto err_exit; |
858 | 854 | ||
859 | sl->tty = tty; | 855 | sl->tty = tty; |
@@ -863,23 +859,25 @@ static int slip_open(struct tty_struct *tty) | |||
863 | 859 | ||
864 | if (!test_bit(SLF_INUSE, &sl->flags)) { | 860 | if (!test_bit(SLF_INUSE, &sl->flags)) { |
865 | /* Perform the low-level SLIP initialization. */ | 861 | /* Perform the low-level SLIP initialization. */ |
866 | if ((err = sl_alloc_bufs(sl, SL_MTU)) != 0) | 862 | err = sl_alloc_bufs(sl, SL_MTU); |
863 | if (err) | ||
867 | goto err_free_chan; | 864 | goto err_free_chan; |
868 | 865 | ||
869 | set_bit(SLF_INUSE, &sl->flags); | 866 | set_bit(SLF_INUSE, &sl->flags); |
870 | 867 | ||
871 | if ((err = register_netdevice(sl->dev))) | 868 | err = register_netdevice(sl->dev); |
869 | if (err) | ||
872 | goto err_free_bufs; | 870 | goto err_free_bufs; |
873 | } | 871 | } |
874 | 872 | ||
875 | #ifdef CONFIG_SLIP_SMART | 873 | #ifdef CONFIG_SLIP_SMART |
876 | if (sl->keepalive) { | 874 | if (sl->keepalive) { |
877 | sl->keepalive_timer.expires=jiffies+sl->keepalive*HZ; | 875 | sl->keepalive_timer.expires = jiffies + sl->keepalive * HZ; |
878 | add_timer (&sl->keepalive_timer); | 876 | add_timer(&sl->keepalive_timer); |
879 | } | 877 | } |
880 | if (sl->outfill) { | 878 | if (sl->outfill) { |
881 | sl->outfill_timer.expires=jiffies+sl->outfill*HZ; | 879 | sl->outfill_timer.expires = jiffies + sl->outfill * HZ; |
882 | add_timer (&sl->outfill_timer); | 880 | add_timer(&sl->outfill_timer); |
883 | } | 881 | } |
884 | #endif | 882 | #endif |
885 | 883 | ||
@@ -928,10 +926,9 @@ err_exit: | |||
928 | * This means flushing out any pending queues, and then returning. This | 926 | * This means flushing out any pending queues, and then returning. This |
929 | * call is serialized against other ldisc functions. | 927 | * call is serialized against other ldisc functions. |
930 | */ | 928 | */ |
931 | static void | 929 | static void slip_close(struct tty_struct *tty) |
932 | slip_close(struct tty_struct *tty) | ||
933 | { | 930 | { |
934 | struct slip *sl = (struct slip *) tty->disc_data; | 931 | struct slip *sl = tty->disc_data; |
935 | 932 | ||
936 | /* First make sure we're connected. */ | 933 | /* First make sure we're connected. */ |
937 | if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty) | 934 | if (!sl || sl->magic != SLIP_MAGIC || sl->tty != tty) |
@@ -955,8 +952,7 @@ slip_close(struct tty_struct *tty) | |||
955 | * STANDARD SLIP ENCAPSULATION * | 952 | * STANDARD SLIP ENCAPSULATION * |
956 | ************************************************************************/ | 953 | ************************************************************************/ |
957 | 954 | ||
958 | static int | 955 | static int slip_esc(unsigned char *s, unsigned char *d, int len) |
959 | slip_esc(unsigned char *s, unsigned char *d, int len) | ||
960 | { | 956 | { |
961 | unsigned char *ptr = d; | 957 | unsigned char *ptr = d; |
962 | unsigned char c; | 958 | unsigned char c; |
@@ -975,16 +971,16 @@ slip_esc(unsigned char *s, unsigned char *d, int len) | |||
975 | */ | 971 | */ |
976 | 972 | ||
977 | while (len-- > 0) { | 973 | while (len-- > 0) { |
978 | switch(c = *s++) { | 974 | switch (c = *s++) { |
979 | case END: | 975 | case END: |
980 | *ptr++ = ESC; | 976 | *ptr++ = ESC; |
981 | *ptr++ = ESC_END; | 977 | *ptr++ = ESC_END; |
982 | break; | 978 | break; |
983 | case ESC: | 979 | case ESC: |
984 | *ptr++ = ESC; | 980 | *ptr++ = ESC; |
985 | *ptr++ = ESC_ESC; | 981 | *ptr++ = ESC_ESC; |
986 | break; | 982 | break; |
987 | default: | 983 | default: |
988 | *ptr++ = c; | 984 | *ptr++ = c; |
989 | break; | 985 | break; |
990 | } | 986 | } |
@@ -996,33 +992,31 @@ slip_esc(unsigned char *s, unsigned char *d, int len) | |||
996 | static void slip_unesc(struct slip *sl, unsigned char s) | 992 | static void slip_unesc(struct slip *sl, unsigned char s) |
997 | { | 993 | { |
998 | 994 | ||
999 | switch(s) { | 995 | switch (s) { |
1000 | case END: | 996 | case END: |
1001 | #ifdef CONFIG_SLIP_SMART | 997 | #ifdef CONFIG_SLIP_SMART |
1002 | /* drop keeptest bit = VSV */ | 998 | /* drop keeptest bit = VSV */ |
1003 | if (test_bit(SLF_KEEPTEST, &sl->flags)) | 999 | if (test_bit(SLF_KEEPTEST, &sl->flags)) |
1004 | clear_bit(SLF_KEEPTEST, &sl->flags); | 1000 | clear_bit(SLF_KEEPTEST, &sl->flags); |
1005 | #endif | 1001 | #endif |
1006 | 1002 | ||
1007 | if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) { | 1003 | if (!test_and_clear_bit(SLF_ERROR, &sl->flags) |
1004 | && (sl->rcount > 2)) | ||
1008 | sl_bump(sl); | 1005 | sl_bump(sl); |
1009 | } | ||
1010 | clear_bit(SLF_ESCAPE, &sl->flags); | 1006 | clear_bit(SLF_ESCAPE, &sl->flags); |
1011 | sl->rcount = 0; | 1007 | sl->rcount = 0; |
1012 | return; | 1008 | return; |
1013 | 1009 | ||
1014 | case ESC: | 1010 | case ESC: |
1015 | set_bit(SLF_ESCAPE, &sl->flags); | 1011 | set_bit(SLF_ESCAPE, &sl->flags); |
1016 | return; | 1012 | return; |
1017 | case ESC_ESC: | 1013 | case ESC_ESC: |
1018 | if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) { | 1014 | if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) |
1019 | s = ESC; | 1015 | s = ESC; |
1020 | } | ||
1021 | break; | 1016 | break; |
1022 | case ESC_END: | 1017 | case ESC_END: |
1023 | if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) { | 1018 | if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) |
1024 | s = END; | 1019 | s = END; |
1025 | } | ||
1026 | break; | 1020 | break; |
1027 | } | 1021 | } |
1028 | if (!test_bit(SLF_ERROR, &sl->flags)) { | 1022 | if (!test_bit(SLF_ERROR, &sl->flags)) { |
@@ -1041,8 +1035,7 @@ static void slip_unesc(struct slip *sl, unsigned char s) | |||
1041 | * 6 BIT SLIP ENCAPSULATION * | 1035 | * 6 BIT SLIP ENCAPSULATION * |
1042 | ************************************************************************/ | 1036 | ************************************************************************/ |
1043 | 1037 | ||
1044 | int | 1038 | static int slip_esc6(unsigned char *s, unsigned char *d, int len) |
1045 | slip_esc6(unsigned char *s, unsigned char *d, int len) | ||
1046 | { | 1039 | { |
1047 | unsigned char *ptr = d; | 1040 | unsigned char *ptr = d; |
1048 | unsigned char c; | 1041 | unsigned char c; |
@@ -1079,8 +1072,7 @@ slip_esc6(unsigned char *s, unsigned char *d, int len) | |||
1079 | return ptr - d; | 1072 | return ptr - d; |
1080 | } | 1073 | } |
1081 | 1074 | ||
1082 | void | 1075 | static void slip_unesc6(struct slip *sl, unsigned char s) |
1083 | slip_unesc6(struct slip *sl, unsigned char s) | ||
1084 | { | 1076 | { |
1085 | unsigned char c; | 1077 | unsigned char c; |
1086 | 1078 | ||
@@ -1091,13 +1083,13 @@ slip_unesc6(struct slip *sl, unsigned char s) | |||
1091 | clear_bit(SLF_KEEPTEST, &sl->flags); | 1083 | clear_bit(SLF_KEEPTEST, &sl->flags); |
1092 | #endif | 1084 | #endif |
1093 | 1085 | ||
1094 | if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) { | 1086 | if (!test_and_clear_bit(SLF_ERROR, &sl->flags) |
1087 | && (sl->rcount > 2)) | ||
1095 | sl_bump(sl); | 1088 | sl_bump(sl); |
1096 | } | ||
1097 | sl->rcount = 0; | 1089 | sl->rcount = 0; |
1098 | sl->xbits = 0; | 1090 | sl->xbits = 0; |
1099 | sl->xdata = 0; | 1091 | sl->xdata = 0; |
1100 | } else if (s >= 0x30 && s < 0x70) { | 1092 | } else if (s >= 0x30 && s < 0x70) { |
1101 | sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F); | 1093 | sl->xdata = (sl->xdata << 6) | ((s - 0x30) & 0x3F); |
1102 | sl->xbits += 6; | 1094 | sl->xbits += 6; |
1103 | if (sl->xbits >= 8) { | 1095 | if (sl->xbits >= 8) { |
@@ -1112,24 +1104,24 @@ slip_unesc6(struct slip *sl, unsigned char s) | |||
1112 | set_bit(SLF_ERROR, &sl->flags); | 1104 | set_bit(SLF_ERROR, &sl->flags); |
1113 | } | 1105 | } |
1114 | } | 1106 | } |
1115 | } | 1107 | } |
1116 | } | 1108 | } |
1117 | #endif /* CONFIG_SLIP_MODE_SLIP6 */ | 1109 | #endif /* CONFIG_SLIP_MODE_SLIP6 */ |
1118 | 1110 | ||
1119 | /* Perform I/O control on an active SLIP channel. */ | 1111 | /* Perform I/O control on an active SLIP channel. */ |
1120 | static int slip_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 1112 | static int slip_ioctl(struct tty_struct *tty, struct file *file, |
1113 | unsigned int cmd, unsigned long arg) | ||
1121 | { | 1114 | { |
1122 | struct slip *sl = (struct slip *) tty->disc_data; | 1115 | struct slip *sl = tty->disc_data; |
1123 | unsigned int tmp; | 1116 | unsigned int tmp; |
1124 | int __user *p = (int __user *)arg; | 1117 | int __user *p = (int __user *)arg; |
1125 | 1118 | ||
1126 | /* First make sure we're connected. */ | 1119 | /* First make sure we're connected. */ |
1127 | if (!sl || sl->magic != SLIP_MAGIC) { | 1120 | if (!sl || sl->magic != SLIP_MAGIC) |
1128 | return -EINVAL; | 1121 | return -EINVAL; |
1129 | } | ||
1130 | 1122 | ||
1131 | switch(cmd) { | 1123 | switch (cmd) { |
1132 | case SIOCGIFNAME: | 1124 | case SIOCGIFNAME: |
1133 | tmp = strlen(sl->dev->name) + 1; | 1125 | tmp = strlen(sl->dev->name) + 1; |
1134 | if (copy_to_user((void __user *)arg, sl->dev->name, tmp)) | 1126 | if (copy_to_user((void __user *)arg, sl->dev->name, tmp)) |
1135 | return -EFAULT; | 1127 | return -EFAULT; |
@@ -1144,34 +1136,31 @@ static int slip_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm | |||
1144 | if (get_user(tmp, p)) | 1136 | if (get_user(tmp, p)) |
1145 | return -EFAULT; | 1137 | return -EFAULT; |
1146 | #ifndef SL_INCLUDE_CSLIP | 1138 | #ifndef SL_INCLUDE_CSLIP |
1147 | if (tmp & (SL_MODE_CSLIP|SL_MODE_ADAPTIVE)) { | 1139 | if (tmp & (SL_MODE_CSLIP|SL_MODE_ADAPTIVE)) |
1148 | return -EINVAL; | 1140 | return -EINVAL; |
1149 | } | ||
1150 | #else | 1141 | #else |
1151 | if ((tmp & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) == | 1142 | if ((tmp & (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) == |
1152 | (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) { | 1143 | (SL_MODE_ADAPTIVE | SL_MODE_CSLIP)) |
1153 | /* return -EINVAL; */ | 1144 | /* return -EINVAL; */ |
1154 | tmp &= ~SL_MODE_ADAPTIVE; | 1145 | tmp &= ~SL_MODE_ADAPTIVE; |
1155 | } | ||
1156 | #endif | 1146 | #endif |
1157 | #ifndef CONFIG_SLIP_MODE_SLIP6 | 1147 | #ifndef CONFIG_SLIP_MODE_SLIP6 |
1158 | if (tmp & SL_MODE_SLIP6) { | 1148 | if (tmp & SL_MODE_SLIP6) |
1159 | return -EINVAL; | 1149 | return -EINVAL; |
1160 | } | ||
1161 | #endif | 1150 | #endif |
1162 | sl->mode = tmp; | 1151 | sl->mode = tmp; |
1163 | sl->dev->type = ARPHRD_SLIP+sl->mode; | 1152 | sl->dev->type = ARPHRD_SLIP + sl->mode; |
1164 | return 0; | 1153 | return 0; |
1165 | 1154 | ||
1166 | case SIOCSIFHWADDR: | 1155 | case SIOCSIFHWADDR: |
1167 | return -EINVAL; | 1156 | return -EINVAL; |
1168 | 1157 | ||
1169 | #ifdef CONFIG_SLIP_SMART | 1158 | #ifdef CONFIG_SLIP_SMART |
1170 | /* VSV changes start here */ | 1159 | /* VSV changes start here */ |
1171 | case SIOCSKEEPALIVE: | 1160 | case SIOCSKEEPALIVE: |
1172 | if (get_user(tmp, p)) | 1161 | if (get_user(tmp, p)) |
1173 | return -EFAULT; | 1162 | return -EFAULT; |
1174 | if (tmp > 255) /* max for unchar */ | 1163 | if (tmp > 255) /* max for unchar */ |
1175 | return -EINVAL; | 1164 | return -EINVAL; |
1176 | 1165 | ||
1177 | spin_lock_bh(&sl->lock); | 1166 | spin_lock_bh(&sl->lock); |
@@ -1179,40 +1168,42 @@ static int slip_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm | |||
1179 | spin_unlock_bh(&sl->lock); | 1168 | spin_unlock_bh(&sl->lock); |
1180 | return -ENODEV; | 1169 | return -ENODEV; |
1181 | } | 1170 | } |
1182 | if ((sl->keepalive = (unchar) tmp) != 0) { | 1171 | sl->keepalive = (u8)tmp; |
1183 | mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ); | 1172 | if (sl->keepalive != 0) { |
1173 | mod_timer(&sl->keepalive_timer, | ||
1174 | jiffies + sl->keepalive * HZ); | ||
1184 | set_bit(SLF_KEEPTEST, &sl->flags); | 1175 | set_bit(SLF_KEEPTEST, &sl->flags); |
1185 | } else { | 1176 | } else |
1186 | del_timer (&sl->keepalive_timer); | 1177 | del_timer(&sl->keepalive_timer); |
1187 | } | ||
1188 | spin_unlock_bh(&sl->lock); | 1178 | spin_unlock_bh(&sl->lock); |
1189 | return 0; | 1179 | return 0; |
1190 | 1180 | ||
1191 | case SIOCGKEEPALIVE: | 1181 | case SIOCGKEEPALIVE: |
1192 | if (put_user(sl->keepalive, p)) | 1182 | if (put_user(sl->keepalive, p)) |
1193 | return -EFAULT; | 1183 | return -EFAULT; |
1194 | return 0; | 1184 | return 0; |
1195 | 1185 | ||
1196 | case SIOCSOUTFILL: | 1186 | case SIOCSOUTFILL: |
1197 | if (get_user(tmp, p)) | 1187 | if (get_user(tmp, p)) |
1198 | return -EFAULT; | 1188 | return -EFAULT; |
1199 | if (tmp > 255) /* max for unchar */ | 1189 | if (tmp > 255) /* max for unchar */ |
1200 | return -EINVAL; | 1190 | return -EINVAL; |
1201 | spin_lock_bh(&sl->lock); | 1191 | spin_lock_bh(&sl->lock); |
1202 | if (!sl->tty) { | 1192 | if (!sl->tty) { |
1203 | spin_unlock_bh(&sl->lock); | 1193 | spin_unlock_bh(&sl->lock); |
1204 | return -ENODEV; | 1194 | return -ENODEV; |
1205 | } | 1195 | } |
1206 | if ((sl->outfill = (unchar) tmp) != 0){ | 1196 | sl->outfill = (u8)tmp; |
1207 | mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ); | 1197 | if (sl->outfill != 0) { |
1198 | mod_timer(&sl->outfill_timer, | ||
1199 | jiffies + sl->outfill * HZ); | ||
1208 | set_bit(SLF_OUTWAIT, &sl->flags); | 1200 | set_bit(SLF_OUTWAIT, &sl->flags); |
1209 | } else { | 1201 | } else |
1210 | del_timer (&sl->outfill_timer); | 1202 | del_timer(&sl->outfill_timer); |
1211 | } | ||
1212 | spin_unlock_bh(&sl->lock); | 1203 | spin_unlock_bh(&sl->lock); |
1213 | return 0; | 1204 | return 0; |
1214 | 1205 | ||
1215 | case SIOCGOUTFILL: | 1206 | case SIOCGOUTFILL: |
1216 | if (put_user(sl->outfill, p)) | 1207 | if (put_user(sl->outfill, p)) |
1217 | return -EFAULT; | 1208 | return -EFAULT; |
1218 | return 0; | 1209 | return 0; |
@@ -1229,7 +1220,7 @@ static int slip_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm | |||
1229 | to allow get/set outfill/keepalive parameter | 1220 | to allow get/set outfill/keepalive parameter |
1230 | by ifconfig */ | 1221 | by ifconfig */ |
1231 | 1222 | ||
1232 | static int sl_ioctl(struct net_device *dev,struct ifreq *rq,int cmd) | 1223 | static int sl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
1233 | { | 1224 | { |
1234 | struct slip *sl = netdev_priv(dev); | 1225 | struct slip *sl = netdev_priv(dev); |
1235 | unsigned long *p = (unsigned long *)&rq->ifr_ifru; | 1226 | unsigned long *p = (unsigned long *)&rq->ifr_ifru; |
@@ -1244,58 +1235,61 @@ static int sl_ioctl(struct net_device *dev,struct ifreq *rq,int cmd) | |||
1244 | return -ENODEV; | 1235 | return -ENODEV; |
1245 | } | 1236 | } |
1246 | 1237 | ||
1247 | switch(cmd){ | 1238 | switch (cmd) { |
1248 | case SIOCSKEEPALIVE: | 1239 | case SIOCSKEEPALIVE: |
1249 | /* max for unchar */ | 1240 | /* max for unchar */ |
1250 | if ((unsigned)*p > 255) { | 1241 | if ((unsigned)*p > 255) { |
1251 | spin_unlock_bh(&sl->lock); | 1242 | spin_unlock_bh(&sl->lock); |
1252 | return -EINVAL; | 1243 | return -EINVAL; |
1253 | } | 1244 | } |
1254 | sl->keepalive = (unchar) *p; | 1245 | sl->keepalive = (u8)*p; |
1255 | if (sl->keepalive != 0) { | 1246 | if (sl->keepalive != 0) { |
1256 | sl->keepalive_timer.expires=jiffies+sl->keepalive*HZ; | 1247 | sl->keepalive_timer.expires = |
1257 | mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ); | 1248 | jiffies + sl->keepalive * HZ; |
1249 | mod_timer(&sl->keepalive_timer, | ||
1250 | jiffies + sl->keepalive * HZ); | ||
1258 | set_bit(SLF_KEEPTEST, &sl->flags); | 1251 | set_bit(SLF_KEEPTEST, &sl->flags); |
1259 | } else { | 1252 | } else |
1260 | del_timer(&sl->keepalive_timer); | 1253 | del_timer(&sl->keepalive_timer); |
1261 | } | ||
1262 | break; | 1254 | break; |
1263 | 1255 | ||
1264 | case SIOCGKEEPALIVE: | 1256 | case SIOCGKEEPALIVE: |
1265 | *p = sl->keepalive; | 1257 | *p = sl->keepalive; |
1266 | break; | 1258 | break; |
1267 | 1259 | ||
1268 | case SIOCSOUTFILL: | 1260 | case SIOCSOUTFILL: |
1269 | if ((unsigned)*p > 255) { /* max for unchar */ | 1261 | if ((unsigned)*p > 255) { /* max for unchar */ |
1270 | spin_unlock_bh(&sl->lock); | 1262 | spin_unlock_bh(&sl->lock); |
1271 | return -EINVAL; | 1263 | return -EINVAL; |
1272 | } | 1264 | } |
1273 | if ((sl->outfill = (unchar)*p) != 0){ | 1265 | sl->outfill = (u8)*p; |
1274 | mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ); | 1266 | if (sl->outfill != 0) { |
1267 | mod_timer(&sl->outfill_timer, | ||
1268 | jiffies + sl->outfill * HZ); | ||
1275 | set_bit(SLF_OUTWAIT, &sl->flags); | 1269 | set_bit(SLF_OUTWAIT, &sl->flags); |
1276 | } else { | 1270 | } else |
1277 | del_timer (&sl->outfill_timer); | 1271 | del_timer(&sl->outfill_timer); |
1278 | } | 1272 | break; |
1279 | break; | ||
1280 | 1273 | ||
1281 | case SIOCGOUTFILL: | 1274 | case SIOCGOUTFILL: |
1282 | *p = sl->outfill; | 1275 | *p = sl->outfill; |
1283 | break; | 1276 | break; |
1284 | 1277 | ||
1285 | case SIOCSLEASE: | 1278 | case SIOCSLEASE: |
1286 | /* Resolve race condition, when ioctl'ing hanged up | 1279 | /* Resolve race condition, when ioctl'ing hanged up |
1287 | and opened by another process device. | 1280 | and opened by another process device. |
1288 | */ | 1281 | */ |
1289 | if (sl->tty != current->signal->tty && sl->pid != current->pid) { | 1282 | if (sl->tty != current->signal->tty && |
1283 | sl->pid != current->pid) { | ||
1290 | spin_unlock_bh(&sl->lock); | 1284 | spin_unlock_bh(&sl->lock); |
1291 | return -EPERM; | 1285 | return -EPERM; |
1292 | } | 1286 | } |
1293 | sl->leased = 0; | 1287 | sl->leased = 0; |
1294 | if (*p) | 1288 | if (*p) |
1295 | sl->leased = 1; | 1289 | sl->leased = 1; |
1296 | break; | 1290 | break; |
1297 | 1291 | ||
1298 | case SIOCGLEASE: | 1292 | case SIOCGLEASE: |
1299 | *p = sl->leased; | 1293 | *p = sl->leased; |
1300 | }; | 1294 | }; |
1301 | spin_unlock_bh(&sl->lock); | 1295 | spin_unlock_bh(&sl->lock); |
@@ -1327,7 +1321,7 @@ static int __init slip_init(void) | |||
1327 | " (6 bit encapsulation enabled)" | 1321 | " (6 bit encapsulation enabled)" |
1328 | #endif | 1322 | #endif |
1329 | ".\n", | 1323 | ".\n", |
1330 | SLIP_VERSION, slip_maxdev ); | 1324 | SLIP_VERSION, slip_maxdev); |
1331 | #if defined(SL_INCLUDE_CSLIP) | 1325 | #if defined(SL_INCLUDE_CSLIP) |
1332 | printk(KERN_INFO "CSLIP: code copyright 1989 Regents of the University of California.\n"); | 1326 | printk(KERN_INFO "CSLIP: code copyright 1989 Regents of the University of California.\n"); |
1333 | #endif | 1327 | #endif |
@@ -1335,14 +1329,16 @@ static int __init slip_init(void) | |||
1335 | printk(KERN_INFO "SLIP linefill/keepalive option.\n"); | 1329 | printk(KERN_INFO "SLIP linefill/keepalive option.\n"); |
1336 | #endif | 1330 | #endif |
1337 | 1331 | ||
1338 | slip_devs = kzalloc(sizeof(struct net_device *)*slip_maxdev, GFP_KERNEL); | 1332 | slip_devs = kzalloc(sizeof(struct net_device *)*slip_maxdev, |
1333 | GFP_KERNEL); | ||
1339 | if (!slip_devs) { | 1334 | if (!slip_devs) { |
1340 | printk(KERN_ERR "SLIP: Can't allocate slip devices array! Uaargh! (-> No SLIP available)\n"); | 1335 | printk(KERN_ERR "SLIP: Can't allocate slip devices array.\n"); |
1341 | return -ENOMEM; | 1336 | return -ENOMEM; |
1342 | } | 1337 | } |
1343 | 1338 | ||
1344 | /* Fill in our line protocol discipline, and register it */ | 1339 | /* Fill in our line protocol discipline, and register it */ |
1345 | if ((status = tty_register_ldisc(N_SLIP, &sl_ldisc)) != 0) { | 1340 | status = tty_register_ldisc(N_SLIP, &sl_ldisc); |
1341 | if (status != 0) { | ||
1346 | printk(KERN_ERR "SLIP: can't register line discipline (err = %d)\n", status); | 1342 | printk(KERN_ERR "SLIP: can't register line discipline (err = %d)\n", status); |
1347 | kfree(slip_devs); | 1343 | kfree(slip_devs); |
1348 | } | 1344 | } |
@@ -1402,10 +1398,9 @@ static void __exit slip_exit(void) | |||
1402 | kfree(slip_devs); | 1398 | kfree(slip_devs); |
1403 | slip_devs = NULL; | 1399 | slip_devs = NULL; |
1404 | 1400 | ||
1405 | if ((i = tty_unregister_ldisc(N_SLIP))) | 1401 | i = tty_unregister_ldisc(N_SLIP); |
1406 | { | 1402 | if (i != 0) |
1407 | printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i); | 1403 | printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i); |
1408 | } | ||
1409 | } | 1404 | } |
1410 | 1405 | ||
1411 | module_init(slip_init); | 1406 | module_init(slip_init); |
@@ -1419,17 +1414,15 @@ module_exit(slip_exit); | |||
1419 | 1414 | ||
1420 | static void sl_outfill(unsigned long sls) | 1415 | static void sl_outfill(unsigned long sls) |
1421 | { | 1416 | { |
1422 | struct slip *sl=(struct slip *)sls; | 1417 | struct slip *sl = (struct slip *)sls; |
1423 | 1418 | ||
1424 | spin_lock(&sl->lock); | 1419 | spin_lock(&sl->lock); |
1425 | 1420 | ||
1426 | if (sl->tty == NULL) | 1421 | if (sl->tty == NULL) |
1427 | goto out; | 1422 | goto out; |
1428 | 1423 | ||
1429 | if(sl->outfill) | 1424 | if (sl->outfill) { |
1430 | { | 1425 | if (test_bit(SLF_OUTWAIT, &sl->flags)) { |
1431 | if( test_bit(SLF_OUTWAIT, &sl->flags) ) | ||
1432 | { | ||
1433 | /* no packets were transmitted, do outfill */ | 1426 | /* no packets were transmitted, do outfill */ |
1434 | #ifdef CONFIG_SLIP_MODE_SLIP6 | 1427 | #ifdef CONFIG_SLIP_MODE_SLIP6 |
1435 | unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END; | 1428 | unsigned char s = (sl->mode & SL_MODE_SLIP6)?0x70:END; |
@@ -1437,13 +1430,11 @@ static void sl_outfill(unsigned long sls) | |||
1437 | unsigned char s = END; | 1430 | unsigned char s = END; |
1438 | #endif | 1431 | #endif |
1439 | /* put END into tty queue. Is it right ??? */ | 1432 | /* put END into tty queue. Is it right ??? */ |
1440 | if (!netif_queue_stopped(sl->dev)) | 1433 | if (!netif_queue_stopped(sl->dev)) { |
1441 | { | ||
1442 | /* if device busy no outfill */ | 1434 | /* if device busy no outfill */ |
1443 | sl->tty->driver->write(sl->tty, &s, 1); | 1435 | sl->tty->driver->write(sl->tty, &s, 1); |
1444 | } | 1436 | } |
1445 | } | 1437 | } else |
1446 | else | ||
1447 | set_bit(SLF_OUTWAIT, &sl->flags); | 1438 | set_bit(SLF_OUTWAIT, &sl->flags); |
1448 | 1439 | ||
1449 | mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ); | 1440 | mod_timer(&sl->outfill_timer, jiffies+sl->outfill*HZ); |
@@ -1454,31 +1445,29 @@ out: | |||
1454 | 1445 | ||
1455 | static void sl_keepalive(unsigned long sls) | 1446 | static void sl_keepalive(unsigned long sls) |
1456 | { | 1447 | { |
1457 | struct slip *sl=(struct slip *)sls; | 1448 | struct slip *sl = (struct slip *)sls; |
1458 | 1449 | ||
1459 | spin_lock(&sl->lock); | 1450 | spin_lock(&sl->lock); |
1460 | 1451 | ||
1461 | if (sl->tty == NULL) | 1452 | if (sl->tty == NULL) |
1462 | goto out; | 1453 | goto out; |
1463 | 1454 | ||
1464 | if( sl->keepalive) | 1455 | if (sl->keepalive) { |
1465 | { | 1456 | if (test_bit(SLF_KEEPTEST, &sl->flags)) { |
1466 | if(test_bit(SLF_KEEPTEST, &sl->flags)) | ||
1467 | { | ||
1468 | /* keepalive still high :(, we must hangup */ | 1457 | /* keepalive still high :(, we must hangup */ |
1469 | if( sl->outfill ) /* outfill timer must be deleted too */ | 1458 | if (sl->outfill) |
1459 | /* outfill timer must be deleted too */ | ||
1470 | (void)del_timer(&sl->outfill_timer); | 1460 | (void)del_timer(&sl->outfill_timer); |
1471 | printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name); | 1461 | printk(KERN_DEBUG "%s: no packets received during keepalive timeout, hangup.\n", sl->dev->name); |
1472 | tty_hangup(sl->tty); /* this must hangup tty & close slip */ | 1462 | /* this must hangup tty & close slip */ |
1463 | tty_hangup(sl->tty); | ||
1473 | /* I think we need not something else */ | 1464 | /* I think we need not something else */ |
1474 | goto out; | 1465 | goto out; |
1475 | } | 1466 | } else |
1476 | else | ||
1477 | set_bit(SLF_KEEPTEST, &sl->flags); | 1467 | set_bit(SLF_KEEPTEST, &sl->flags); |
1478 | 1468 | ||
1479 | mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ); | 1469 | mod_timer(&sl->keepalive_timer, jiffies+sl->keepalive*HZ); |
1480 | } | 1470 | } |
1481 | |||
1482 | out: | 1471 | out: |
1483 | spin_unlock(&sl->lock); | 1472 | spin_unlock(&sl->lock); |
1484 | } | 1473 | } |