diff options
author | Kurt Van Dijck <kurt.van.dijck@eia.be> | 2012-12-18 12:50:56 -0500 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2013-01-26 10:58:59 -0500 |
commit | bf03a5379cd3492fbeca42111340581ba9dee0b8 (patch) | |
tree | c4a4a93c0645d66a0dcb8f718739696b4240c8ab | |
parent | 996a953de02ffb852c9ac736f4e892008ed68884 (diff) |
can: export a safe netdev_priv wrapper for candev
In net_device notifier calls, it was impossible to determine
if a CAN device is based on candev in a safe way.
This patch adds such test in order to access candev storage
from within those notifiers.
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | drivers/net/can/dev.c | 13 | ||||
-rw-r--r-- | include/linux/can/dev.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 8233e5ed2939..13e738098fbe 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c | |||
@@ -794,6 +794,19 @@ void unregister_candev(struct net_device *dev) | |||
794 | } | 794 | } |
795 | EXPORT_SYMBOL_GPL(unregister_candev); | 795 | EXPORT_SYMBOL_GPL(unregister_candev); |
796 | 796 | ||
797 | /* | ||
798 | * Test if a network device is a candev based device | ||
799 | * and return the can_priv* if so. | ||
800 | */ | ||
801 | struct can_priv *safe_candev_priv(struct net_device *dev) | ||
802 | { | ||
803 | if ((dev->type != ARPHRD_CAN) || (dev->rtnl_link_ops != &can_link_ops)) | ||
804 | return NULL; | ||
805 | |||
806 | return netdev_priv(dev); | ||
807 | } | ||
808 | EXPORT_SYMBOL_GPL(safe_candev_priv); | ||
809 | |||
797 | static __init int can_dev_init(void) | 810 | static __init int can_dev_init(void) |
798 | { | 811 | { |
799 | int err; | 812 | int err; |
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 7747d9bcdc84..fb0ab651a041 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h | |||
@@ -106,6 +106,9 @@ u8 can_len2dlc(u8 len); | |||
106 | struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max); | 106 | struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max); |
107 | void free_candev(struct net_device *dev); | 107 | void free_candev(struct net_device *dev); |
108 | 108 | ||
109 | /* a candev safe wrapper around netdev_priv */ | ||
110 | struct can_priv *safe_candev_priv(struct net_device *dev); | ||
111 | |||
109 | int open_candev(struct net_device *dev); | 112 | int open_candev(struct net_device *dev); |
110 | void close_candev(struct net_device *dev); | 113 | void close_candev(struct net_device *dev); |
111 | 114 | ||