From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 771493ED122 for ; Mon, 18 May 2026 11:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779102973; cv=none; b=PtMLNey1ur+jg4I96ZE3K9/a0PqRiQkN/WxQfWrm7kR/IBtkP3PpYVVCrXj1usObsIHg+rk0vV7tIsvYVN0bop3UaOZpD3Jqwcs7lr6Tjc1x//yxQKlwFMGBzdTm2LJ1v/Gue0oReRGc7nsYcNG/gnZwJbySpWjXL2LC64cEir8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779102973; c=relaxed/simple; bh=Rsq11OBDmWjRx182/cbkiwGJKi6eYGncgB5TgjY/gwg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fl0L/wK0U4kUDJIoZMh30Y1MrK/kb91RKf07gFkTIHtASoNMw3GQvn9dhg6k3+3ASSyDRoDqBLX1XP7TgTsJ8qFrqEpkSEq1xsIOhSQFBbR5i27kDgtOkdS8Meo82ELtg3rKSMgdEHLynj86VNyd0ZlsS0+jtGvvQzkw/8q/Sj0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lE1hz4+7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lE1hz4+7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5A48C2BCB7; Mon, 18 May 2026 11:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779102972; bh=Rsq11OBDmWjRx182/cbkiwGJKi6eYGncgB5TgjY/gwg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lE1hz4+7oqBojincmB2fStMEcKBUpuj8ENsXqcz8xlDIc7vaEo1mWYs/ki95PUYxh KIrP9pTthgboqGbWRubTDV6vmiUPTX0GgMXgjn+DJc19KsGeV4HFtWjiFVb+g3F6Km q3T7X5Wudff42EaiaT7+039pZeVYYZ2x2XMAcW8vG1CMWhBpsr4ixXImu9Iev+ZfTt BGifyuogualEE0A3ev/fxY1pNMqXCZhQrcV1edPKq2dYT00l5599EdAWUdcbjW4wct lLtXAuwYlBBKuxrdoVLe/XuzGBpSlpIp5VA1m/3HSF/TYV6PvJfEiK1h8tVCXj1Vc1 QqC3/iN37gDLw== Date: Mon, 18 May 2026 12:16:07 +0100 From: Lorenzo Stoakes 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() Message-ID: References: <20260518020208.55676-1-ranxiaokai627@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > >> > >> 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