Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp651584pxb; Tue, 5 Apr 2022 17:21:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyl3PvzaTwPGlqv2WOWjo4SvubJwaY30J3YSRAuIk0OMRwQaAaSFK5M+YTB5tGYONXx3Xnp X-Received: by 2002:a17:907:9622:b0:6e0:b38b:df18 with SMTP id gb34-20020a170907962200b006e0b38bdf18mr5830125ejc.182.1649204503303; Tue, 05 Apr 2022 17:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204503; cv=none; d=google.com; s=arc-20160816; b=Qia2xxp4tugQdy2ph0bBSi2PEtnkTzQOklp5407WzQ5D7xmPjqJqk7HS45UBLVCFtG i2Q3WGezzi7oBR1nZx2JgxcHl2yKUlwSDqpSjAg2+s0mrdv53bbAMevgtJAsRQH65egB Ww4BUcC2BQFbsppuQAOud5x8yUi6fJXe2B6uunCHDoqPPqFUEL718xcGAeL8tvGPV85u ie263/4XmaloYfWeyWm6KRO5vpQu27GOm66fUCcGLhpDH5fr/fuxjHHXgN8Hr2wOFGbB U3DFVKmVfjB2tNUozxTKpNrkihADw1zq0x/o31labu+3a+awy0XFnIQ978PLXzqzZlmx ydng== 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=fRMXq9D+dGEA4ViPxQOdxJRSeShpDcfKDblrH72fb7xOBg1MEEhVv1Xdk4UhaBxhU3 tNnOuwp8PG9WG0jQuvUAg/tnZ9EmJMsqwXGslAHKxXojYOeNf1vtPGNS6uV3AgzhDjfT rPrkz1kdgci0U7jtFRmsBtowylBGZ6K3LF8efY8RHxettC0DFCZbsq5p88yYq55I0z5t q8G9DVVhGGORfK/yjz+n/UQxmsfXlcRt1nakNQh3pdS0YwA0XwOaFA6JzGx6OrY1yJib NjAmxSJ1W41SosOBGnGiQW+ciacEvK9bD1JT9y3abNt7BDNmzj02asAYmrI09+Pp7F2G gwTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1G3KapPe; 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 dd17-20020a170906c83100b006df76385c0fsi9678403ejb.175.2022.04.05.17.21.11; Tue, 05 Apr 2022 17:21:43 -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=1G3KapPe; 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 S1380369AbiDEMND (ORCPT + 99 others); Tue, 5 Apr 2022 08:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244756AbiDEIwh (ORCPT ); Tue, 5 Apr 2022 04:52:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E030DFB3; Tue, 5 Apr 2022 01:43:31 -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 23C60609D0; Tue, 5 Apr 2022 08:43:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B61DC385A0; Tue, 5 Apr 2022 08:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148210; bh=6rWeWZOC3ktBYreoC88HJB7ZluW+5NlAEBSobv0dqyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1G3KapPe3gNRLLPToJaTprNcP02D0flenlCGX3yM771/HxzjzxlrtrH1ZwirBqePi OLDUQj++P2REEEXRv8A+y9fSdBjDItJq+YVXR1AFevRx72DyD0MzzBo9fclb/m3DgA rSAJ7UPOp2IcoUdqYSIrocGzYV3I2xBhGcT7Bn7o= 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.16 0275/1017] drivers/base/memory: add memory block to memory group after registration succeeded Date: Tue, 5 Apr 2022 09:19:48 +0200 Message-Id: <20220405070402.429332890@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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