Re: [PATCH v3 3/4] hugetlb: Fix return value of __setup handlers

From: Muchun Song
Date: Wed Apr 13 2022 - 05:01:58 EST


On Wed, Apr 13, 2022 at 04:45:30PM +0800, Kefeng Wang wrote:
>
> On 2022/4/13 16:21, Muchun Song wrote:
> > On Wed, Apr 13, 2022 at 04:16:11PM +0800, liupeng (DM) wrote:
> > > On 2022/4/13 15:55, Muchun Song wrote:
> > > > On Wed, Apr 13, 2022 at 03:29:14AM +0000, Peng Liu wrote:
> > > > > When __setup() return '0', using invalid option values causes the
> > > > > entire kernel boot option string to be reported as Unknown. Hugetlb
> > > > > calls __setup() and will return '0' when set invalid parameter
> > > > > string.
> > > > >
> > > > > The following phenomenon is observed:
> > > > > cmdline:
> > > > > hugepagesz=1Y hugepages=1
> > > > > dmesg:
> > > > > HugeTLB: unsupported hugepagesz=1Y
> > > > > HugeTLB: hugepages=1 does not follow a valid hugepagesz, ignoring
> > > > > Unknown kernel command line parameters "hugepagesz=1Y hugepages=1"
> > > > >
> > > > > Since hugetlb will print warning/error information before return for
> > > > > invalid parameter string, just use return '1' to avoid print again.
> > > > >
> > > > Can't return -EINVAL? It is weird to return 1 on failure.
> > > >
> > > > Thanks.
> > > >
> > > > .
> > > Not against "return -EINVAL", but consistent with:
> > > 1d02b444b8d1 ("tracing: Fix return value of __setup handlers")
> > I think it is better not return 1. I don't think it's a good habit we
> > should follow.
> /*
>  * NOTE: __setup functions return values:
>  * @fn returns 1 (or non-zero) if the option argument is "handled"
>  * and returns 0 if the option argument is "not handled".
>  */
> #define __setup(str, fn)               \
>        __setup_param(str, fn, fn, 0)
>
>
> 1 or -EINVAL should ok, and  most __setup return 1 for know ;)
>

Got it. Thanks. Seems like a lot of users make mistakes in
this regard [1].

Reviewed-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>

[1] https://lore.kernel.org/all/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@xxxxxxxxxxxx/