ledtrig-netdev: switch rwlock to spinlock

Read/write lock was adding useless complexity, there wasn't any real
gain in case of this driver.
Also switch to _bh variants to avoid deadlocks.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 47986
master
Rafał Miłecki 9 years ago
parent e8c6d01d74
commit a56aaf73b9
  1. 40
      target/linux/generic/files/drivers/leds/ledtrig-netdev.c

@ -68,7 +68,7 @@
#define MODE_RX 4 #define MODE_RX 4
struct led_netdev_data { struct led_netdev_data {
rwlock_t lock; spinlock_t lock;
struct timer_list timer; struct timer_list timer;
struct notifier_block notifier; struct notifier_block notifier;
@ -102,9 +102,9 @@ static ssize_t led_device_name_show(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct led_netdev_data *trigger_data = led_cdev->trigger_data; struct led_netdev_data *trigger_data = led_cdev->trigger_data;
read_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
sprintf(buf, "%s\n", trigger_data->device_name); sprintf(buf, "%s\n", trigger_data->device_name);
read_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return strlen(buf) + 1; return strlen(buf) + 1;
} }
@ -118,7 +118,7 @@ static ssize_t led_device_name_store(struct device *dev,
if (size < 0 || size >= IFNAMSIZ) if (size < 0 || size >= IFNAMSIZ)
return -EINVAL; return -EINVAL;
write_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
strcpy(trigger_data->device_name, buf); strcpy(trigger_data->device_name, buf);
if (size > 0 && trigger_data->device_name[size-1] == '\n') if (size > 0 && trigger_data->device_name[size-1] == '\n')
@ -132,7 +132,7 @@ static ssize_t led_device_name_store(struct device *dev,
set_baseline_state(trigger_data); /* updates LEDs, may start timers */ set_baseline_state(trigger_data); /* updates LEDs, may start timers */
} }
write_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return size; return size;
} }
@ -144,7 +144,7 @@ static ssize_t led_mode_show(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct led_netdev_data *trigger_data = led_cdev->trigger_data; struct led_netdev_data *trigger_data = led_cdev->trigger_data;
read_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
if (trigger_data->mode == 0) { if (trigger_data->mode == 0) {
strcpy(buf, "none\n"); strcpy(buf, "none\n");
@ -158,7 +158,7 @@ static ssize_t led_mode_show(struct device *dev,
strcat(buf, "\n"); strcat(buf, "\n");
} }
read_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return strlen(buf)+1; return strlen(buf)+1;
} }
@ -199,10 +199,10 @@ static ssize_t led_mode_store(struct device *dev,
if (new_mode == -1) if (new_mode == -1)
return -EINVAL; return -EINVAL;
write_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
trigger_data->mode = new_mode; trigger_data->mode = new_mode;
set_baseline_state(trigger_data); set_baseline_state(trigger_data);
write_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return size; return size;
} }
@ -215,9 +215,9 @@ static ssize_t led_interval_show(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev); struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct led_netdev_data *trigger_data = led_cdev->trigger_data; struct led_netdev_data *trigger_data = led_cdev->trigger_data;
read_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
sprintf(buf, "%u\n", jiffies_to_msecs(trigger_data->interval)); sprintf(buf, "%u\n", jiffies_to_msecs(trigger_data->interval));
read_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return strlen(buf) + 1; return strlen(buf) + 1;
} }
@ -237,10 +237,10 @@ static ssize_t led_interval_store(struct device *dev,
/* impose some basic bounds on the timer interval */ /* impose some basic bounds on the timer interval */
if (count == size && value >= 5 && value <= 10000) { if (count == size && value >= 5 && value <= 10000) {
write_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
trigger_data->interval = msecs_to_jiffies(value); trigger_data->interval = msecs_to_jiffies(value);
set_baseline_state(trigger_data); /* resets timer */ set_baseline_state(trigger_data); /* resets timer */
write_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
ret = count; ret = count;
} }
@ -259,7 +259,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER) if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER)
return NOTIFY_DONE; return NOTIFY_DONE;
write_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
if (strcmp(dev->name, trigger_data->device_name)) if (strcmp(dev->name, trigger_data->device_name))
goto done; goto done;
@ -285,7 +285,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
set_baseline_state(trigger_data); set_baseline_state(trigger_data);
done: done:
write_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
return NOTIFY_DONE; return NOTIFY_DONE;
} }
@ -297,7 +297,7 @@ static void netdev_trig_timer(unsigned long arg)
unsigned new_activity; unsigned new_activity;
struct rtnl_link_stats64 temp; struct rtnl_link_stats64 temp;
write_lock(&trigger_data->lock); spin_lock(&trigger_data->lock);
if (!trigger_data->link_up || !trigger_data->net_dev || (trigger_data->mode & (MODE_TX | MODE_RX)) == 0) { if (!trigger_data->link_up || !trigger_data->net_dev || (trigger_data->mode & (MODE_TX | MODE_RX)) == 0) {
/* we don't need to do timer work, just reflect link state. */ /* we don't need to do timer work, just reflect link state. */
@ -336,7 +336,7 @@ static void netdev_trig_timer(unsigned long arg)
mod_timer(&trigger_data->timer, jiffies + trigger_data->interval); mod_timer(&trigger_data->timer, jiffies + trigger_data->interval);
no_restart: no_restart:
write_unlock(&trigger_data->lock); spin_unlock(&trigger_data->lock);
} }
static void netdev_trig_activate(struct led_classdev *led_cdev) static void netdev_trig_activate(struct led_classdev *led_cdev)
@ -348,7 +348,7 @@ static void netdev_trig_activate(struct led_classdev *led_cdev)
if (!trigger_data) if (!trigger_data)
return; return;
rwlock_init(&trigger_data->lock); spin_lock_init(&trigger_data->lock);
trigger_data->notifier.notifier_call = netdev_trig_notify; trigger_data->notifier.notifier_call = netdev_trig_notify;
trigger_data->notifier.priority = 10; trigger_data->notifier.priority = 10;
@ -399,14 +399,14 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)
device_remove_file(led_cdev->dev, &dev_attr_mode); device_remove_file(led_cdev->dev, &dev_attr_mode);
device_remove_file(led_cdev->dev, &dev_attr_interval); device_remove_file(led_cdev->dev, &dev_attr_interval);
write_lock(&trigger_data->lock); spin_lock_bh(&trigger_data->lock);
if (trigger_data->net_dev) { if (trigger_data->net_dev) {
dev_put(trigger_data->net_dev); dev_put(trigger_data->net_dev);
trigger_data->net_dev = NULL; trigger_data->net_dev = NULL;
} }
write_unlock(&trigger_data->lock); spin_unlock_bh(&trigger_data->lock);
del_timer_sync(&trigger_data->timer); del_timer_sync(&trigger_data->timer);

Loading…
Cancel
Save