The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Rakie Kim <rakie.kim@sk.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Rakie Kim <rakie.kim@sk.com>,
	kernel_team@skhynix.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Gregory Price <gourry@gourry.net>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org, Honggyu Kim <honggyu.kim@sk.com>
Subject: Re: [PATCH next] mm/mempolicy: Fix error code in sysfs_wi_node_add()
Date: Fri,  2 May 2025 16:40:02 +0900	[thread overview]
Message-ID: <20250502074010.153-1-rakie.kim@sk.com> (raw)
In-Reply-To: <aBRv6RmQf7vNZQMJ@stanley.mountain>

On Fri, 2 May 2025 10:10:33 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:
> On Fri, May 02, 2025 at 03:46:21PM +0900, Honggyu Kim wrote:
> > Hi Dan,
> > 
> > On 4/23/2025 5:24 PM, Dan Carpenter wrote:
> > > Return -EEXIST if the node already exists.  Don't return success.
> > > 
> > > Fixes: 1bf270ac1b0a ("mm/mempolicy: support memory hotplug in weighted interleave")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > > ---
> > > Potentially returning success was intentional?  This is from static
> > > analysis and I can't be totally sure.
> > > 
> > >   mm/mempolicy.c | 3 ++-
> > >   1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > > index f43951668c41..0538a994440a 100644
> > > --- a/mm/mempolicy.c
> > > +++ b/mm/mempolicy.c
> > > @@ -3539,7 +3539,7 @@ static const struct kobj_type wi_ktype = {
> > >   static int sysfs_wi_node_add(int nid)
> > >   {
> > > -	int ret = 0;
> > > +	int ret;
> > >   	char *name;
> > >   	struct iw_node_attr *new_attr;
> > > @@ -3569,6 +3569,7 @@ static int sysfs_wi_node_add(int nid)
> > >   	if (wi_group->nattrs[nid]) {
> > >   		mutex_unlock(&wi_group->kobj_lock);
> > >   		pr_info("node%d already exists\n", nid);
> > > +		ret = -EEXIST;
> > 
> > Returning -EEXIST here looks good to me, but could you remove the above pr_info
> > as well?  I mean the following change is needed.
> > 
> > -		pr_info("node%d already exists\n", nid)
> > +		ret = -EEXIST;
> > 
> > We don't need the above pr_info here because we delegate a warning message to
> > its caller wi_node_notifier().
> > 
> > This can close another warning report below.
> > https://lore.kernel.org/all/202505020458.yLHRAaW9-lkp@intel.com
> > 
> > If you apply my suggestion then please add
> > 
> > 	Reviewed-by: Honggyu Kim <honggyu.kim@sk.com>
> > 
> 
> Rakie Kim was pretty confident that returning 0 was intentional.  Btw,
> Smatch considers it intentional if the "ret = 0;" is within 5
> lines of the goto.  Or we could add a comment, which wouldn't silence
> the warning but it would help people reading the code.
> 

Hi Dan,

Thank you for taking the time to review this code and point out the issue.
I believe there may have been some confusion related to the behavior in
previous versions.

In the latest revision, the `wi_node_notifier()` function that calls
`sysfs_wi_node_add()` has been updated to always return `NOTIFY_OK`,
regardless of the return value from `sysfs_wi_node_add()`. This ensures that
no memory hotplug event will be blocked by our notifier logic.

static int wi_node_notifier(struct notifier_block *nb,
                            unsigned long action, void *data)
{
	...
	switch (action) {
	case MEM_ONLINE:
		err = sysfs_wi_node_add(nid);
		if (err)
			pr_err("failed to add sysfs for node%d during hotplug: %d\n",
			       nid, err);
		break;
	...
	return NOTIFY_OK;
}

Given that, it is appropriate for `sysfs_wi_node_add()` to return `-EEXIST`
when the node already exists. Since the error message is already logged by
`wi_node_notifier()`, I agree with Honggyu's suggestion to remove the
redundant `pr_info()` statement as well:

-		pr_info("node%d already exists\n", nid);
+		ret = -EEXIST;

Once again, thank you very much for your review and for helping us improve
the code.

Reviewed-by: Rakie Kim <rakie.kim@sk.com>

Rakie

> regards,
> dan carpenter
> 
> 

      reply	other threads:[~2025-05-02  7:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23  8:24 [PATCH next] mm/mempolicy: Fix error code in sysfs_wi_node_add() Dan Carpenter
2025-04-23 15:27 ` Joshua Hahn
2025-04-23 16:33 ` Gregory Price
2025-04-24  5:49   ` Rakie Kim
2025-05-02  6:46 ` Honggyu Kim
2025-05-02  7:10   ` Dan Carpenter
2025-05-02  7:40     ` Rakie Kim [this message]

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=20250502074010.153-1-rakie.kim@sk.com \
    --to=rakie.kim@sk.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@linaro.org \
    --cc=dan.j.williams@intel.com \
    --cc=gourry@gourry.net \
    --cc=honggyu.kim@sk.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kernel_team@skhynix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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