Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp666496pxb; Tue, 5 Apr 2022 17:59:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBbDT01dUFr5bJicI5nNw8IbFnXSUG8z08x4aGkz2YMyjbWceBSbcFqvRl9b1wZx1gIJJK X-Received: by 2002:a17:907:7ea8:b0:6df:d4a4:8156 with SMTP id qb40-20020a1709077ea800b006dfd4a48156mr6113529ejc.226.1649206669522; Tue, 05 Apr 2022 17:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206669; cv=none; d=google.com; s=arc-20160816; b=tFNcST5OFYA2B/hkiF0N7I6mrvMqm1TBg5Pgs7dWUmGMhwsJXvoV+xfOiwoV0sZjGi e5qAqcCwaz9QTEMQqdITv9ymBYAcZv+CZUxUNDkWLSwDP075zXq/rThZJEVf61tfPFL4 9dKxbhI9hxjXDAhbZxdZUEvLBTqHYaCIFuiM5VU9W7iiDBWdOcO3JD+fqaFyLzsNenUt K+dwlv2pR1gUIojgAPMXU8+YkA+qYrXSjLnGqTFhYQfq6/Ap4EicpfUCTRAQ8wgzmy+5 L94QFkNd/IO4nq6ZbVRHCBarTe2NBHKtB/bU5JTGmv8BANLx33pz/NyVmP7v08sL8145 ixrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PMoCF25ch1TKOoU4/FMKKsPPqlJ5VVVFbBcMIlByBmc=; b=zzyd0hhD9fC44LKKfyRJ1CEB54us5UqB/2fDDoJW1TCxbQkt7B4ofYles10mHG81yH N3rHPn/5t/3Tlr0chq71lCcKt4EE9LdzFVLUc9pCef+emSP3WjFus8wx9GDB/R1uPjOt hlAXfP+IEqNtSZgKqKU3EeJVhl3urdfvPea/f1qZm7+Rk39kfEOuf7sToxbugCpahyJW WhzeceusE2+bLaIQ1+zTxLdVNN4+3//n9RfrvcDqlrz7WpOyMgd4/YBqfcOTJlnvZbQY oRDNXQrz9Kje7nPH95Aw62tBA9lcdK7dzq9DsYBgqx7mZ3xfwlfnx+JUqtpYcmrGKlx0 eAiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="LH/KOVgN"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r4-20020a170906c28400b006e0598b7d80si9520082ejz.821.2022.04.05.17.57.22; Tue, 05 Apr 2022 17:57:49 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="LH/KOVgN"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357966AbiDEPMc (ORCPT + 99 others); Tue, 5 Apr 2022 11:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346147AbiDEJob (ORCPT ); Tue, 5 Apr 2022 05:44:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF876C748E; Tue, 5 Apr 2022 02:30:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4057861675; Tue, 5 Apr 2022 09:30:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CE3BC385A2; Tue, 5 Apr 2022 09:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151009; bh=6rWeWZOC3ktBYreoC88HJB7ZluW+5NlAEBSobv0dqyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LH/KOVgNA9Zv1eLQ8pxR+esJImevx5PiRSvp4HIB5U4XrK2+Tzc3fyBFfJWSUwuS6 uLGHznhzfOw4WhT+8TtEIkPQwJA2gm8rK0Pf/JD14JwJs73WMCoBBQRrnupPmYwbW+ C+UTmy0p0rCKqffdw4/BByqnONiqZqYGU6QCpAfA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Oscar Salvador , Michal Hocko , "Rafael J. Wysocki" , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.15 262/913] drivers/base/memory: add memory block to memory group after registration succeeded Date: Tue, 5 Apr 2022 09:22:04 +0200 Message-Id: <20220405070347.710149757@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Hildenbrand [ Upstream commit 7ea0d2d79da09d1f7d71c96a9c9bc1b5229360b5 ] 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. Link: https://lkml.kernel.org/r/20220128144540.153902-1-david@redhat.com Fixes: 028fc57a1c36 ("drivers/base/memory: introduce "memory groups" to logically group memory blocks") Signed-off-by: David Hildenbrand Reviewed-by: Oscar Salvador Acked-by: Michal Hocko Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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