6767#define SLCAN_MAGIC 0x53CA
6868
6969static int maxdev = 10 ; /* MAX number of SLCAN channels;
70- This can be overridden with
71- insmod slcan.ko maxdev=nnn */
70+ * This can be overridden with
71+ * insmod slcan.ko maxdev=nnn
72+ */
7273module_param (maxdev , int , 0 );
7374MODULE_PARM_DESC (maxdev , "Maximum number of slcan interfaces" );
7475
7576/* maximum rx buffer len: extended CAN frame with timestamp */
76- #define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+ 1)
77+ #define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r") + 1)
7778
7879#define SLC_CMD_LEN 1
7980#define SLC_SFF_ID_LEN 3
@@ -139,12 +140,11 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on)
139140 return 0 ;
140141}
141142
142- / ************************************************************************
143- * SLCAN ENCAPSULATION FORMAT *
144- ************************************************************************/
143+ /* ************************************************************************
144+ * SLCAN ENCAPSULATION FORMAT *
145+ * ************************************************************************/
145146
146- /*
147- * A CAN frame has a can_id (11 bit standard frame format OR 29 bit extended
147+ /* A CAN frame has a can_id (11 bit standard frame format OR 29 bit extended
148148 * frame format) a data length code (len) which can be from 0 to 8
149149 * and up to <len> data bytes as payload.
150150 * Additionally a CAN frame may become a remote transmission frame if the
@@ -174,9 +174,9 @@ int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on)
174174 *
175175 */
176176
177- / ************************************************************************
178- * STANDARD SLCAN DECAPSULATION *
179- ************************************************************************/
177+ /* ************************************************************************
178+ * STANDARD SLCAN DECAPSULATION *
179+ * ************************************************************************/
180180
181181/* Send one completely decapsulated can_frame to the network layer */
182182static void slc_bump_frame (struct slcan * sl )
@@ -469,26 +469,26 @@ static void slcan_unesc(struct slcan *sl, unsigned char s)
469469{
470470 if ((s == '\r' ) || (s == '\a' )) { /* CR or BEL ends the pdu */
471471 if (!test_and_clear_bit (SLF_ERROR , & sl -> flags ) &&
472- ( sl -> rcount > 4 )) {
472+ sl -> rcount > 4 )
473473 slc_bump (sl );
474- }
474+
475475 sl -> rcount = 0 ;
476476 } else {
477477 if (!test_bit (SLF_ERROR , & sl -> flags )) {
478478 if (sl -> rcount < SLC_MTU ) {
479479 sl -> rbuff [sl -> rcount ++ ] = s ;
480480 return ;
481- } else {
482- sl -> dev -> stats .rx_over_errors ++ ;
483- set_bit (SLF_ERROR , & sl -> flags );
484481 }
482+
483+ sl -> dev -> stats .rx_over_errors ++ ;
484+ set_bit (SLF_ERROR , & sl -> flags );
485485 }
486486 }
487487}
488488
489- / ************************************************************************
490- * STANDARD SLCAN ENCAPSULATION *
491- ************************************************************************/
489+ /* ************************************************************************
490+ * STANDARD SLCAN ENCAPSULATION *
491+ * ************************************************************************/
492492
493493/* Encapsulate one can_frame and stuff into a TTY queue. */
494494static void slc_encaps (struct slcan * sl , struct can_frame * cf )
@@ -575,7 +575,8 @@ static void slcan_transmit(struct work_struct *work)
575575 }
576576
577577 /* Now serial buffer is almost free & we can start
578- * transmission of another packet */
578+ * transmission of another packet
579+ */
579580 sl -> dev -> stats .tx_packets ++ ;
580581 clear_bit (TTY_DO_WRITE_WAKEUP , & sl -> tty -> flags );
581582 spin_unlock_bh (& sl -> lock );
@@ -589,8 +590,7 @@ static void slcan_transmit(struct work_struct *work)
589590 spin_unlock_bh (& sl -> lock );
590591}
591592
592- /*
593- * Called by the driver when there's room for more data.
593+ /* Called by the driver when there's room for more data.
594594 * Schedule the transmit.
595595 */
596596static void slcan_write_wakeup (struct tty_struct * tty )
@@ -618,21 +618,20 @@ static netdev_tx_t slc_xmit(struct sk_buff *skb, struct net_device *dev)
618618 netdev_warn (dev , "xmit: iface is down\n" );
619619 goto out ;
620620 }
621- if (sl -> tty == NULL ) {
621+ if (! sl -> tty ) {
622622 spin_unlock (& sl -> lock );
623623 goto out ;
624624 }
625625
626626 netif_stop_queue (sl -> dev );
627- slc_encaps (sl , (struct can_frame * ) skb -> data ); /* encaps & send */
627+ slc_encaps (sl , (struct can_frame * )skb -> data ); /* encaps & send */
628628 spin_unlock (& sl -> lock );
629629
630630out :
631631 kfree_skb (skb );
632632 return NETDEV_TX_OK ;
633633}
634634
635-
636635/******************************************
637636 * Routines looking at netdevice side.
638637 ******************************************/
@@ -708,7 +707,7 @@ static int slc_open(struct net_device *dev)
708707 unsigned char cmd [SLC_MTU ];
709708 int err , s ;
710709
711- if (sl -> tty == NULL )
710+ if (! sl -> tty )
712711 return - ENODEV ;
713712
714713 /* The baud rate is not set with the command
@@ -736,7 +735,6 @@ static int slc_open(struct net_device *dev)
736735 /* The CAN framework has already validate the bitrate value,
737736 * so we can avoid to check if `s' has been properly set.
738737 */
739-
740738 snprintf (cmd , sizeof (cmd ), "C\rS%d\r" , s );
741739 err = slcan_transmit_cmd (sl , cmd );
742740 if (err ) {
@@ -792,23 +790,21 @@ static const struct net_device_ops slc_netdev_ops = {
792790};
793791
794792/******************************************
795- Routines looking at TTY side.
793+ * Routines looking at TTY side.
796794 ******************************************/
797795
798- /*
799- * Handle the 'receiver data ready' interrupt.
796+ /* Handle the 'receiver data ready' interrupt.
800797 * This function is called by the 'tty_io' module in the kernel when
801798 * a block of SLCAN data has been received, which can now be decapsulated
802799 * and sent on to some IP layer for further processing. This will not
803800 * be re-entered while running but other ldisc functions may be called
804801 * in parallel
805802 */
806-
807803static void slcan_receive_buf (struct tty_struct * tty ,
808804 const unsigned char * cp , const char * fp ,
809805 int count )
810806{
811- struct slcan * sl = (struct slcan * ) tty -> disc_data ;
807+ struct slcan * sl = (struct slcan * )tty -> disc_data ;
812808
813809 if (!sl || sl -> magic != SLCAN_MAGIC || !netif_running (sl -> dev ))
814810 return ;
@@ -838,7 +834,7 @@ static void slc_sync(void)
838834
839835 for (i = 0 ; i < maxdev ; i ++ ) {
840836 dev = slcan_devs [i ];
841- if (dev == NULL )
837+ if (! dev )
842838 break ;
843839
844840 sl = netdev_priv (dev );
@@ -858,9 +854,8 @@ static struct slcan *slc_alloc(void)
858854
859855 for (i = 0 ; i < maxdev ; i ++ ) {
860856 dev = slcan_devs [i ];
861- if (dev == NULL )
857+ if (! dev )
862858 break ;
863-
864859 }
865860
866861 /* Sorry, too many, all slots in use */
@@ -890,16 +885,14 @@ static struct slcan *slc_alloc(void)
890885 return sl ;
891886}
892887
893- /*
894- * Open the high-level part of the SLCAN channel.
888+ /* Open the high-level part of the SLCAN channel.
895889 * This function is called by the TTY module when the
896890 * SLCAN line discipline is called for. Because we are
897891 * sure the tty line exists, we only have to link it to
898892 * a free SLCAN channel...
899893 *
900894 * Called in process context serialized from other ldisc calls.
901895 */
902-
903896static int slcan_open (struct tty_struct * tty )
904897{
905898 struct slcan * sl ;
@@ -908,12 +901,12 @@ static int slcan_open(struct tty_struct *tty)
908901 if (!capable (CAP_NET_ADMIN ))
909902 return - EPERM ;
910903
911- if (tty -> ops -> write == NULL )
904+ if (! tty -> ops -> write )
912905 return - EOPNOTSUPP ;
913906
914907 /* RTnetlink lock is misused here to serialize concurrent
915- opens of slcan channels. There are better ways, but it is
916- the simplest one.
908+ * opens of slcan channels. There are better ways, but it is
909+ * the simplest one.
917910 */
918911 rtnl_lock ();
919912
@@ -930,7 +923,7 @@ static int slcan_open(struct tty_struct *tty)
930923 /* OK. Find a free SLCAN channel to use. */
931924 err = - ENFILE ;
932925 sl = slc_alloc ();
933- if (sl == NULL )
926+ if (! sl )
934927 goto err_exit ;
935928
936929 sl -> tty = tty ;
@@ -974,17 +967,15 @@ static int slcan_open(struct tty_struct *tty)
974967 return err ;
975968}
976969
977- /*
978- * Close down a SLCAN channel.
970+ /* Close down a SLCAN channel.
979971 * This means flushing out any pending queues, and then returning. This
980972 * call is serialized against other ldisc functions.
981973 *
982974 * We also use this method for a hangup event.
983975 */
984-
985976static void slcan_close (struct tty_struct * tty )
986977{
987- struct slcan * sl = (struct slcan * ) tty -> disc_data ;
978+ struct slcan * sl = (struct slcan * )tty -> disc_data ;
988979
989980 /* First make sure we're connected. */
990981 if (!sl || sl -> magic != SLCAN_MAGIC || sl -> tty != tty )
@@ -1014,7 +1005,7 @@ static void slcan_hangup(struct tty_struct *tty)
10141005static int slcan_ioctl (struct tty_struct * tty , unsigned int cmd ,
10151006 unsigned long arg )
10161007{
1017- struct slcan * sl = (struct slcan * ) tty -> disc_data ;
1008+ struct slcan * sl = (struct slcan * )tty -> disc_data ;
10181009 unsigned int tmp ;
10191010
10201011 /* First make sure we're connected. */
@@ -1065,7 +1056,7 @@ static int __init slcan_init(void)
10651056 /* Fill in our line protocol discipline, and register it */
10661057 status = tty_register_ldisc (& slc_ldisc );
10671058 if (status ) {
1068- printk ( KERN_ERR "slcan: can't register line discipline\n" );
1059+ pr_err ( "slcan: can't register line discipline\n" );
10691060 kfree (slcan_devs );
10701061 }
10711062 return status ;
@@ -1079,7 +1070,7 @@ static void __exit slcan_exit(void)
10791070 unsigned long timeout = jiffies + HZ ;
10801071 int busy = 0 ;
10811072
1082- if (slcan_devs == NULL )
1073+ if (! slcan_devs )
10831074 return ;
10841075
10851076 /* First of all: check for active disciplines and hangup them.
@@ -1104,17 +1095,17 @@ static void __exit slcan_exit(void)
11041095 } while (busy && time_before (jiffies , timeout ));
11051096
11061097 /* FIXME: hangup is async so we should wait when doing this second
1107- phase */
1098+ * phase
1099+ */
11081100
11091101 for (i = 0 ; i < maxdev ; i ++ ) {
11101102 dev = slcan_devs [i ];
11111103 if (!dev )
11121104 continue ;
11131105
11141106 sl = netdev_priv (dev );
1115- if (sl -> tty ) {
1107+ if (sl -> tty )
11161108 netdev_err (dev , "tty discipline still running\n" );
1117- }
11181109
11191110 slc_close (dev );
11201111 unregister_candev (dev );
0 commit comments