Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2733882pxb; Mon, 31 Jan 2022 03:10:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbNMdf49ZipiF6vbpmC/lNDSmRQsrFQ3hMvCwTG+iJdjD80tZZW91UsoGDR6DYnnELBI34 X-Received: by 2002:a17:90b:3ec5:: with SMTP id rm5mr31609400pjb.140.1643627444585; Mon, 31 Jan 2022 03:10:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643627444; cv=none; d=google.com; s=arc-20160816; b=E35tnsodDIvV6mYKhoeUpQsqs/1vQvuEVkDpFQRHtMXrFivBCu7maKurzY4GcVxCOG 2imSkIWgBaIYB24EF7q+WXEIk32aWwtnpM3F3DHTSiHcz9OjbkmyL3smI6zkdR1efWdw r5F9B+qPfPB8qQGiwnTepWj7IFfDRwVmAJ5vHmogKvyUejcuoplAPT0NkagW0JSHCJYv yVMN9fqQBAy3cm8MXT04TudzISZfQ8x4fg+aMxvcRnwgt4EFDM1nWkGV0F4ClyeHbN82 Sf/M8N5WN2fbH9XJws6lvUQNod6tnu24x0F6A0BJ5m6EdN/DDRiUGom4t4M6xi+ygg+g GZOw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=HFyK9YSPqzN8UFNpZeb69roURTWWg8qSsNbo2x59knA=; b=LwBkEqEAYKFU1RKSxMDJM04UjMzkbTsVpnbux8ZcD67o5Zqk+TdOHatExA5beIjOdw +JXOCJNN+IR93th9UfRdMTD+zPjWeYNmpHb9xSfhoL8CZRFDKF99kjdwHJdgGpVqvfmA piZezSN9lM7+5OzugXKHWW+AD5X6CzD9t90vm/rzshhGDIlKfUcTTORVLGBrwGmTVUOu VvkOQkziaexwZS8RCSKGRkOnhuBdmqzhM7Hpqit+lJ1yFrmfmtjfyDcsdfUGS/jQcABD ka50/yHRpdN82RGXHfwV+FXImNXDKPuhcnxEMFk/alUMaxzYMdMxTSLxAWcEbwEv6C1J JDKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XqXACsWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si7708565plo.400.2022.01.31.03.10.32; Mon, 31 Jan 2022 03:10:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XqXACsWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349425AbiA1OqC (ORCPT + 99 others); Fri, 28 Jan 2022 09:46:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47120 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349400AbiA1OqB (ORCPT ); Fri, 28 Jan 2022 09:46:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643381160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HFyK9YSPqzN8UFNpZeb69roURTWWg8qSsNbo2x59knA=; b=XqXACsWfg+QtuDhFZqX2yw2l+3eWHtSuezIjJ1CQZjURYwFBgzeiTRxq3tpsFHhEsr93r3 phvyzEVr43j8uEEAScZeAO/qhy8eP+gmIhnoTrw46LeAey85pNrIiOwLMCiAKQhvQ4RXtO yNs2KQ0ydkYKz6HTCMzOvtUVoyWDnjY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-1-0TLvl7ZXOlOCj-4oqSTr-g-1; Fri, 28 Jan 2022 09:45:55 -0500 X-MC-Unique: 0TLvl7ZXOlOCj-4oqSTr-g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC69C814246; Fri, 28 Jan 2022 14:45:53 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id D923C7B9E3; Fri, 28 Jan 2022 14:45:41 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , stable@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Michal Hocko , Oscar Salvador Subject: [PATCH v1] drivers/base/memory: add memory block to memory group after registration succeeded Date: Fri, 28 Jan 2022 15:45:40 +0100 Message-Id: <20220128144540.153902-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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