Re: [PATCH] proc: Use str_yes_no() helper in proc_pid_ksm_stat()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12. Feb 2025, at 13:04, Al Viro wrote:
> On Wed, Feb 12, 2025 at 12:59:52PM +0100, Thorsten Blum wrote:
>> Remove hard-coded strings by using the str_yes_no() helper function.
> 
>> seq_printf(m, "ksm_merge_any: %s\n",
>> - test_bit(MMF_VM_MERGE_ANY, &mm->flags) ? "yes" : "no");
>> + str_yes_no(test_bit(MMF_VM_MERGE_ANY, &mm->flags)));
>> ret = mmap_read_lock_killable(mm);
>> if (ret) {
>> mmput(mm);
>> return ret;
>> }
>> seq_printf(m, "ksm_mergeable: %s\n",
>> - ksm_process_mergeable(mm) ? "yes" : "no");
>> + str_yes_no(ksm_process_mergeable(mm)));
> 
> Is that any more readable?  If anything, that might be better off with something
> like a printf modifier...

The helpers have other benefits (from include/linux/string_choices.h):

/*
 * Here provide a series of helpers in the str_$TRUE_$FALSE format (you can
 * also expand some helpers as needed), where $TRUE and $FALSE are their
 * corresponding literal strings. These helpers can be used in the printing
 * and also in other places where constant strings are required. Using these
 * helpers offers the following benefits:
 *  1) Reducing the hardcoding of strings, which makes the code more elegant
 *     through these simple literal-meaning helpers.
 *  2) Unifying the output, which prevents the same string from being printed
 *     in various forms, such as enable/disable, enabled/disabled, en/dis.
 *  3) Deduping by the linker, which results in a smaller binary file.
 */

Thanks,
Thorsten




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux