sh: push-switch: use sysfs_emit() in switch_show
PATCH 1/2 sh: push-switch: use sysfs_emit() in switch_show
Replace sprintf() with sysfs_emit() in switch_show(). sysfs_emit() is preferred for formatting sysfs output because it provides safer bounds checking.
Signed-off-by Thorsten Blum <[email protected]>
--- arch/sh/drivers/push-switch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sh/drivers/push-switch.c +2 -1
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/sysfs.h> #include <asm/push-switch.h> #define DRV_NAME "push-switch"
@@ -19,7 +20,7 @@ static ssize_t switch_show(struct device *dev, char *buf) {struct push_switch_platform_info *psw_info = dev->platform_data; -return sprintf (buf,"%s\n" , psw_info->name); +return sysfs_emit (buf,"%s\n" , psw_info->name); }static DEVICE_ATTR_RO (switch);
PATCH 2/2 sh: sq: use sysfs_emit_at() in mapping_show
Replace sprintf() with sysfs_emit_at() in mapping_show(). sysfs_emit_at() is preferred for formatting sysfs output because it provides safer bounds checking and avoids manual buffer size accounting.
Signed-off-by Thorsten Blum <[email protected]>
--- arch/sh/kernel/cpu/sh4/sq.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/sh/kernel/cpu/sh4/sq.c +6 -5
@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/sysfs.h> #include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/io.h>
@@ -289,14 +290,14 @@ static ssize_t sq_sysfs_store(struct kobject *kobj, struct attribute *attr,static ssize_t mapping_show (char *buf) {struct sq_mapping **list, *entry; -char *p = buf; +ssize_t len =0 ;for (list = &sq_mapping_list; (entry = *list); list = &entry->next) - p +=sprintf (p,"%08lx-%08lx [%08lx]: %s\n" , - entry->sq_addr, entry->sq_addr + entry->size, - entry->addr, entry->name); + len +=sysfs_emit_at (buf, len,"%08lx-%08lx [%08lx]: %s\n" , + entry->sq_addr, entry->sq_addr + entry->size, + entry->addr, entry->name); -return p - buf; +return len; }static ssize_t mapping_store (const char *buf,size_t count)