projects
/
elmcan.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c4a0fb8
)
Simplify/clarify branching and locking in several places
author
norly
<ny-git@enpas.org>
Fri, 20 May 2022 22:51:27 +0000
(
00:51
+0200)
committer
norly
<ny-git@enpas.org>
Tue, 31 May 2022 11:48:15 +0000
(13:48 +0200)
module/can327.c
patch
|
blob
|
history
diff --git
a/module/can327.c
b/module/can327.c
index 803a9ab79214ceee3ed0d1f74562acf1fca47134..97ca7e148d334607dddbb7dfe02804d6e04c4374 100644
(file)
--- a/
module/can327.c
+++ b/
module/can327.c
@@
-856,25
+856,26
@@
static netdev_tx_t can327_netdev_start_xmit(struct sk_buff *skb,
if (can_dropped_invalid_skb(dev, skb))
return NETDEV_TX_OK;
if (can_dropped_invalid_skb(dev, skb))
return NETDEV_TX_OK;
- /*
BHs are already disabled, so no spin_lock_bh().
- *
See Documentation/networking/netdevices.txt
+ /*
This check will be part of can_dropped_invalid_skb()
+ *
in future kernels.
*/
*/
- spin_lock(&elm->lock);
+ if (elm->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+ goto out;
/* We shouldn't get here after a hardware fault:
* can_bus_off() calls netif_carrier_off()
*/
/* We shouldn't get here after a hardware fault:
* can_bus_off() calls netif_carrier_off()
*/
- WARN_ON_ONCE(elm->uart_side_failure);
-
- if (!elm->tty ||
- elm->uart_side_failure ||
- elm->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
- spin_unlock(&elm->lock);
+ if (elm->uart_side_failure) {
+ WARN_ON_ONCE(elm->uart_side_failure);
goto out;
}
netif_stop_queue(dev);
goto out;
}
netif_stop_queue(dev);
+ /* BHs are already disabled, so no spin_lock_bh().
+ * See Documentation/networking/netdevices.txt
+ */
+ spin_lock(&elm->lock);
elm327_send_frame(elm, frame);
spin_unlock(&elm->lock);
elm327_send_frame(elm, frame);
spin_unlock(&elm->lock);
@@
-925,10
+926,10
@@
static void can327_ldisc_rx(struct tty_struct *tty,
{
struct can327 *elm = (struct can327 *)tty->disc_data;
{
struct can327 *elm = (struct can327 *)tty->disc_data;
- spin_lock_bh(&elm->lock);
-
if (elm->uart_side_failure)
if (elm->uart_side_failure)
- goto out;
+ return;
+
+ spin_lock_bh(&elm->lock);
while (count-- && elm->rxfill < ELM327_SIZE_RXBUF) {
if (fp && *fp++) {
while (count-- && elm->rxfill < ELM327_SIZE_RXBUF) {
if (fp && *fp++) {
@@
-936,7
+937,8
@@
static void can327_ldisc_rx(struct tty_struct *tty,
elm327_uart_side_failure(elm);
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
/* Ignore NUL characters, which the PIC microcontroller may
}
/* Ignore NUL characters, which the PIC microcontroller may
@@
-954,7
+956,8
@@
static void can327_ldisc_rx(struct tty_struct *tty,
*cp);
elm327_uart_side_failure(elm);
*cp);
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
elm->rxbuf[elm->rxfill++] = *cp;
}
elm->rxbuf[elm->rxfill++] = *cp;
@@
-968,12
+971,11
@@
static void can327_ldisc_rx(struct tty_struct *tty,
elm327_uart_side_failure(elm);
elm327_uart_side_failure(elm);
- goto out;
+ spin_unlock_bh(&elm->lock);
+ return;
}
elm327_parse_rxbuf(elm);
}
elm327_parse_rxbuf(elm);
-
-out:
spin_unlock_bh(&elm->lock);
}
spin_unlock_bh(&elm->lock);
}
@@
-997,6
+999,7
@@
static void can327_ldisc_tx_worker(struct work_struct *work)
"Failed to write to tty %s.\n",
elm->tty->name);
elm327_uart_side_failure(elm);
"Failed to write to tty %s.\n",
elm->tty->name);
elm327_uart_side_failure(elm);
+
spin_unlock_bh(&elm->lock);
return;
}
spin_unlock_bh(&elm->lock);
return;
}
@@
-1005,12
+1008,10
@@
static void can327_ldisc_tx_worker(struct work_struct *work)
elm->txhead += written;
}
elm->txhead += written;
}
- if (!elm->txleft)
{
+ if (!elm->txleft)
clear_bit(TTY_DO_WRITE_WAKEUP, &elm->tty->flags);
clear_bit(TTY_DO_WRITE_WAKEUP, &elm->tty->flags);
- spin_unlock_bh(&elm->lock);
- } else {
- spin_unlock_bh(&elm->lock);
- }
+
+ spin_unlock_bh(&elm->lock);
}
/* Called by the driver when there's room for more data. */
}
/* Called by the driver when there's room for more data. */
@@
-1082,16
+1083,14
@@
static int can327_ldisc_open(struct tty_struct *tty)
/* Let 'er rip */
err = register_candev(elm->dev);
/* Let 'er rip */
err = register_candev(elm->dev);
- if (err)
- goto out_err;
+ if (err) {
+ free_candev(elm->dev);
+ return err;
+ }
netdev_info(elm->dev, "can327 on %s.\n", tty->name);
return 0;
netdev_info(elm->dev, "can327 on %s.\n", tty->name);
return 0;
-
-out_err:
- free_candev(elm->dev);
- return err;
}
/* Close down a can327 channel.
}
/* Close down a can327 channel.