Skip to content

Commit a1ef7bd

Browse files
Kurt Van Dijckmarckleinebudde
authored andcommitted
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>
1 parent bf03a53 commit a1ef7bd

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎drivers/net/can/dev.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/can.h>
2626
#include <linux/can/dev.h>
2727
#include <linux/can/netlink.h>
28+
#include <linux/can/led.h>
2829
#include <net/rtnetlink.h>
2930

3031
#define MOD_DESC "CAN device driver interface"
@@ -811,6 +812,8 @@ static __init int can_dev_init(void)
811812
{
812813
int err;
813814

815+
can_led_notifier_init();
816+
814817
err = rtnl_link_register(&can_link_ops);
815818
if (!err)
816819
printk(KERN_INFO MOD_DESC "\n");
@@ -822,6 +825,8 @@ module_init(can_dev_init);
822825
static __exit void can_dev_exit(void)
823826
{
824827
rtnl_link_unregister(&can_link_ops);
828+
829+
can_led_notifier_exit();
825830
}
826831
module_exit(can_dev_exit);
827832

‎drivers/net/can/led.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com>
3+
* Copyright 2012, Kurt Van Dijck <kurt.van.dijck@eia.be>
34
*
45
* This program is free software; you can redistribute it and/or modify
56
* 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)
8485
devres_add(&netdev->dev, res);
8586
}
8687
EXPORT_SYMBOL_GPL(devm_can_led_init);
88+
89+
/* NETDEV rename notifier to rename the associated led triggers too */
90+
static 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 */
112+
static struct notifier_block can_netdev_notifier __read_mostly = {
113+
.notifier_call = can_led_notifier,
114+
};
115+
116+
int __init can_led_notifier_init(void)
117+
{
118+
return register_netdevice_notifier(&can_netdev_notifier);
119+
}
120+
121+
void __exit can_led_notifier_exit(void)
122+
{
123+
unregister_netdevice_notifier(&can_netdev_notifier);
124+
}

‎include/linux/can/led.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum can_led_event {
2626

2727
void can_led_event(struct net_device *netdev, enum can_led_event event);
2828
void devm_can_led_init(struct net_device *netdev);
29+
int __init can_led_notifier_init(void);
30+
void __exit can_led_notifier_exit(void);
2931

3032
#else
3133

@@ -36,6 +38,13 @@ static inline void can_led_event(struct net_device *netdev,
3638
static inline void devm_can_led_init(struct net_device *netdev)
3739
{
3840
}
41+
static inline int can_led_notifier_init(void)
42+
{
43+
return 0;
44+
}
45+
static inline void can_led_notifier_exit(void)
46+
{
47+
}
3948

4049
#endif
4150

0 commit comments

Comments
 (0)