aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2014-03-18 13:19:12 -0400
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-04-01 05:55:00 -0400
commitbf88a20611d5a62119a02da4eba95b461ec692c8 (patch)
treef1ee16ea5621c98799fdf17f5b102474a77b4e8e
parent710c56105dfd10e32a89086cf78cc1c8433f6a7a (diff)
can: c_can: Provide protection in the xmit path
The network core does not serialize the access to the hardware. The xmit related code lets the following happen: CPU0 CPU1 interrupt() do_poll() c_can_do_tx() Fiddle with HW and xmit() internal data Fiddle with HW and internal data due the complete lack of serialization. Add proper locking. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--drivers/net/can/c_can/c_can.c9
-rw-r--r--drivers/net/can/c_can/c_can.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 30a85aa81d45..1fe79ce50c5a 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -549,6 +549,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
549 if (can_dropped_invalid_skb(dev, skb)) 549 if (can_dropped_invalid_skb(dev, skb))
550 return NETDEV_TX_OK; 550 return NETDEV_TX_OK;
551 551
552 spin_lock_bh(&priv->xmit_lock);
552 msg_obj_no = get_tx_next_msg_obj(priv); 553 msg_obj_no = get_tx_next_msg_obj(priv);
553 554
554 /* prepare message object for transmission */ 555 /* prepare message object for transmission */
@@ -563,6 +564,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
563 if (c_can_is_next_tx_obj_busy(priv, get_tx_next_msg_obj(priv)) || 564 if (c_can_is_next_tx_obj_busy(priv, get_tx_next_msg_obj(priv)) ||
564 (priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) == 0) 565 (priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) == 0)
565 netif_stop_queue(dev); 566 netif_stop_queue(dev);
567 spin_unlock_bh(&priv->xmit_lock);
566 568
567 return NETDEV_TX_OK; 569 return NETDEV_TX_OK;
568} 570}
@@ -787,7 +789,9 @@ static void c_can_do_tx(struct net_device *dev)
787 struct c_can_priv *priv = netdev_priv(dev); 789 struct c_can_priv *priv = netdev_priv(dev);
788 struct net_device_stats *stats = &dev->stats; 790 struct net_device_stats *stats = &dev->stats;
789 791
790 for (/* nix */; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) { 792 spin_lock_bh(&priv->xmit_lock);
793
794 for (; (priv->tx_next - priv->tx_echo) > 0; priv->tx_echo++) {
791 msg_obj_no = get_tx_echo_msg_obj(priv); 795 msg_obj_no = get_tx_echo_msg_obj(priv);
792 val = c_can_read_reg32(priv, C_CAN_TXRQST1_REG); 796 val = c_can_read_reg32(priv, C_CAN_TXRQST1_REG);
793 if (!(val & (1 << (msg_obj_no - 1)))) { 797 if (!(val & (1 << (msg_obj_no - 1)))) {
@@ -809,6 +813,8 @@ static void c_can_do_tx(struct net_device *dev)
809 if (((priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) != 0) || 813 if (((priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) != 0) ||
810 ((priv->tx_echo & C_CAN_NEXT_MSG_OBJ_MASK) == 0)) 814 ((priv->tx_echo & C_CAN_NEXT_MSG_OBJ_MASK) == 0))
811 netif_wake_queue(dev); 815 netif_wake_queue(dev);
816
817 spin_unlock_bh(&priv->xmit_lock);
812} 818}
813 819
814/* 820/*
@@ -1262,6 +1268,7 @@ struct net_device *alloc_c_can_dev(void)
1262 return NULL; 1268 return NULL;
1263 1269
1264 priv = netdev_priv(dev); 1270 priv = netdev_priv(dev);
1271 spin_lock_init(&priv->xmit_lock);
1265 netif_napi_add(dev, &priv->napi, c_can_poll, C_CAN_NAPI_WEIGHT); 1272 netif_napi_add(dev, &priv->napi, c_can_poll, C_CAN_NAPI_WEIGHT);
1266 1273
1267 priv->dev = dev; 1274 priv->dev = dev;
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index d2e1c21b143f..5097c802a61e 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -156,6 +156,7 @@ struct c_can_priv {
156 struct napi_struct napi; 156 struct napi_struct napi;
157 struct net_device *dev; 157 struct net_device *dev;
158 struct device *device; 158 struct device *device;
159 spinlock_t xmit_lock;
159 int tx_object; 160 int tx_object;
160 int current_status; 161 int current_status;
161 int last_status; 162 int last_status;