linux-can-fixes-for-4.8-20160922

-----BEGIN PGP SIGNATURE-----
 
 iQEcBAABCgAGBQJX45B3AAoJED07qiWsqSVqw34H/060v5lUgOYtRU4Eq2v9PJ9K
 S+zTHFObExqHB2CdIqoYoWROG8HT0KcaDI7R1Ua62lM0kM9JucbMUghDALdQiSSE
 GG2n7VWgAwpDTh+HL9FCX4sRSjgJ5efRCcGV/x+W/bc9lpFdjCY2G41S3od2Ts6v
 m54uXaUPAK29G2rMOUIFKX8IqWcG+OvUCnt+iDeijHRgzwDvNV1vNW9sTPJQjLdN
 z1jwSVHelrG/7bBJ5ZuVQVCnF564cTRCr+ZKuwCFXI6fp7DLzup4pqzS/+S0hiVP
 MPfuDYoYE1lOVaYgzbR9QSo11TGhCRfnFgYUF9hgklDW+iOQ9heVMXhZ6TRKbBA=
 =8O8M
 -----END PGP SIGNATURE-----

Merge tag 'linux-can-fixes-for-4.8-20160922' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can

Marc Kleine-Budde says:

====================
pull-request: can 2016-09-22

this is a pull request of one patch for the upcoming linux-4.8 release.

The patch by Sergei Miroshnichenko fixes a potential deadlock in the generic
CAN device code that cann occour after a bus-off.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2016-09-23 07:13:55 -04:00
commit f44ace4d06
2 changed files with 19 additions and 11 deletions

View File

@ -21,6 +21,7 @@
#include <linux/slab.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/workqueue.h>
#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/skb.h>
@ -501,9 +502,8 @@ EXPORT_SYMBOL_GPL(can_free_echo_skb);
/*
* CAN device restart for bus-off recovery
*/
static void can_restart(unsigned long data)
static void can_restart(struct net_device *dev)
{
struct net_device *dev = (struct net_device *)data;
struct can_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = &dev->stats;
struct sk_buff *skb;
@ -543,6 +543,14 @@ restart:
netdev_err(dev, "Error %d during restart", err);
}
static void can_restart_work(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
struct can_priv *priv = container_of(dwork, struct can_priv, restart_work);
can_restart(priv->dev);
}
int can_restart_now(struct net_device *dev)
{
struct can_priv *priv = netdev_priv(dev);
@ -556,8 +564,8 @@ int can_restart_now(struct net_device *dev)
if (priv->state != CAN_STATE_BUS_OFF)
return -EBUSY;
/* Runs as soon as possible in the timer context */
mod_timer(&priv->restart_timer, jiffies);
cancel_delayed_work_sync(&priv->restart_work);
can_restart(dev);
return 0;
}
@ -578,8 +586,8 @@ void can_bus_off(struct net_device *dev)
netif_carrier_off(dev);
if (priv->restart_ms)
mod_timer(&priv->restart_timer,
jiffies + (priv->restart_ms * HZ) / 1000);
schedule_delayed_work(&priv->restart_work,
msecs_to_jiffies(priv->restart_ms));
}
EXPORT_SYMBOL_GPL(can_bus_off);
@ -688,6 +696,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
return NULL;
priv = netdev_priv(dev);
priv->dev = dev;
if (echo_skb_max) {
priv->echo_skb_max = echo_skb_max;
@ -697,7 +706,7 @@ struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
priv->state = CAN_STATE_STOPPED;
init_timer(&priv->restart_timer);
INIT_DELAYED_WORK(&priv->restart_work, can_restart_work);
return dev;
}
@ -778,8 +787,6 @@ int open_candev(struct net_device *dev)
if (!netif_carrier_ok(dev))
netif_carrier_on(dev);
setup_timer(&priv->restart_timer, can_restart, (unsigned long)dev);
return 0;
}
EXPORT_SYMBOL_GPL(open_candev);
@ -794,7 +801,7 @@ void close_candev(struct net_device *dev)
{
struct can_priv *priv = netdev_priv(dev);
del_timer_sync(&priv->restart_timer);
cancel_delayed_work_sync(&priv->restart_work);
can_flush_echo_skb(dev);
}
EXPORT_SYMBOL_GPL(close_candev);

View File

@ -32,6 +32,7 @@ enum can_mode {
* CAN common private data
*/
struct can_priv {
struct net_device *dev;
struct can_device_stats can_stats;
struct can_bittiming bittiming, data_bittiming;
@ -47,7 +48,7 @@ struct can_priv {
u32 ctrlmode_static; /* static enabled options for driver/hardware */
int restart_ms;
struct timer_list restart_timer;
struct delayed_work restart_work;
int (*do_set_bittiming)(struct net_device *dev);
int (*do_set_data_bittiming)(struct net_device *dev);