aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKurt Van Dijck <kurt.van.dijck@eia.be>2012-12-18 12:50:57 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2013-01-26 10:58:59 -0500
commita1ef7bd9fce8aba8e4701e60208148fb3bc9bdd4 (patch)
tree0b9008a80fdbe8304f1983980996117024ebc96a
parentbf03a5379cd3492fbeca42111340581ba9dee0b8 (diff)
can: rename LED trigger name on netdev renames
The LED trigger name for CAN devices is based on the initial CAN device name, but does never change. The LED trigger name is not guaranteed to be unique in case of hotplugging CAN devices. This patch tries to address this problem by modifying the LED trigger name according to the CAN device name when the latter changes. v1 - Kurt Van Dijck v2 - Fabio Baltieri - remove rename blocking if trigger is bound - use led-subsystem function for the actual rename (still WiP) - call init/exit functions from dev.c v3 - Kurt Van Dijck - safe operation for non-candev based devices (vcan, slcan) based on earlier patch v4 - Kurt Van Dijck - trivial patch mistakes fixed Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> 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.c5
-rw-r--r--drivers/net/can/led.c38
-rw-r--r--include/linux/can/led.h9
3 files changed, 52 insertions, 0 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 13e738098fbe..6abc6e59778e 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -25,6 +25,7 @@
25#include <linux/can.h> 25#include <linux/can.h>
26#include <linux/can/dev.h> 26#include <linux/can/dev.h>
27#include <linux/can/netlink.h> 27#include <linux/can/netlink.h>
28#include <linux/can/led.h>
28#include <net/rtnetlink.h> 29#include <net/rtnetlink.h>
29 30
30#define MOD_DESC "CAN device driver interface" 31#define MOD_DESC "CAN device driver interface"
@@ -811,6 +812,8 @@ static __init int can_dev_init(void)
811{ 812{
812 int err; 813 int err;
813 814
815 can_led_notifier_init();
816
814 err = rtnl_link_register(&can_link_ops); 817 err = rtnl_link_register(&can_link_ops);
815 if (!err) 818 if (!err)
816 printk(KERN_INFO MOD_DESC "\n"); 819 printk(KERN_INFO MOD_DESC "\n");
@@ -822,6 +825,8 @@ module_init(can_dev_init);
822static __exit void can_dev_exit(void) 825static __exit void can_dev_exit(void)
823{ 826{
824 rtnl_link_unregister(&can_link_ops); 827 rtnl_link_unregister(&can_link_ops);
828
829 can_led_notifier_exit();
825} 830}
826module_exit(can_dev_exit); 831module_exit(can_dev_exit);
827 832
diff --git a/drivers/net/can/led.c b/drivers/net/can/led.c
index c50a0d741c57..f27fca65dc4a 100644
--- a/drivers/net/can/led.c
+++ b/drivers/net/can/led.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com> 2 * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com>
3 * Copyright 2012, Kurt Van Dijck <kurt.van.dijck@eia.be>
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as 6 * it under the terms of the GNU General Public License version 2 as
@@ -84,3 +85,40 @@ void devm_can_led_init(struct net_device *netdev)
84 devres_add(&netdev->dev, res); 85 devres_add(&netdev->dev, res);
85} 86}
86EXPORT_SYMBOL_GPL(devm_can_led_init); 87EXPORT_SYMBOL_GPL(devm_can_led_init);
88
89/* NETDEV rename notifier to rename the associated led triggers too */
90static int can_led_notifier(struct notifier_block *nb, unsigned long msg,
91 void *data)
92{
93 struct net_device *netdev = data;
94 struct can_priv *priv = safe_candev_priv(netdev);
95 char name[CAN_LED_NAME_SZ];
96
97 if (!priv)
98 return NOTIFY_DONE;
99
100 if (msg == NETDEV_CHANGENAME) {
101 snprintf(name, sizeof(name), "%s-tx", netdev->name);
102 led_trigger_rename_static(name, priv->tx_led_trig);
103
104 snprintf(name, sizeof(name), "%s-rx", netdev->name);
105 led_trigger_rename_static(name, priv->rx_led_trig);
106 }
107
108 return NOTIFY_DONE;
109}
110
111/* notifier block for netdevice event */
112static struct notifier_block can_netdev_notifier __read_mostly = {
113 .notifier_call = can_led_notifier,
114};
115
116int __init can_led_notifier_init(void)
117{
118 return register_netdevice_notifier(&can_netdev_notifier);
119}
120
121void __exit can_led_notifier_exit(void)
122{
123 unregister_netdevice_notifier(&can_netdev_notifier);
124}
diff --git a/include/linux/can/led.h b/include/linux/can/led.h
index 12d5549abb95..9c1167baf273 100644
--- a/include/linux/can/led.h
+++ b/include/linux/can/led.h
@@ -26,6 +26,8 @@ enum can_led_event {
26 26
27void can_led_event(struct net_device *netdev, enum can_led_event event); 27void can_led_event(struct net_device *netdev, enum can_led_event event);
28void devm_can_led_init(struct net_device *netdev); 28void devm_can_led_init(struct net_device *netdev);
29int __init can_led_notifier_init(void);
30void __exit can_led_notifier_exit(void);
29 31
30#else 32#else
31 33
@@ -36,6 +38,13 @@ static inline void can_led_event(struct net_device *netdev,
36static inline void devm_can_led_init(struct net_device *netdev) 38static inline void devm_can_led_init(struct net_device *netdev)
37{ 39{
38} 40}
41static inline int can_led_notifier_init(void)
42{
43 return 0;
44}
45static inline void can_led_notifier_exit(void)
46{
47}
39 48
40#endif 49#endif
41 50