Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <ljs@kernel.org>
To: ranxiaokai627@163.com
Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com,
	 hughd@google.com, leitao@debian.org,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org,
	ran.xiaokai@zte.com.cn
Subject: Re: [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string()
Date: Mon, 18 May 2026 12:16:07 +0100	[thread overview]
Message-ID: <agr0aV3o-5Iqwqn5@lucifer> (raw)
In-Reply-To: <20260518020208.55676-1-ranxiaokai627@163.com>

On Mon, May 18, 2026 at 02:02:08AM +0000, ranxiaokai627@163.com wrote:
> >On Wed, May 13, 2026 at 09:45:07AM +0000, ranxiaokai627@163.com wrote:
> >> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> >>
> >> Inspired by commit 82d9ff648c6c ("mm: huge_memory: refactor
> >> anon_enabled_store() with set_anon_enabled_mode()"), refactor
> >> thpsize_shmem_enabled_store() using sysfs_match_string().
> >> This eliminates the duplicated spin_lock/unlock(), set/clear_bit(),
> >> calls across all branches, reducing code duplication.
> >
> >>  static ssize_t thpsize_shmem_enabled_show(struct kobject *kobj,
> >>  					  struct kobj_attribute *attr, char *buf)
> >>  {
> >> @@ -5551,57 +5574,42 @@ static ssize_t thpsize_shmem_enabled_store(struct kobject *kobj,
> >>  					   const char *buf, size_t count)
> >>  {
> >>  	int order = to_thpsize(kobj)->order;
> >> +	int mode, m;
> >
> >I hate single letter variable names (yes I see set_anon_enabled_mode() has it, I
> >should have reviewed against that, oops :).
> >
> >Please give it its type of enum huge_shmem_enalbed_mode.
>
> Hi, Lorenzo,
>
> int main()
> {
>     enum huge_shmem_enabled_mode mode = 0;
>     const char* type_name = _Generic((mode),
>         int: "signed int",
>         unsigned int: "unsigned int",
>         default: "other"
>     );
>     printf("enum huge_shmem_enabled_mode underlying type is: %s\n", type_name);
>     return 0;
> }
>  ./a.out
> enum huge_shmem_enabled_mode underlying type is: unsigned int
>
> This will cause the following check to always evaluate to false and
> does not validate input parameters like echo "xxx" > .../hugepages-xxkB/shmem_enable
> if (mode < 0)
> 	return mode;
>
> So i think we should keep mode as integer.
>
> >> +	mode = sysfs_match_string(huge_shmem_enabled_mode_strings, buf);
> >> +	if (mode < 0)
> >> +		return -EINVAL;

OK fair enough. The C type system strikes again :)

>

Cheers, Lorenzo


  reply	other threads:[~2026-05-18 11:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  9:45 [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string() ranxiaokai627
2026-05-13  9:45 ` [PATCH v2 2/2] mm: huge_memory: refactor thpsize_shmem_enabled_show() with helper arrays ranxiaokai627
2026-05-14  2:41   ` Baolin Wang
2026-05-14  9:08   ` Breno Leitao
2026-05-14 12:22   ` Lorenzo Stoakes
2026-05-15  6:04     ` ranxiaokai627
2026-05-15 11:36       ` Lorenzo Stoakes
2026-05-14  2:36 ` [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string() Baolin Wang
2026-05-14 10:10   ` ranxiaokai627
2026-05-14 12:05   ` Lorenzo Stoakes
2026-05-14  8:33 ` Breno Leitao
2026-05-14  9:26   ` ranxiaokai627
2026-05-14 12:48 ` Lorenzo Stoakes
2026-05-15  6:21   ` ranxiaokai627
2026-05-15  7:23   ` ranxiaokai627
2026-05-15 11:34     ` Lorenzo Stoakes
2026-05-18  2:02   ` ranxiaokai627
2026-05-18 11:16     ` Lorenzo Stoakes [this message]
     [not found] <20260518110816.79be9a7c71777c1876b0019d@linux-foundation.org>
2026-05-20 10:29 ` ranxiaokai627
2026-05-22 13:04   ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=agr0aV3o-5Iqwqn5@lucifer \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hughd@google.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ran.xiaokai@zte.com.cn \
    --cc=ranxiaokai627@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox