The patch titled Subject: mm: huge_memory: convert remaining use of sprintf to sysfs_emit and neatening has been added to the -mm tree. Its filename is mm-huge_memory-convert-remaining-use-of-sprintf-to-sysfs_emit-and-neatening.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-huge_memory-convert-remaining-use-of-sprintf-to-sysfs_emit-and-neatening.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-huge_memory-convert-remaining-use-of-sprintf-to-sysfs_emit-and-neatening.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Joe Perches <joe@xxxxxxxxxxx> Subject: mm: huge_memory: convert remaining use of sprintf to sysfs_emit and neatening Convert the only use of sprintf with struct kobject * that the cocci script could not convert. Miscellanea: o Neaten the uses of a constant string with sysfs_emit to use a const char * to reduce overall object size Link: https://lkml.kernel.org/r/7df6be66bbd68e1a0bca9d35aca1341dbf94d2a7.1605376435.git.joe@xxxxxxxxxxx Signed-off-by: Joe Perches <joe@xxxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/huge_memory.c | 52 ++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 21 deletions(-) --- a/mm/huge_memory.c~mm-huge_memory-convert-remaining-use-of-sprintf-to-sysfs_emit-and-neatening +++ a/mm/huge_memory.c @@ -163,12 +163,17 @@ static struct shrinker huge_zero_page_sh static ssize_t enabled_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { + const char *output; + if (test_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, "[always] madvise never\n"); - else if (test_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, "always [madvise] never\n"); + output = "[always] madvise never"; + else if (test_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + &transparent_hugepage_flags)) + output = "always [madvise] never"; else - return sysfs_emit(buf, "always madvise [never]\n"); + output = "always madvise [never]"; + + return sysfs_emit(buf, "%s\n", output); } static ssize_t enabled_store(struct kobject *kobj, @@ -200,11 +205,11 @@ static struct kobj_attribute enabled_att __ATTR(enabled, 0644, enabled_show, enabled_store); ssize_t single_hugepage_flag_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf, - enum transparent_hugepage_flag flag) + struct kobj_attribute *attr, char *buf, + enum transparent_hugepage_flag flag) { - return sprintf(buf, "%d\n", - !!test_bit(flag, &transparent_hugepage_flags)); + return sysfs_emit(buf, "%d\n", + !!test_bit(flag, &transparent_hugepage_flags)); } ssize_t single_hugepage_flag_store(struct kobject *kobj, @@ -232,19 +237,24 @@ ssize_t single_hugepage_flag_store(struc static ssize_t defrag_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, - "[always] defer defer+madvise madvise never\n"); - if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, - "always [defer] defer+madvise madvise never\n"); - if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, - "always defer [defer+madvise] madvise never\n"); - if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags)) - return sysfs_emit(buf, - "always defer defer+madvise [madvise] never\n"); - return sysfs_emit(buf, "always defer defer+madvise madvise [never]\n"); + const char *output; + + if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, + &transparent_hugepage_flags)) + output = "[always] defer defer+madvise madvise never"; + else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, + &transparent_hugepage_flags)) + output = "always [defer] defer+madvise madvise never"; + else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, + &transparent_hugepage_flags)) + output = "always defer [defer+madvise] madvise never"; + else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, + &transparent_hugepage_flags)) + output = "always defer defer+madvise [madvise] never"; + else + output = "always defer defer+madvise madvise [never]"; + + return sysfs_emit(buf, "%s\n", output); } static ssize_t defrag_store(struct kobject *kobj, _ Patches currently in -mm which might be from joe@xxxxxxxxxxx are mm-zswap-make-struct-kernel_param_ops-definitions-const.patch mm-use-sysfs_emit-for-struct-kobject-uses.patch mm-huge_memory-convert-remaining-use-of-sprintf-to-sysfs_emit-and-neatening.patch mm-backing-dev-use-sysfs_emit-in-macro-defining-functions.patch mm-shmem-convert-shmem_enabled_show-to-use-sysfs_emit_at.patch mm-slub-convert-sysfs-sprintf-family-to-sysfs_emit-sysfs_emit_at.patch checkpatch-prefer-static-const-declarations.patch checkpatch-allow-fix-removal-of-unnecessary-break-statements.patch checkpatch-update-__attribute__sectionname-quote-removal.patch checkpatch-update-__attribute__sectionname-quote-removal-v2.patch checkpatch-add-__alias-and-__weak-to-suggested-__attribute__-conversions.patch treewide-remove-stringification-from-__alias-macro-definition.patch