leds: use sysfs_emit() to instead of scnprintf()

Replace the open-code with sysfs_emit() to simplify the code.

Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
This commit is contained in:
ye xingchen 2022-12-01 16:11:24 +08:00 committed by Pavel Machek
parent 135780f104
commit 3f6fb1cfaf
5 changed files with 14 additions and 14 deletions

View File

@ -139,11 +139,11 @@ static ssize_t show_color_common(struct device *dev, char *buf, int color)
return ret;
switch (color) {
case RED:
return scnprintf(buf, PAGE_SIZE, "%02X\n", data->red);
return sysfs_emit(buf, "%02X\n", data->red);
case GREEN:
return scnprintf(buf, PAGE_SIZE, "%02X\n", data->green);
return sysfs_emit(buf, "%02X\n", data->green);
case BLUE:
return scnprintf(buf, PAGE_SIZE, "%02X\n", data->blue);
return sysfs_emit(buf, "%02X\n", data->blue);
default:
return -EINVAL;
}
@ -253,7 +253,7 @@ static DEVICE_ATTR_RW(blue);
static ssize_t test_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE,
return sysfs_emit(buf,
"#Write into test to start test sequence!#\n");
}

View File

@ -314,7 +314,7 @@ static ssize_t show_id(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct lm3533_led *led = to_lm3533_led(led_cdev);
return scnprintf(buf, PAGE_SIZE, "%d\n", led->id);
return sysfs_emit(buf, "%d\n", led->id);
}
/*
@ -344,7 +344,7 @@ static ssize_t show_risefalltime(struct device *dev,
if (ret)
return ret;
return scnprintf(buf, PAGE_SIZE, "%x\n", val);
return sysfs_emit(buf, "%x\n", val);
}
static ssize_t show_risetime(struct device *dev,
@ -415,7 +415,7 @@ static ssize_t show_als_channel(struct device *dev,
channel = (val & LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK) + 1;
return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
return sysfs_emit(buf, "%u\n", channel);
}
static ssize_t store_als_channel(struct device *dev,
@ -465,7 +465,7 @@ static ssize_t show_als_en(struct device *dev,
enable = val & LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
return sysfs_emit(buf, "%d\n", enable);
}
static ssize_t store_als_en(struct device *dev,
@ -518,7 +518,7 @@ static ssize_t show_linear(struct device *dev,
else
linear = 0;
return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
return sysfs_emit(buf, "%x\n", linear);
}
static ssize_t store_linear(struct device *dev,
@ -564,7 +564,7 @@ static ssize_t show_pwm(struct device *dev,
if (ret)
return ret;
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
return sysfs_emit(buf, "%u\n", val);
}
static ssize_t store_pwm(struct device *dev,

View File

@ -469,7 +469,7 @@ static ssize_t lp5521_selftest(struct device *dev,
ret = lp5521_run_selftest(chip, buf);
mutex_unlock(&chip->lock);
return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK");
return sysfs_emit(buf, "%s\n", ret ? "FAIL" : "OK");
}
/* device attributes */

View File

@ -88,7 +88,7 @@ static ssize_t led_current_show(struct device *dev,
{
struct lp55xx_led *led = dev_to_lp55xx_led(dev);
return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current);
return sysfs_emit(buf, "%d\n", led->led_current);
}
static ssize_t led_current_store(struct device *dev,
@ -121,7 +121,7 @@ static ssize_t max_current_show(struct device *dev,
{
struct lp55xx_led *led = dev_to_lp55xx_led(dev);
return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current);
return sysfs_emit(buf, "%d\n", led->max_current);
}
static DEVICE_ATTR_RW(led_current);

View File

@ -155,7 +155,7 @@ static ssize_t repeat_show(struct device *dev, struct device_attribute *attr,
mutex_unlock(&data->lock);
return scnprintf(buf, PAGE_SIZE, "%d\n", repeat);
return sysfs_emit(buf, "%d\n", repeat);
}
static ssize_t repeat_store(struct device *dev, struct device_attribute *attr,