]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
powerpc: use sysfs_emit{_at} in sysfs show functions
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 24 May 2026 13:00:03 +0000 (15:00 +0200)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Tue, 2 Jun 2026 05:54:32 +0000 (11:24 +0530)
Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
functions, which are preferred for formatting sysfs output because they
provide safer bounds checking.

While the current code only emits strings that fit easily within
PAGE_SIZE, use sysfs_emit() and sysfs_emit_at() to follow secure coding
best practices.

This is a mechanical cleanup with a few simple edge cases:

- In domains_show(), drop the redundant n < 0 check since neither
  sprintf() nor sysfs_emit() return negative values.

- In powercap_show() and psr_show(), also drop the dead ret < 0 checks.

- In ps3_fw_version_show(), normalize the output by adding a terminating
  newline as suggested by checkpatch.

- In vio's modalias_show(), replace the deprecated strcpy() [1] followed
  by strlen() with sysfs_emit().

Leave validate_show() and the variable-length hv-gpci helpers unchanged
since they already have explicit bounds handling, and converting those
would be more than a mechanical conversion.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20260524130002.793476-2-thorsten.blum@linux.dev
31 files changed:
arch/powerpc/kernel/cacheinfo.c
arch/powerpc/kernel/eeh_sysfs.c
arch/powerpc/kernel/fadump.c
arch/powerpc/kernel/iommu.c
arch/powerpc/kernel/security.c
arch/powerpc/kernel/sysfs.c
arch/powerpc/perf/core-book3s.c
arch/powerpc/perf/hv-24x7.c
arch/powerpc/perf/hv-gpci.c
arch/powerpc/perf/kvm-hv-pmu.c
arch/powerpc/perf/vpa-pmu.c
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
arch/powerpc/platforms/cell/spu_base.c
arch/powerpc/platforms/powernv/idle.c
arch/powerpc/platforms/powernv/opal-dump.c
arch/powerpc/platforms/powernv/opal-elog.c
arch/powerpc/platforms/powernv/opal-flash.c
arch/powerpc/platforms/powernv/opal-powercap.c
arch/powerpc/platforms/powernv/opal-psr.c
arch/powerpc/platforms/powernv/subcore.c
arch/powerpc/platforms/ps3/setup.c
arch/powerpc/platforms/pseries/cmm.c
arch/powerpc/platforms/pseries/dlpar.c
arch/powerpc/platforms/pseries/ibmebus.c
arch/powerpc/platforms/pseries/papr_scm.c
arch/powerpc/platforms/pseries/power.c
arch/powerpc/platforms/pseries/pseries_energy.c
arch/powerpc/platforms/pseries/suspend.c
arch/powerpc/platforms/pseries/vas-sysfs.c
arch/powerpc/platforms/pseries/vio.c
arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c

index 90d51d9b3ed23d8f9d805cbb25142bbabc943f9e..04e5ea38bdc0a8ecc01b34dec0b0c9aedacc4f24 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/of.h>
 #include <linux/percpu.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <asm/cputhreads.h>
 #include <asm/smp.h>
 
@@ -596,7 +597,7 @@ static ssize_t size_show(struct kobject *k, struct kobj_attribute *attr, char *b
        if (cache_size_kb(cache, &size_kb))
                return -ENODEV;
 
-       return sprintf(buf, "%uK\n", size_kb);
+       return sysfs_emit(buf, "%uK\n", size_kb);
 }
 
 static struct kobj_attribute cache_size_attr =
@@ -613,7 +614,7 @@ static ssize_t line_size_show(struct kobject *k, struct kobj_attribute *attr, ch
        if (cache_get_line_size(cache, &line_size))
                return -ENODEV;
 
-       return sprintf(buf, "%u\n", line_size);
+       return sysfs_emit(buf, "%u\n", line_size);
 }
 
 static struct kobj_attribute cache_line_size_attr =
@@ -629,7 +630,7 @@ static ssize_t nr_sets_show(struct kobject *k, struct kobj_attribute *attr, char
        if (cache_nr_sets(cache, &nr_sets))
                return -ENODEV;
 
-       return sprintf(buf, "%u\n", nr_sets);
+       return sysfs_emit(buf, "%u\n", nr_sets);
 }
 
 static struct kobj_attribute cache_nr_sets_attr =
@@ -645,7 +646,7 @@ static ssize_t associativity_show(struct kobject *k, struct kobj_attribute *attr
        if (cache_associativity(cache, &associativity))
                return -ENODEV;
 
-       return sprintf(buf, "%u\n", associativity);
+       return sysfs_emit(buf, "%u\n", associativity);
 }
 
 static struct kobj_attribute cache_assoc_attr =
@@ -657,7 +658,7 @@ static ssize_t type_show(struct kobject *k, struct kobj_attribute *attr, char *b
 
        cache = index_kobj_to_cache(k);
 
-       return sprintf(buf, "%s\n", cache_type_string(cache));
+       return sysfs_emit(buf, "%s\n", cache_type_string(cache));
 }
 
 static struct kobj_attribute cache_type_attr =
@@ -671,7 +672,7 @@ static ssize_t level_show(struct kobject *k, struct kobj_attribute *attr, char *
        index = kobj_to_cache_index_dir(k);
        cache = index->cache;
 
-       return sprintf(buf, "%d\n", cache->level);
+       return sysfs_emit(buf, "%d\n", cache->level);
 }
 
 static struct kobj_attribute cache_level_attr =
index 706e1eb95efe6d45d942d6165c8b2fa8bcf8eb12..b9785f105f75194202ac2c94eea1cf754110acf8 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/of.h>
 #include <linux/pci.h>
 #include <linux/stat.h>
+#include <linux/sysfs.h>
 #include <asm/ppc-pci.h>
 #include <asm/pci-bridge.h>
 
@@ -31,7 +32,7 @@ static ssize_t eeh_show_##_name(struct device *dev,      \
        if (!edev)                                            \
                return 0;                                     \
                                                              \
-       return sprintf(buf, _format "\n", edev->_memb);       \
+       return sysfs_emit(buf, _format "\n", edev->_memb);    \
 }                                                        \
 static DEVICE_ATTR(_name, 0444, eeh_show_##_name, NULL);
 
@@ -49,8 +50,7 @@ static ssize_t eeh_pe_state_show(struct device *dev,
                return -ENODEV;
 
        state = eeh_ops->get_state(edev->pe, NULL);
-       return sprintf(buf, "0x%08x 0x%08x\n",
-                      state, edev->pe->state);
+       return sysfs_emit(buf, "0x%08x 0x%08x\n", state, edev->pe->state);
 }
 
 static ssize_t eeh_pe_state_store(struct device *dev,
@@ -87,7 +87,7 @@ static ssize_t eeh_notify_resume_show(struct device *dev,
        if (!edev || !edev->pe)
                return -ENODEV;
 
-       return sprintf(buf, "%d\n", pdn->last_allow_rc);
+       return sysfs_emit(buf, "%d\n", pdn->last_allow_rc);
 }
 
 static ssize_t eeh_notify_resume_store(struct device *dev,
index 501d43bf18f3a171d4b4c0dce5deeecf2bfb1d59..a313b1653124bf490565124d73503945b068f432 100644 (file)
@@ -1422,7 +1422,7 @@ static ssize_t enabled_show(struct kobject *kobj,
                            struct kobj_attribute *attr,
                            char *buf)
 {
-       return sprintf(buf, "%d\n", fw_dump.fadump_enabled);
+       return sysfs_emit(buf, "%d\n", fw_dump.fadump_enabled);
 }
 
 /*
@@ -1434,28 +1434,28 @@ static ssize_t hotplug_ready_show(struct kobject *kobj,
                                      struct kobj_attribute *attr,
                                      char *buf)
 {
-       return sprintf(buf, "%d\n", 1);
+       return sysfs_emit(buf, "%d\n", 1);
 }
 
 static ssize_t mem_reserved_show(struct kobject *kobj,
                                 struct kobj_attribute *attr,
                                 char *buf)
 {
-       return sprintf(buf, "%ld\n", fw_dump.reserve_dump_area_size);
+       return sysfs_emit(buf, "%ld\n", fw_dump.reserve_dump_area_size);
 }
 
 static ssize_t registered_show(struct kobject *kobj,
                               struct kobj_attribute *attr,
                               char *buf)
 {
-       return sprintf(buf, "%d\n", fw_dump.dump_registered);
+       return sysfs_emit(buf, "%d\n", fw_dump.dump_registered);
 }
 
 static ssize_t bootargs_append_show(struct kobject *kobj,
                                   struct kobj_attribute *attr,
                                   char *buf)
 {
-       return sprintf(buf, "%s\n", (char *)__va(fw_dump.param_area));
+       return sysfs_emit(buf, "%s\n", (char *)__va(fw_dump.param_area));
 }
 
 static ssize_t bootargs_append_store(struct kobject *kobj,
index d122e8447831c9673ef1bdd4e98a1b15477de4f4..ee1b5cb557c9a68125b766137b39c4b6e3107253 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/mm.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
@@ -141,7 +142,7 @@ late_initcall(fail_iommu_debugfs);
 static ssize_t fail_iommu_show(struct device *dev,
                               struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", dev->archdata.fail_iommu);
+       return sysfs_emit(buf, "%d\n", dev->archdata.fail_iommu);
 }
 
 static ssize_t fail_iommu_store(struct device *dev,
index fbb7ebd8aa08bcb7d08903c1507993ad214ef415..600596cb4ffbde538d17c93f7bba3f77ef5f407c 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/nospec.h>
 #include <linux/prctl.h>
 #include <linux/seq_buf.h>
+#include <linux/sysfs.h>
 #include <linux/debugfs.h>
 
 #include <asm/asm-prototypes.h>
@@ -163,13 +164,13 @@ ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, cha
        }
 
        if (thread_priv)
-               return sprintf(buf, "Vulnerable: L1D private per thread\n");
+               return sysfs_emit(buf, "Vulnerable: L1D private per thread\n");
 
        if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
            !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
-               return sprintf(buf, "Not affected\n");
+               return sysfs_emit(buf, "Not affected\n");
 
-       return sprintf(buf, "Vulnerable\n");
+       return sysfs_emit(buf, "Vulnerable\n");
 }
 
 ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *buf)
@@ -352,14 +353,14 @@ ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *
                default:
                        type = "unknown";
                }
-               return sprintf(buf, "Mitigation: Kernel entry/exit barrier (%s)\n", type);
+               return sysfs_emit(buf, "Mitigation: Kernel entry/exit barrier (%s)\n", type);
        }
 
        if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
            !security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
-               return sprintf(buf, "Not affected\n");
+               return sysfs_emit(buf, "Not affected\n");
 
-       return sprintf(buf, "Vulnerable\n");
+       return sysfs_emit(buf, "Vulnerable\n");
 }
 
 static int ssb_prctl_get(struct task_struct *task)
index 6b3dd6decdf900d540aee2603f311243723c0e84..329c1690b5ed35ccd11e06b119adf93bd3c0bfcb 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/percpu.h>
 #include <linux/init.h>
 #include <linux/sched.h>
+#include <linux/sysfs.h>
 #include <linux/export.h>
 #include <linux/nodemask.h>
 #include <linux/cpumask.h>
@@ -63,7 +64,7 @@ static ssize_t show_smt_snooze_delay(struct device *dev,
 {
        pr_warn_once("%s (%d) read from unsupported smt_snooze_delay\n",
                     current->comm, current->pid);
-       return sprintf(buf, "100\n");
+       return sysfs_emit(buf, "100\n");
 }
 
 static DEVICE_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
@@ -100,7 +101,7 @@ static ssize_t show_##NAME(struct device *dev, \
        struct cpu *cpu = container_of(dev, struct cpu, dev); \
        unsigned long val; \
        smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1);    \
-       return sprintf(buf, "%lx\n", val); \
+       return sysfs_emit(buf, "%lx\n", val); \
 } \
 static ssize_t __used \
        store_##NAME(struct device *dev, struct device_attribute *attr, \
@@ -183,7 +184,7 @@ static void add_write_permission_dev_attr(struct device_attribute *attr)
 static ssize_t show_dscr_default(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%lx\n", dscr_default);
+       return sysfs_emit(buf, "%lx\n", dscr_default);
 }
 
 /**
@@ -272,7 +273,7 @@ static ssize_t show_pw20_state(struct device *dev,
 
        value &= PWRMGTCR0_PW20_WAIT;
 
-       return sprintf(buf, "%u\n", value ? 1 : 0);
+       return sysfs_emit(buf, "%u\n", value ? 1 : 0);
 }
 
 static void do_store_pw20_state(void *val)
@@ -337,7 +338,7 @@ static ssize_t show_pw20_wait_time(struct device *dev,
                time = pw20_wt;
        }
 
-       return sprintf(buf, "%llu\n", time > 0 ? time : 0);
+       return sysfs_emit(buf, "%llu\n", time > 0 ? time : 0);
 }
 
 static void set_pw20_wait_entry_bit(void *val)
@@ -394,7 +395,7 @@ static ssize_t show_altivec_idle(struct device *dev,
 
        value &= PWRMGTCR0_AV_IDLE_PD_EN;
 
-       return sprintf(buf, "%u\n", value ? 1 : 0);
+       return sysfs_emit(buf, "%u\n", value ? 1 : 0);
 }
 
 static void do_store_altivec_idle(void *val)
@@ -459,7 +460,7 @@ static ssize_t show_altivec_idle_wait_time(struct device *dev,
                time = altivec_idle_wt;
        }
 
-       return sprintf(buf, "%llu\n", time > 0 ? time : 0);
+       return sysfs_emit(buf, "%llu\n", time > 0 ? time : 0);
 }
 
 static void set_altivec_idle_wait_entry_bit(void *val)
@@ -746,7 +747,7 @@ static struct device_attribute pa6t_attrs[] = {
 #ifdef CONFIG_PPC_SVM
 static ssize_t show_svm(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%u\n", is_secure_guest());
+       return sysfs_emit(buf, "%u\n", is_secure_guest());
 }
 static DEVICE_ATTR(svm, 0444, show_svm, NULL);
 
@@ -780,7 +781,7 @@ static ssize_t idle_purr_show(struct device *dev,
        u64 val;
 
        smp_call_function_single(cpu->dev.id, read_idle_purr, &val, 1);
-       return sprintf(buf, "%llx\n", val);
+       return sysfs_emit(buf, "%llx\n", val);
 }
 static DEVICE_ATTR(idle_purr, 0400, idle_purr_show, NULL);
 
@@ -810,7 +811,7 @@ static ssize_t idle_spurr_show(struct device *dev,
        u64 val;
 
        smp_call_function_single(cpu->dev.id, read_idle_spurr, &val, 1);
-       return sprintf(buf, "%llx\n", val);
+       return sysfs_emit(buf, "%llx\n", val);
 }
 static DEVICE_ATTR(idle_spurr, 0400, idle_spurr_show, NULL);
 
@@ -1143,7 +1144,7 @@ static ssize_t show_physical_id(struct device *dev,
 {
        struct cpu *cpu = container_of(dev, struct cpu, dev);
 
-       return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
+       return sysfs_emit(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
 }
 static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL);
 
index 802bc9b7ef6fad944d5f9f3d5ac0a27629c0ff64..720b1a5009226fcf64a6afc18a421c2593c64266 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/perf_event.h>
 #include <linux/percpu.h>
 #include <linux/hardirq.h>
+#include <linux/sysfs.h>
 #include <linux/uaccess.h>
 #include <asm/reg.h>
 #include <asm/pmc.h>
@@ -2204,7 +2205,7 @@ ssize_t power_events_sysfs_show(struct device *dev,
 
        pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
 
-       return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+       return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 static struct pmu power_pmu = {
index 243c0a1c8cda00f2c77b82adc0ff17e5d86cb101..abb4cfb11fcc97d05baf6dfcb509a3b85a3126f2 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/rbtree.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/vmalloc.h>
 
 #include <asm/cputhreads.h>
@@ -434,19 +435,19 @@ static ssize_t cpumask_show(struct device *dev,
 static ssize_t sockets_show(struct device *dev,
                            struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", phys_sockets);
+       return sysfs_emit(buf, "%d\n", phys_sockets);
 }
 
 static ssize_t chipspersocket_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", phys_chipspersocket);
+       return sysfs_emit(buf, "%d\n", phys_chipspersocket);
 }
 
 static ssize_t coresperchip_show(struct device *dev,
                                 struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", phys_coresperchip);
+       return sysfs_emit(buf, "%d\n", phys_coresperchip);
 }
 
 static struct attribute *device_str_attr_create_(char *name, char *str)
@@ -1061,7 +1062,7 @@ e_free:
 static ssize_t domains_show(struct device *dev, struct device_attribute *attr,
                            char *page)
 {
-       int d, n, count = 0;
+       int d, count = 0;
        const char *str;
 
        for (d = 0; d < HV_PERF_DOMAIN_MAX; d++) {
@@ -1069,12 +1070,7 @@ static ssize_t domains_show(struct device *dev, struct device_attribute *attr,
                if (!str)
                        continue;
 
-               n = sprintf(page, "%d: %s\n", d, str);
-               if (n < 0)
-                       break;
-
-               count += n;
-               page += n;
+               count += sysfs_emit_at(page, count, "%d: %s\n", d, str);
        }
        return count;
 }
@@ -1095,7 +1091,7 @@ static ssize_t _name##_show(struct device *dev,                   \
                ret = -EIO;                                     \
                goto e_free;                                    \
        }                                                       \
-       ret = sprintf(buf, _fmt, _expr);                        \
+       ret = sysfs_emit(buf, _fmt, _expr);                     \
 e_free:                                                                \
        kmem_cache_free(hv_page_cache, page);                   \
        return ret;                                             \
index 10c82cf8f5b39331847787a565fd05e4a52416d1..7269273d3aa88cd744da148ad23d8be46cdfa6c5 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/init.h>
 #include <linux/perf_event.h>
+#include <linux/sysfs.h>
 #include <asm/firmware.h>
 #include <asm/hvcall.h>
 #include <asm/io.h>
@@ -85,7 +86,7 @@ static ssize_t _name##_show(struct device *dev,                       \
        if (hret)                                               \
                return -EIO;                                    \
                                                                \
-       return sprintf(page, _format, caps._name);              \
+       return sysfs_emit(page, _format, caps._name);           \
 }                                                              \
 static struct device_attribute hv_caps_attr_##_name = __ATTR_RO(_name)
 
@@ -93,7 +94,7 @@ static ssize_t kernel_version_show(struct device *dev,
                                   struct device_attribute *attr,
                                   char *page)
 {
-       return sprintf(page, "0x%x\n", COUNTER_INFO_VERSION_CURRENT);
+       return sysfs_emit(page, "0x%x\n", COUNTER_INFO_VERSION_CURRENT);
 }
 
 static ssize_t cpumask_show(struct device *dev,
index ae264c9080ef6996fafbcbb8a85bbf66c8f15ca3..aa72b96b5a8cef5b69d2fbd799404850cc089d03 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/perf_event.h>
 #include <linux/spinlock_types.h>
 #include <linux/spinlock.h>
+#include <linux/sysfs.h>
 
 #include <asm/types.h>
 #include <asm/kvm_ppc.h>
@@ -48,7 +49,7 @@ static ssize_t kvmppc_events_sysfs_show(struct device *dev,
        struct perf_pmu_events_attr *pmu_attr;
 
        pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
-       return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+       return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 /* Holds the hostwide stats */
index 8407334689596a9bdb6bc3883cf48015a38801a1..bff4cfab7b94549f12309d07bf05cd413f7b18d3 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/module.h>
 #include <linux/perf_event.h>
+#include <linux/sysfs.h>
 #include <asm/kvm_ppc.h>
 #include <asm/kvm_book3s_64.h>
 
@@ -26,7 +27,7 @@ static ssize_t vpa_pmu_events_sysfs_show(struct device *dev,
 
        pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
 
-       return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+       return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
 }
 
 #define VPA_PMU_EVENT_ATTR(_name, _id)                         \
index 9b693594a5f721f11c2eba8ec3c19d47a36e99a1..c3fbec1f1d24a736dde2b439798b5b793ff2a324 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/i2c.h>
 #include <linux/gpio/driver.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/kthread.h>
 #include <linux/property.h>
 #include <linux/reboot.h>
@@ -77,7 +78,7 @@ static ssize_t show_status(struct device *d,
                return -ENODEV;
        mcu->reg_ctrl = ret;
 
-       return sprintf(buf, "%02x\n", ret);
+       return sysfs_emit(buf, "%02x\n", ret);
 }
 static DEVICE_ATTR(status, 0444, show_status, NULL);
 
index 0ec7b3bdda5653ad782df2611b6a4ff07ccebdad..8452153d465007b507ed504ce2b2487549b7e802 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/mutex.h>
 #include <linux/linux_logo.h>
 #include <linux/syscore_ops.h>
+#include <linux/sysfs.h>
 #include <asm/spu.h>
 #include <asm/spu_priv1.h>
 #include <asm/spu_csa.h>
@@ -638,8 +639,8 @@ static ssize_t spu_stat_show(struct device *dev,
 {
        struct spu *spu = container_of(dev, struct spu, dev);
 
-       return sprintf(buf, "%s %llu %llu %llu %llu "
-                     "%llu %llu %llu %llu %llu %llu %llu %llu\n",
+       return sysfs_emit(buf,
+               "%s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
                spu_state_names[spu->stats.util_state],
                spu_acct_time(spu, SPU_UTIL_USER),
                spu_acct_time(spu, SPU_UTIL_SYSTEM),
index 6cd461f8296872f390bacdab68916b27a5baea16..33103a98cfd55416d0b1d3e13572fd5e2e9ac64e 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/of.h>
 #include <linux/device.h>
 #include <linux/cpu.h>
@@ -171,7 +172,7 @@ static u8 fastsleep_workaround_applyonce;
 static ssize_t show_fastsleep_workaround_applyonce(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%u\n", fastsleep_workaround_applyonce);
+       return sysfs_emit(buf, "%u\n", fastsleep_workaround_applyonce);
 }
 
 static ssize_t store_fastsleep_workaround_applyonce(struct device *dev,
index 2e4bffa741630ac4e33e947f0737c0e618c724e6..0586821d7af4cec1e22457f5c35255ac3ac4a4ad 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/kobject.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/vmalloc.h>
 #include <linux/pagemap.h>
 #include <linux/delay.h>
@@ -40,7 +41,7 @@ static ssize_t dump_id_show(struct dump_obj *dump_obj,
                            struct dump_attribute *attr,
                            char *buf)
 {
-       return sprintf(buf, "0x%x\n", dump_obj->id);
+       return sysfs_emit(buf, "0x%x\n", dump_obj->id);
 }
 
 static const char* dump_type_to_string(uint32_t type)
@@ -58,15 +59,15 @@ static ssize_t dump_type_show(struct dump_obj *dump_obj,
                              char *buf)
 {
 
-       return sprintf(buf, "0x%x %s\n", dump_obj->type,
-                      dump_type_to_string(dump_obj->type));
+       return sysfs_emit(buf, "0x%x %s\n", dump_obj->type,
+                         dump_type_to_string(dump_obj->type));
 }
 
 static ssize_t dump_ack_show(struct dump_obj *dump_obj,
                             struct dump_attribute *attr,
                             char *buf)
 {
-       return sprintf(buf, "ack - acknowledge dump\n");
+       return sysfs_emit(buf, "ack - acknowledge dump\n");
 }
 
 /*
@@ -114,7 +115,7 @@ static ssize_t init_dump_show(struct dump_obj *dump_obj,
                              struct dump_attribute *attr,
                              char *buf)
 {
-       return sprintf(buf, "1 - initiate Service Processor(FSP) dump\n");
+       return sysfs_emit(buf, "1 - initiate Service Processor(FSP) dump\n");
 }
 
 static int64_t dump_fips_init(uint8_t type)
index 2b8331922ab9b1fe516e6161262c026431e7588a..6cacd3fd3cd538e2ab20b44de02390724d37f56b 100644 (file)
@@ -40,7 +40,7 @@ static ssize_t elog_id_show(struct elog_obj *elog_obj,
                            struct elog_attribute *attr,
                            char *buf)
 {
-       return sprintf(buf, "0x%llx\n", elog_obj->id);
+       return sysfs_emit(buf, "0x%llx\n", elog_obj->id);
 }
 
 static const char *elog_type_to_string(uint64_t type)
@@ -55,16 +55,15 @@ static ssize_t elog_type_show(struct elog_obj *elog_obj,
                              struct elog_attribute *attr,
                              char *buf)
 {
-       return sprintf(buf, "0x%llx %s\n",
-                      elog_obj->type,
-                      elog_type_to_string(elog_obj->type));
+       return sysfs_emit(buf, "0x%llx %s\n", elog_obj->type,
+                         elog_type_to_string(elog_obj->type));
 }
 
 static ssize_t elog_ack_show(struct elog_obj *elog_obj,
                             struct elog_attribute *attr,
                             char *buf)
 {
-       return sprintf(buf, "ack - acknowledge log message\n");
+       return sysfs_emit(buf, "ack - acknowledge log message\n");
 }
 
 static ssize_t elog_ack_store(struct elog_obj *elog_obj,
index a3f7a2928767f98c809f230275acb617f64ad45d..5ca5f6329a2dca945791b2f8e27d95740df8d4b8 100644 (file)
@@ -238,7 +238,7 @@ static ssize_t manage_show(struct kobject *kobj,
        struct manage_flash_t *const args_buf = &manage_flash_data;
        int rc;
 
-       rc = sprintf(buf, "%d\n", args_buf->status);
+       rc = sysfs_emit(buf, "%d\n", args_buf->status);
        /* Set status to default*/
        args_buf->status = FLASH_NO_OP;
        return rc;
@@ -321,7 +321,7 @@ static ssize_t update_show(struct kobject *kobj,
                           struct kobj_attribute *attr, char *buf)
 {
        struct update_flash_t *const args_buf = &update_flash_data;
-       return sprintf(buf, "%d\n", args_buf->status);
+       return sysfs_emit(buf, "%d\n", args_buf->status);
 }
 
 /*
index 9bb73cb42a657cc19db402af263c68d322202c86..bf18b333281eadf9bb86f3cf467b24016b01a1aa 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/of.h>
 #include <linux/kobject.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 
 #include <asm/opal.h>
 
@@ -56,16 +57,11 @@ static ssize_t powercap_show(struct kobject *kobj, struct kobj_attribute *attr,
                        goto out;
                }
                ret = opal_error_code(opal_get_async_rc(msg));
-               if (!ret) {
-                       ret = sprintf(buf, "%u\n", be32_to_cpu(pcap));
-                       if (ret < 0)
-                               ret = -EIO;
-               }
+               if (!ret)
+                       ret = sysfs_emit(buf, "%u\n", be32_to_cpu(pcap));
                break;
        case OPAL_SUCCESS:
-               ret = sprintf(buf, "%u\n", be32_to_cpu(pcap));
-               if (ret < 0)
-                       ret = -EIO;
+               ret = sysfs_emit(buf, "%u\n", be32_to_cpu(pcap));
                break;
        default:
                ret = opal_error_code(ret);
index 24d0a894d965fee23b1b1be4a89a4699d5147a0e..19228181cb6f47e4863a91e0127cbf140e86b662 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/of.h>
 #include <linux/kobject.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 
 #include <asm/opal.h>
 
@@ -50,16 +51,11 @@ static ssize_t psr_show(struct kobject *kobj, struct kobj_attribute *attr,
                        goto out;
                }
                ret = opal_error_code(opal_get_async_rc(msg));
-               if (!ret) {
-                       ret = sprintf(buf, "%u\n", be32_to_cpu(psr));
-                       if (ret < 0)
-                               ret = -EIO;
-               }
+               if (!ret)
+                       ret = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
                break;
        case OPAL_SUCCESS:
-               ret = sprintf(buf, "%u\n", be32_to_cpu(psr));
-               if (ret < 0)
-                       ret = -EIO;
+               ret = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
                break;
        default:
                ret = opal_error_code(ret);
index 393e747541fbeb217bedf48d354099eb75290164..f7668ef1ac1fc186061e742a6f0850b44adf1c2d 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/gfp.h>
 #include <linux/smp.h>
 #include <linux/stop_machine.h>
+#include <linux/sysfs.h>
 
 #include <asm/cputhreads.h>
 #include <asm/cpuidle.h>
@@ -409,7 +410,7 @@ out:
 static ssize_t show_subcores_per_core(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%x\n", subcores_per_core);
+       return sysfs_emit(buf, "%x\n", subcores_per_core);
 }
 
 static DEVICE_ATTR(subcores_per_core, 0644,
index 150c09b58ae8ef40e0133b75963098e245b4325b..ca2608a70f4d27dd48b28f54213c88228a3f3c8f 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/root_dev.h>
+#include <linux/sysfs.h>
 #include <linux/console.h>
 #include <linux/export.h>
 #include <linux/memblock.h>
@@ -183,7 +184,7 @@ static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx)
 static ssize_t ps3_fw_version_show(struct kobject *kobj,
        struct kobj_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%s", ps3_firmware_version_str);
+       return sysfs_emit(buf, "%s\n", ps3_firmware_version_str);
 }
 
 static int __init ps3_setup_sysfs(void)
index 8d83df12430f29c9ccb6b04aec4aa44179e9d0a2..38e22125b96f0df303966745238d6fd3e8db18a9 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/sched.h>
 #include <linux/stringify.h>
 #include <linux/swap.h>
+#include <linux/sysfs.h>
 #include <linux/device.h>
 #include <linux/balloon.h>
 #include <asm/firmware.h>
@@ -333,7 +334,7 @@ static int cmm_thread(void *dummy)
                                   struct device_attribute *attr,       \
                                   char *buf)                   \
        {                                                       \
-               return sprintf(buf, format, ##args);            \
+               return sysfs_emit(buf, format, ##args);         \
        }                                                       \
        static DEVICE_ATTR(name, 0444, show_##name, NULL)
 
@@ -343,7 +344,7 @@ CMM_SHOW(loaned_target_kb, "%lu\n", PAGES2KB(loaned_pages_target));
 static ssize_t show_oom_pages(struct device *dev,
                              struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%lu\n", PAGES2KB(oom_freed_pages));
+       return sysfs_emit(buf, "%lu\n", PAGES2KB(oom_freed_pages));
 }
 
 static ssize_t store_oom_pages(struct device *dev,
index a7c451c2507d3d2cb50f655612c732e1a25a207f..f4d33b8dffd85490081dd6d29efe0b5b596251b9 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/cpu.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/of.h>
 
 #include "of_helpers.h"
@@ -798,7 +799,7 @@ dlpar_store_out:
 static ssize_t dlpar_show(const struct class *class, const struct class_attribute *attr,
                          char *buf)
 {
-       return sprintf(buf, "%s\n", "memory,cpu,dt");
+       return sysfs_emit(buf, "%s\n", "memory,cpu,dt");
 }
 
 static CLASS_ATTR_RW(dlpar);
index cad2deb7e70d9a1fc072b4a26970e8cc607f4232..2d0f991da2c8df958514b2df16c77d106a999001 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/stat.h>
+#include <linux/sysfs.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <asm/ibmebus.h>
@@ -399,7 +400,7 @@ static ssize_t devspec_show(struct device *dev,
        struct platform_device *ofdev;
 
        ofdev = to_platform_device(dev);
-       return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
+       return sysfs_emit(buf, "%pOF\n", ofdev->dev.of_node);
 }
 static DEVICE_ATTR_RO(devspec);
 
@@ -409,7 +410,7 @@ static ssize_t name_show(struct device *dev,
        struct platform_device *ofdev;
 
        ofdev = to_platform_device(dev);
-       return sprintf(buf, "%pOFn\n", ofdev->dev.of_node);
+       return sysfs_emit(buf, "%pOFn\n", ofdev->dev.of_node);
 }
 static DEVICE_ATTR_RO(name);
 
index 63eca4ebb5e5a1052db1327f704baf0eb9d7b1ae..75da96c08cdd82609471437c15db433ecb699da5 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/ioport.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/ndctl.h>
 #include <linux/sched.h>
 #include <linux/libnvdimm.h>
@@ -1062,8 +1063,8 @@ static ssize_t health_bitmap_inject_show(struct device *dev,
        struct nvdimm *dimm = to_nvdimm(dev);
        struct papr_scm_priv *p = nvdimm_provider_data(dimm);
 
-       return sprintf(buf, "%#llx\n",
-                      READ_ONCE(p->health_bitmap_inject_mask));
+       return sysfs_emit(buf, "%#llx\n",
+                         READ_ONCE(p->health_bitmap_inject_mask));
 }
 
 static DEVICE_ATTR_ADMIN_RO(health_bitmap_inject);
index 3676cb297767e5095cab9f540a44d1023e27014a..7b9dfe829f25440584673c437084387f4e462e28 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/kobject.h>
 #include <linux/string.h>
+#include <linux/sysfs.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <asm/machdep.h>
@@ -22,7 +23,7 @@ unsigned long rtas_poweron_auto; /* default and normal state is 0 */
 static ssize_t auto_poweron_show(struct kobject *kobj,
                                 struct kobj_attribute *attr, char *buf)
 {
-        return sprintf(buf, "%lu\n", rtas_poweron_auto);
+       return sysfs_emit(buf, "%lu\n", rtas_poweron_auto);
 }
 
 static ssize_t auto_poweron_store(struct kobject *kobj,
index 2c661b798235edfcd62789cb9e21b6d131f2f535..fdaf85ecd39b8b2cc53bcaf43166b0303dba7f69 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
+#include <linux/sysfs.h>
 #include <linux/device.h>
 #include <linux/cpu.h>
 #include <linux/of.h>
@@ -242,7 +243,7 @@ static ssize_t get_best_energy_data(struct device *dev,
        if (rc != H_SUCCESS)
                return -EINVAL;
 
-       return sprintf(page, "%lu\n", retbuf[1] >> 32);
+       return sysfs_emit(page, "%lu\n", retbuf[1] >> 32);
 }
 
 /* Wrapper functions */
index c51db63d3e88d38dfc42d84cc1b5532b6ca03b1e..a9928d75624a68029b865c3536cf24e288f78f40 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/delay.h>
 #include <linux/suspend.h>
 #include <linux/stat.h>
+#include <linux/sysfs.h>
 #include <asm/firmware.h>
 #include <asm/hvcall.h>
 #include <asm/machdep.h>
@@ -121,7 +122,7 @@ static ssize_t show_hibernate(struct device *dev,
                              struct device_attribute *attr,
                              char *buf)
 {
-       return sprintf(buf, "%d\n", KERN_DT_UPDATE);
+       return sysfs_emit(buf, "%d\n", KERN_DT_UPDATE);
 }
 
 static DEVICE_ATTR(hibernate, 0644, show_hibernate, store_hibernate);
index 4f6fbbb672aecf4ac8f1d69842e0e05b6565a64c..00c6ffd3ef39a78fef3cc6fa440bca66f93be46f 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/miscdevice.h>
 #include <linux/kobject.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/mm.h>
 
 #include "vas.h"
@@ -58,7 +59,7 @@ static ssize_t update_total_credits_store(struct vas_cop_feat_caps *caps,
 #define sysfs_caps_entry_read(_name)                                   \
 static ssize_t _name##_show(struct vas_cop_feat_caps *caps, char *buf)         \
 {                                                                      \
-       return sprintf(buf, "%d\n", atomic_read(&caps->_name)); \
+       return sysfs_emit(buf, "%d\n", atomic_read(&caps->_name));      \
 }
 
 struct vas_sysfs_entry {
index 08e2add48adb4f0ffb59c8bf878b24f02bbba63c..572bdf42335ed127c814611880d75ff2e0d8cfaf 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 #include <linux/delay.h>
 #include <linux/stat.h>
+#include <linux/sysfs.h>
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -942,14 +943,14 @@ static ssize_t cmo_##name##_show(struct device *dev,                    \
                                         struct device_attribute *attr,  \
                                          char *buf)                     \
 {                                                                       \
-       return sprintf(buf, "%lu\n", to_vio_dev(dev)->cmo.name);        \
+       return sysfs_emit(buf, "%lu\n", to_vio_dev(dev)->cmo.name);     \
 }
 
 static ssize_t cmo_allocs_failed_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
        struct vio_dev *viodev = to_vio_dev(dev);
-       return sprintf(buf, "%d\n", atomic_read(&viodev->cmo.allocs_failed));
+       return sysfs_emit(buf, "%d\n", atomic_read(&viodev->cmo.allocs_failed));
 }
 
 static ssize_t cmo_allocs_failed_store(struct device *dev,
@@ -998,7 +999,7 @@ static DEVICE_ATTR_RW(cmo_allocs_failed);
 #define viobus_cmo_rd_attr(name)                                        \
 static ssize_t cmo_bus_##name##_show(const struct bus_type *bt, char *buf)    \
 {                                                                       \
-       return sprintf(buf, "%lu\n", vio_cmo.name);                     \
+       return sysfs_emit(buf, "%lu\n", vio_cmo.name);                  \
 }                                                                       \
 static struct bus_attribute bus_attr_cmo_bus_##name =                  \
        __ATTR(cmo_##name, S_IRUGO, cmo_bus_##name##_show, NULL)
@@ -1007,7 +1008,7 @@ static struct bus_attribute bus_attr_cmo_bus_##name =                     \
 static ssize_t                                                          \
 cmo_##name##_##var##_show(const struct bus_type *bt, char *buf)         \
 {                                                                       \
-       return sprintf(buf, "%lu\n", vio_cmo.name.var);                 \
+       return sysfs_emit(buf, "%lu\n", vio_cmo.name.var);              \
 }                                                                       \
 static BUS_ATTR_RO(cmo_##name##_##var)
 
@@ -1022,7 +1023,7 @@ viobus_cmo_pool_rd_attr(excess, free);
 
 static ssize_t cmo_high_show(const struct bus_type *bt, char *buf)
 {
-       return sprintf(buf, "%lu\n", vio_cmo.high);
+       return sysfs_emit(buf, "%lu\n", vio_cmo.high);
 }
 
 static ssize_t cmo_high_store(const struct bus_type *bt, const char *buf,
@@ -1535,7 +1536,7 @@ machine_device_initcall(pseries, vio_device_init);
 static ssize_t name_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "%s\n", to_vio_dev(dev)->name);
+       return sysfs_emit(buf, "%s\n", to_vio_dev(dev)->name);
 }
 static DEVICE_ATTR_RO(name);
 
@@ -1544,7 +1545,7 @@ static ssize_t devspec_show(struct device *dev,
 {
        struct device_node *of_node = dev->of_node;
 
-       return sprintf(buf, "%pOF\n", of_node);
+       return sysfs_emit(buf, "%pOF\n", of_node);
 }
 static DEVICE_ATTR_RO(devspec);
 
@@ -1556,17 +1557,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
        const char *cp;
 
        dn = dev->of_node;
-       if (!dn) {
-               strcpy(buf, "\n");
-               return strlen(buf);
-       }
+       if (!dn)
+               return sysfs_emit(buf, "\n");
        cp = of_get_property(dn, "compatible", NULL);
-       if (!cp) {
-               strcpy(buf, "\n");
-               return strlen(buf);
-       }
+       if (!cp)
+               return sysfs_emit(buf, "\n");
 
-       return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp);
+       return sysfs_emit(buf, "vio:T%sS%s\n", vio_dev->type, cp);
 }
 static DEVICE_ATTR_RO(modalias);
 
index f9e64f54dc14b486befa59f2bbd9be626a6e3fac..f63b89adf9f314db3a806645a3ea7a92c91cd3fd 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -61,7 +62,7 @@ static ssize_t fsl_timer_wakeup_show(struct device *dev,
        }
        mutex_unlock(&sysfs_lock);
 
-       return sprintf(buf, "%lld\n", interval);
+       return sysfs_emit(buf, "%lld\n", interval);
 }
 
 static ssize_t fsl_timer_wakeup_store(struct device *dev,