Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kurt Van Dijck and committed by
Marc Kleine-Budde
a1ef7bd9 bf03a537

+52
+5
drivers/net/can/dev.c
··· 25 25 #include <linux/can.h> 26 26 #include <linux/can/dev.h> 27 27 #include <linux/can/netlink.h> 28 + #include <linux/can/led.h> 28 29 #include <net/rtnetlink.h> 29 30 30 31 #define MOD_DESC "CAN device driver interface" ··· 812 811 { 813 812 int err; 814 813 814 + can_led_notifier_init(); 815 + 815 816 err = rtnl_link_register(&can_link_ops); 816 817 if (!err) 817 818 printk(KERN_INFO MOD_DESC "\n"); ··· 825 822 static __exit void can_dev_exit(void) 826 823 { 827 824 rtnl_link_unregister(&can_link_ops); 825 + 826 + can_led_notifier_exit(); 828 827 } 829 828 module_exit(can_dev_exit); 830 829
+38
drivers/net/can/led.c
··· 1 1 /* 2 2 * Copyright 2012, Fabio Baltieri <fabio.baltieri@gmail.com> 3 + * Copyright 2012, Kurt Van Dijck <kurt.van.dijck@eia.be> 3 4 * 4 5 * This program is free software; you can redistribute it and/or modify 5 6 * it under the terms of the GNU General Public License version 2 as ··· 85 84 devres_add(&netdev->dev, res); 86 85 } 87 86 EXPORT_SYMBOL_GPL(devm_can_led_init); 87 + 88 + /* NETDEV rename notifier to rename the associated led triggers too */ 89 + static int can_led_notifier(struct notifier_block *nb, unsigned long msg, 90 + void *data) 91 + { 92 + struct net_device *netdev = data; 93 + struct can_priv *priv = safe_candev_priv(netdev); 94 + char name[CAN_LED_NAME_SZ]; 95 + 96 + if (!priv) 97 + return NOTIFY_DONE; 98 + 99 + if (msg == NETDEV_CHANGENAME) { 100 + snprintf(name, sizeof(name), "%s-tx", netdev->name); 101 + led_trigger_rename_static(name, priv->tx_led_trig); 102 + 103 + snprintf(name, sizeof(name), "%s-rx", netdev->name); 104 + led_trigger_rename_static(name, priv->rx_led_trig); 105 + } 106 + 107 + return NOTIFY_DONE; 108 + } 109 + 110 + /* notifier block for netdevice event */ 111 + static struct notifier_block can_netdev_notifier __read_mostly = { 112 + .notifier_call = can_led_notifier, 113 + }; 114 + 115 + int __init can_led_notifier_init(void) 116 + { 117 + return register_netdevice_notifier(&can_netdev_notifier); 118 + } 119 + 120 + void __exit can_led_notifier_exit(void) 121 + { 122 + unregister_netdevice_notifier(&can_netdev_notifier); 123 + }
+9
include/linux/can/led.h
··· 26 26 27 27 void can_led_event(struct net_device *netdev, enum can_led_event event); 28 28 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); 29 31 30 32 #else 31 33 ··· 36 34 { 37 35 } 38 36 static inline void devm_can_led_init(struct net_device *netdev) 37 + { 38 + } 39 + static inline int can_led_notifier_init(void) 40 + { 41 + return 0; 42 + } 43 + static inline void can_led_notifier_exit(void) 39 44 { 40 45 } 41 46