From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 6CF2B6B0003 for ; Fri, 6 Jul 2018 17:23:31 -0400 (EDT) Received: by mail-wm0-f72.google.com with SMTP id w21-v6so8136268wmc.4 for ; Fri, 06 Jul 2018 14:23:31 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t7-v6sor2210766wrp.50.2018.07.06.14.23.29 for (Google Transport Security); Fri, 06 Jul 2018 14:23:29 -0700 (PDT) Date: Fri, 6 Jul 2018 23:23:27 +0200 From: Oscar Salvador Subject: Re: [PATCH] mm/sparse.c: fix error path in sparse_add_one_section Message-ID: <20180706212327.GA10824@techadventures.net> References: <20180706190658.6873-1-ross.zwisler@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180706190658.6873-1-ross.zwisler@linux.intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: Ross Zwisler Cc: pasha.tatashin@oracle.com, linux-nvdimm@lists.01.org, bhe@redhat.com, Dave Hansen , LKML , Linux MM , Michal Hocko , Vlastimil Babka , Andrew Morton , "Kirill A. Shutemov" , osalvador@suse.de On Fri, Jul 06, 2018 at 01:06:58PM -0600, Ross Zwisler wrote: > The following commit in -next: > > commit 054620849110 ("mm/sparse.c: make sparse_init_one_section void and > remove check") > > changed how the error handling in sparse_add_one_section() works. > > Previously sparse_index_init() could return -EEXIST, and the function would > continue on happily. 'ret' would get unconditionally overwritten by the > result from sparse_init_one_section() and the error code after the 'out:' > label wouldn't be triggered. My bad, I missed that. > diff --git a/mm/sparse.c b/mm/sparse.c > index 9574113fc745..d254bd2d3289 100644 > --- a/mm/sparse.c > +++ b/mm/sparse.c > @@ -753,8 +753,12 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, > * plus, it does a kmalloc > */ > ret = sparse_index_init(section_nr, pgdat->node_id); > - if (ret < 0 && ret != -EEXIST) > - return ret; > + if (ret < 0) { > + if (ret == -EEXIST) > + ret = 0; > + else > + return ret; > + } sparse_index_init() can return: -ENOMEM, -EEXIST or 0. So what about this?: diff --git a/mm/sparse.c b/mm/sparse.c index f55e79fda03e..eb188eb6b82d 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -770,6 +770,7 @@ int __meminit sparse_add_one_section(struct pglist_data *pgdat, ret = sparse_index_init(section_nr, pgdat->node_id); if (ret < 0 && ret != -EEXIST) return ret; + ret = 0; Does this look more clean? -- Oscar Salvador SUSE L3