counter/counter-sysfs: use sysfs_emit everywhere
authorDavid Lechner <david@lechnology.com>
Sun, 17 Oct 2021 19:01:06 +0000 (14:01 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Oct 2021 07:40:49 +0000 (09:40 +0200)
In the counter subsystem, we are already using sysfs_emit(), but there
were a few places where we were still using sprintf() in *_show()
functions. For consistency and added protections, use sysfs_emit()
everywhere.

Suggested-by: Greg KH <gregkh@linuxfoundation.org>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: David Lechner <david@lechnology.com>
Link: https://lore.kernel.org/r/20211017190106.3472645-1-david@lechnology.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/counter/counter-sysfs.c

index 1ccd771da25ff038e505306dfc5095fc29cf78a7..c2fddbb0d442a2308c0e0ad2353c6cf44b6e52cd 100644 (file)
@@ -113,7 +113,7 @@ static ssize_t counter_comp_u8_show(struct device *dev,
                /* data should already be boolean but ensure just to be safe */
                data = !!data;
 
-       return sprintf(buf, "%u\n", (unsigned int)data);
+       return sysfs_emit(buf, "%u\n", (unsigned int)data);
 }
 
 static ssize_t counter_comp_u8_store(struct device *dev,
@@ -196,7 +196,7 @@ static ssize_t counter_comp_u32_show(struct device *dev,
        case COUNTER_COMP_COUNT_MODE:
                return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]);
        default:
-               return sprintf(buf, "%u\n", (unsigned int)data);
+               return sysfs_emit(buf, "%u\n", (unsigned int)data);
        }
 }
 
@@ -300,7 +300,7 @@ static ssize_t counter_comp_u64_show(struct device *dev,
        if (err < 0)
                return err;
 
-       return sprintf(buf, "%llu\n", (unsigned long long)data);
+       return sysfs_emit(buf, "%llu\n", (unsigned long long)data);
 }
 
 static ssize_t counter_comp_u64_store(struct device *dev,
@@ -539,7 +539,7 @@ static ssize_t counter_comp_id_show(struct device *dev,
 {
        const size_t id = (size_t)to_counter_attribute(attr)->comp.priv;
 
-       return sprintf(buf, "%zu\n", id);
+       return sysfs_emit(buf, "%zu\n", id);
 }
 
 static int counter_comp_id_attr_create(struct device *const dev,