Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3835387pxb; Fri, 4 Feb 2022 18:34:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/+FrllKSnCvy5/G3ytXP9t5UEp6M++AW56la40iI5tc5Q7+kFUXMzJabk27iBq62JC1fR X-Received: by 2002:a63:78e:: with SMTP id 136mr1553998pgh.326.1644028483097; Fri, 04 Feb 2022 18:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644028483; cv=none; d=google.com; s=arc-20160816; b=pUzOPGKSQ/RslrHS5AMJpT6mHF8DjPLj2l3audJvDEIYc9jGU+MDBaN3w4slF7nGy/ hs9MqZaoA7vTu2/13UTZ+uxXpLlLvK7FH4YXHHuHjCCNi3h1JJUx42ThRJPInm072rTE xx8rJ+1cbJFBeG6AOETjrGLO2GkskPJyZUPqRptF6TmOA6yTKh/pE4SQ7OB1xM1Hyb0R JSuO0fcXyjxbi+QoROHy7fMus7VTcMZA0v0T5E3SpeDifQgETGY/R6/jvFhgbzx2WhvV ex0f3wEwN2MELWusDMpX7Cczu9YwQIg5zlRQuGo1wqhxZB5JTD9Fzmv3Y3oNVoWjuRwq j9Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=waTSXVBuauKX5YnIa/Qo7/CVnbpIOue+UFyeuExs0gY=; b=ATfj5xJODU+SvRL/IOj3/GyO5Nzf/DlnXhJacGTyzri4rGZVTwMl71O3jBFH7ocJ0U 63qJBYbz8sewupea78/253OMrKDhdhE2MMmISBQ4uQaRTvZ7DLlsxScIdTiuTzPecIZM LpjqKJqIXCtrRAv926hOqQ8uG9fBOGmjccTHlvpdYgyui7U0WhMC9YE5d26kvDya/J48 b3uayumSu7NPaOPmuGyRwS+ir7+PESY28KFJcPKfFaNnpRQxX0VzpuB9AzNZEorGU6+c 7smkYoKQ1flZQCO1ek3swAr0msXHsW8Ue9BS4wXjalTpuKhCKmSzsbseF69kFlQYLCkE X1/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hNJhJH1i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15si4053143pfc.227.2022.02.04.18.34.29; Fri, 04 Feb 2022 18:34:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hNJhJH1i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237815AbiBAMLP (ORCPT + 99 others); Tue, 1 Feb 2022 07:11:15 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:53580 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237805AbiBAMLO (ORCPT ); Tue, 1 Feb 2022 07:11:14 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DB5481F383; Tue, 1 Feb 2022 12:11:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1643717473; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=waTSXVBuauKX5YnIa/Qo7/CVnbpIOue+UFyeuExs0gY=; b=hNJhJH1i2ZicjCdh5dcouWfJ4t3wurHaTB8N9eASUJgI+bv1w9u0NDFacQILWhK69y7sE+ R1CydIbT1KdbAlXKRW4gwb1yZa7pdwYZUBj8bMNIs+aGgce+a4fvnGmEYnb4+LL3ccXnW5 od8ZYIZ/FhWRGt97afnwYV1pLqFTYRw= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C426EA3B85; Tue, 1 Feb 2022 12:11:13 +0000 (UTC) Date: Tue, 1 Feb 2022 13:11:13 +0100 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Oscar Salvador Subject: Re: [PATCH v1] drivers/base/memory: add memory block to memory group after registration succeeded Message-ID: References: <20220128144540.153902-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220128144540.153902-1-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 28-01-22 15:45:40, David Hildenbrand wrote: > If register_memory() fails, we freed the memory block but already added > the memory block to the group list, not good. Let's defer adding the > block to the memory group to after registering the memory block device. > > We do handle it properly during unregister_memory(), but that's not > called when the registration fails. > > Fixes: 028fc57a1c36 ("drivers/base/memory: introduce "memory groups" to logically group memory blocks") > Cc: stable@vger.kernel.org # v5.15+ > Cc: Greg Kroah-Hartman > Cc: "Rafael J. Wysocki" > Cc: Andrew Morton > Cc: Michal Hocko > Cc: Oscar Salvador > Signed-off-by: David Hildenbrand Acked-by: Michal Hocko Thanks! > --- > drivers/base/memory.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 365cd4a7f239..60c38f9cf1a7 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -663,14 +663,16 @@ static int init_memory_block(unsigned long block_id, unsigned long state, > mem->nr_vmemmap_pages = nr_vmemmap_pages; > INIT_LIST_HEAD(&mem->group_next); > > + ret = register_memory(mem); > + if (ret) > + return ret; > + > if (group) { > mem->group = group; > list_add(&mem->group_next, &group->memory_blocks); > } > > - ret = register_memory(mem); > - > - return ret; > + return 0; > } > > static int add_memory_block(unsigned long base_section_nr) > -- > 2.34.1 -- Michal Hocko SUSE Labs