From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BA1417D6 for ; Mon, 18 May 2026 02:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779069784; cv=none; b=YZl3CpJa1VdFLxT2oLggxn5WolvjjsrA3QvxgnJ9DetcKTvC1R+TFSojEd6nA5BQnbg7GvQtNkOiO+5HWE2MAsMsxzejUxQBXLE2h4n3zH6DoYdcRzx6cI0Z6flnvvNLns8OvHswWCn4yvIDGabQ5oiRccbZRfhDXfVQSN26HXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779069784; c=relaxed/simple; bh=9EJvLunwbJymvSZqn6pRAuesjPi7K7qBCusupGj7S+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OCZf9yBXTKl222lNoFcbDI3Mv6L12rWuYuUzXxTi6n+GVnWiVIzaodFSZtBX21fxR4hgTSHeboDIBAzT7WpI8D/UEE+/uOanVgUwvuC0hJJ7I+bcOdkrUiFb1Qsba5k680S1I+oAfjHu4RMPmBtcIKyStxUKxtWj7G8PJwO8x8Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=V2jUlbDw; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="V2jUlbDw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=kS 82Y82Smkz806tcG5eajrNEYIT+cNNWW5kXF3cQzFY=; b=V2jUlbDwF4V7pumD24 siiYEpmjOvuRHg1j2KdGVCb+c+gm9IVdgQTDKX1UULmh/XJW2fUYu/0hMzZliiF8 3BvR/Xwyji2FP7lNbVV/Z4XWC7mhozq3ZEXEVe9XWb2dH0zEDOK6pqeEtu4LRgfr VgY4se1xxoGzf/l4bYXkp3iHY= Received: from ubuntu24-z.. (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wDn1jUgcwpqX1zSBw--.33526S2; Mon, 18 May 2026 10:02:10 +0800 (CST) From: ranxiaokai627@163.com To: ljs@kernel.org 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, ranxiaokai627@163.com Subject: Re: [PATCH v2 1/2] mm: huge_memory: refactor thpsize_shmem_enabled_store() with sysfs_match_string() Date: Mon, 18 May 2026 02:02:08 +0000 Message-ID: <20260518020208.55676-1-ranxiaokai627@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDn1jUgcwpqX1zSBw--.33526S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7AFWfuFW5WFy8Jr43Jw1kZrb_yoW8Ww15pr Z5A34IyryUJ34kKayIvFW8Ja45tr4xXr15t3s8Wa4Sy3Z5Wr1vgr1vyryrZa4xur95Wr42 qF4xWF98Z34qqrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUGFAQUUUUU= X-CM-SenderInfo: xudq5x5drntxqwsxqiywtou0bp/xtbC7QICTmoKcyJkOgAA3M >On Wed, May 13, 2026 at 09:45:07AM +0000, ranxiaokai627@163.com wrote: >> From: Ran Xiaokai >> >> 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;