From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id 4B6F26B038D for ; Thu, 16 Mar 2017 02:12:26 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id q126so74696250pga.0 for ; Wed, 15 Mar 2017 23:12:26 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id i187si3026875pfc.171.2017.03.15.23.12.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 23:12:25 -0700 (PDT) Subject: [PATCH v4 05/13] mm: cleanup sparse_init_one_section() return value From: Dan Williams Date: Wed, 15 Mar 2017 23:07:14 -0700 Message-ID: <148964443460.19438.2319455591268290209.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <148964440651.19438.2288075389153762985.stgit@dwillia2-desk3.amr.corp.intel.com> References: <148964440651.19438.2288075389153762985.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: akpm@linux-foundation.org Cc: Michal Hocko , linux-nvdimm@lists.01.org, Logan Gunthorpe , linux-kernel@vger.kernel.org, Stephen Bates , linux-mm@kvack.org, Johannes Weiner , Mel Gorman , Vlastimil Babka We mark and check that the section is present under a spin_lock() in sparse_add_one_section(), so the lock ensures it will not change between those 2 events. Also, we do not check the -EBUSY return value in sparse_init(). Just make sparse_init_one_section() return void and clean up the error handling. Cc: Michal Hocko Cc: Vlastimil Babka Cc: Johannes Weiner Cc: Logan Gunthorpe Cc: Mel Gorman Cc: Andrew Morton Cc: Stephen Bates Signed-off-by: Dan Williams --- mm/sparse.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index d0d4c005dc60..886f666ebe35 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -231,19 +231,14 @@ struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pn return ((struct page *)coded_mem_map) + section_nr_to_pfn(pnum); } -static int __meminit sparse_init_one_section(struct mem_section *ms, +static void __meminit sparse_init_one_section(struct mem_section *ms, unsigned long pnum, struct page *mem_map, struct mem_section_usage *usage) { - if (!present_section(ms)) - return -EINVAL; - ms->section_mem_map &= ~SECTION_MAP_MASK; ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum) | SECTION_HAS_MEM_MAP; ms->usage = usage; - - return 1; } unsigned long usemap_size(void) @@ -690,11 +685,6 @@ static void free_map_bootmem(struct page *memmap) #endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_SPARSEMEM_VMEMMAP */ -/* - * returns the number of sections whose mem_maps were properly - * set. If this is <=0, then that means that the passed-in - * map was not consumed and must be freed. - */ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn) { unsigned long section_nr = pfn_to_section_nr(start_pfn); @@ -725,7 +715,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn) ms = __pfn_to_section(start_pfn); if (ms->section_mem_map & SECTION_MARKED_PRESENT) { - ret = -EEXIST; + ret = -EBUSY; goto out; } @@ -733,15 +723,16 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn) ms->section_mem_map |= SECTION_MARKED_PRESENT; - ret = sparse_init_one_section(ms, section_nr, memmap, usage); + sparse_init_one_section(ms, section_nr, memmap, usage); out: pgdat_resize_unlock(pgdat, &flags); - if (ret <= 0) { + if (ret < 0 && ret != -EEXIST) { kfree(usage); __kfree_section_memmap(memmap); + return ret; } - return ret; + return 0; } #ifdef CONFIG_MEMORY_HOTREMOVE -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org