diff options
author | Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk> | 2018-02-13 13:53:50 +0000 |
---|---|---|
committer | John Crispin <john@phrozen.org> | 2018-02-14 07:54:24 +0100 |
commit | 0b4e3b1bed6d0281cdad152724ba9224d5647437 (patch) | |
tree | 5e606355218318584ded2902332ee56308180a18 /target/linux/generic/files | |
parent | eb8fbc431879a698b5bd8f3bcb8a057ce01793c0 (diff) | |
download | upstream-0b4e3b1bed6d0281cdad152724ba9224d5647437.tar.gz upstream-0b4e3b1bed6d0281cdad152724ba9224d5647437.tar.bz2 upstream-0b4e3b1bed6d0281cdad152724ba9224d5647437.zip |
generic: swconfig: reduce lock duration on sysfs files
sysfs attributes 'port_mask' & 'speed_mask' held locks whilst doing
mundane tasks such as sprintf. Refactor code to reduce length of time
locks are held unnecessarily.
Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Diffstat (limited to 'target/linux/generic/files')
-rw-r--r-- | target/linux/generic/files/drivers/net/phy/swconfig_leds.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/target/linux/generic/files/drivers/net/phy/swconfig_leds.c b/target/linux/generic/files/drivers/net/phy/swconfig_leds.c index 92be3c7501..91824b7cf6 100644 --- a/target/linux/generic/files/drivers/net/phy/swconfig_leds.c +++ b/target/linux/generic/files/drivers/net/phy/swconfig_leds.c @@ -124,18 +124,16 @@ swconfig_trig_port_mask_store(struct device *dev, struct device_attribute *attr, return ret; write_lock(&trig_data->lock); - changed = (trig_data->port_mask != port_mask); + trig_data->port_mask = port_mask; + write_unlock(&trig_data->lock); + if (changed) { - trig_data->port_mask = port_mask; if (port_mask == 0) swconfig_trig_set_brightness(trig_data, LED_OFF); - } - write_unlock(&trig_data->lock); - - if (changed) swconfig_trig_update_port_mask(led_cdev->trigger); + } return size; } @@ -146,11 +144,14 @@ swconfig_trig_port_mask_show(struct device *dev, struct device_attribute *attr, { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct swconfig_trig_data *trig_data = led_cdev->trigger_data; + u32 port_mask; read_lock(&trig_data->lock); - sprintf(buf, "%#x\n", trig_data->port_mask); + port_mask = trig_data->port_mask; read_unlock(&trig_data->lock); + sprintf(buf, "%#x\n", port_mask); + return strlen(buf) + 1; } @@ -164,11 +165,14 @@ static ssize_t swconfig_trig_speed_mask_show(struct device *dev, { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct swconfig_trig_data *trig_data = led_cdev->trigger_data; + u8 speed_mask; read_lock(&trig_data->lock); - sprintf(buf, "%#x\n", trig_data->speed_mask); + speed_mask = trig_data->speed_mask; read_unlock(&trig_data->lock); + sprintf(buf, "%#x\n", speed_mask); + return strlen(buf) + 1; } |