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

gpiolib: sysfs: Move sysfs_emit() calls outside of the mutex lock

In a few places we perform sysfs_emit() operations under mutex that
do not require any locking. Move them outside of the mutex locks.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
e28747da 4398693a

+14 -15
+14 -15
drivers/gpio/gpiolib-sysfs.c
··· 61 61 { 62 62 struct gpiod_data *data = dev_get_drvdata(dev); 63 63 struct gpio_desc *desc = data->desc; 64 - ssize_t status; 64 + int value; 65 65 66 66 mutex_lock(&data->mutex); 67 67 68 68 gpiod_get_direction(desc); 69 - status = sysfs_emit(buf, "%s\n", 70 - test_bit(FLAG_IS_OUT, &desc->flags) ? "out" : "in"); 69 + value = !!test_bit(FLAG_IS_OUT, &desc->flags); 71 70 72 71 mutex_unlock(&data->mutex); 73 72 74 - return status; 73 + return sysfs_emit(buf, "%s\n", value ? "out" : "in"); 75 74 } 76 75 77 76 static ssize_t direction_store(struct device *dev, ··· 107 108 mutex_lock(&data->mutex); 108 109 109 110 status = gpiod_get_value_cansleep(desc); 110 - if (status >= 0) 111 - status = sysfs_emit(buf, "%zd\n", status); 112 111 113 112 mutex_unlock(&data->mutex); 114 113 115 - return status; 114 + if (status < 0) 115 + return status; 116 + 117 + return sysfs_emit(buf, "%zd\n", status); 116 118 } 117 119 118 120 static ssize_t value_store(struct device *dev, ··· 238 238 struct device_attribute *attr, char *buf) 239 239 { 240 240 struct gpiod_data *data = dev_get_drvdata(dev); 241 - ssize_t status = 0; 242 241 int i; 243 242 244 243 mutex_lock(&data->mutex); ··· 246 247 if (data->irq_flags == trigger_types[i].flags) 247 248 break; 248 249 } 249 - if (i < ARRAY_SIZE(trigger_types)) 250 - status = sysfs_emit(buf, "%s\n", trigger_types[i].name); 251 250 252 251 mutex_unlock(&data->mutex); 253 252 254 - return status; 253 + if (i >= ARRAY_SIZE(trigger_types)) 254 + return 0; 255 + 256 + return sysfs_emit(buf, "%s\n", trigger_types[i].name); 255 257 } 256 258 257 259 static ssize_t edge_store(struct device *dev, ··· 324 324 { 325 325 struct gpiod_data *data = dev_get_drvdata(dev); 326 326 struct gpio_desc *desc = data->desc; 327 - ssize_t status; 327 + int value; 328 328 329 329 mutex_lock(&data->mutex); 330 330 331 - status = sysfs_emit(buf, "%d\n", 332 - !!test_bit(FLAG_ACTIVE_LOW, &desc->flags)); 331 + value = !!test_bit(FLAG_ACTIVE_LOW, &desc->flags); 333 332 334 333 mutex_unlock(&data->mutex); 335 334 336 - return status; 335 + return sysfs_emit(buf, "%d\n", value); 337 336 } 338 337 339 338 static ssize_t active_low_store(struct device *dev,