Skip to contentSkip to conversation

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

PATCH In review [email protected] 3 participants 3 messages Sep 23, 2022 – Sep 26, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backlight: use sysfs_emit() to instead of scnprintf()

From: ye xingchen <[email protected]>

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

---
 drivers/video/backlight/lm3533_bl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/video/backlight/lm3533_bl.c +5 -5
index 1df1b6643c0b..5e2ce9285245 100644
@@ -66,7 +66,7 @@ static ssize_t show_id(struct device *dev,
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 
-	return scnprintf(buf, PAGE_SIZE, "%d\n", bl->id);
+	return sysfs_emit(buf, "%d\n", bl->id);
 }
 
 static ssize_t show_als_channel(struct device *dev,
@@ -75,7 +75,7 @@ static ssize_t show_als_channel(struct device *dev,
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	unsigned channel = lm3533_bl_get_ctrlbank_id(bl);
 
-	return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
+	return sysfs_emit(buf, "%u\n", channel);
 }
 
 static ssize_t show_als_en(struct device *dev,
@@ -95,7 +95,7 @@ static ssize_t show_als_en(struct device *dev,
 	mask = 1 << (2 * ctrlbank);
 	enable = val & 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,
@@ -147,7 +147,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,
@@ -190,7 +190,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,
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Thu, Sep 22, 2022 <[email protected]> wrote:

From: ye xingchen <[email protected]>

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

Best regards,
Jingoo Han

Quoted 55 lines
---
 drivers/video/backlight/lm3533_bl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/video/backlight/lm3533_bl.c +5 -6
index 1df1b6643c0b..5e2ce9285245 100644
@@ -66,7 +66,7 @@ static ssize_t show_id(struct device *dev,
 {
        struct lm3533_bl *bl = dev_get_drvdata(dev);
 
-       return scnprintf(buf, PAGE_SIZE, "%d\n", bl->id);
+       return sysfs_emit(buf, "%d\n", bl->id);
 }
 
 static ssize_t show_als_channel(struct device *dev,
@@ -75,7 +75,7 @@ static ssize_t show_als_channel(struct device *dev,
        struct lm3533_bl *bl = dev_get_drvdata(dev);
        unsigned channel = lm3533_bl_get_ctrlbank_id(bl);
 
-       return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
+       return sysfs_emit(buf, "%u\n", channel);
 }
 
 static ssize_t show_als_en(struct device *dev,
@@ -95,7 +95,7 @@ static ssize_t show_als_en(struct device *dev,
        mask = 1 << (2 * ctrlbank);
        enable = val & 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,
@@ -147,7 +147,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,
@@ -190,7 +190,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,
--

2.25.1

#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Fri, Sep 23, 2022 at 06:34:48AM +0000, [email protected] wrote:

Subject: [PATCH linux-next] backlight: use sysfs_emit() to instead of scnprintf()
From: ye xingchen <[email protected]>

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

---
 drivers/video/backlight/lm3533_bl.c | 10 +++++-----

Looks like a good change but the topic tag ('backlight:') looks a bit generic for something that only impacts the lm3533_bl.c driver.

Also it would be good if this patchset included the same fix for *all* drivers that a grep shows contain this code pattern (e.g. git grep 'return scnprintf.*PAGE_SIZE').

Daniel.