From patchwork Fri Jan 28 14:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12728633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C47BCC433FE for ; Fri, 28 Jan 2022 14:46:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C4716B00C4; Fri, 28 Jan 2022 09:46:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 474766B00C5; Fri, 28 Jan 2022 09:46:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33B966B00C6; Fri, 28 Jan 2022 09:46:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay037.a.hostedemail.com [64.99.140.37]) by kanga.kvack.org (Postfix) with ESMTP id 233556B00C4 for ; Fri, 28 Jan 2022 09:46:00 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id C713280352 for ; Fri, 28 Jan 2022 14:45:59 +0000 (UTC) X-FDA: 79079970438.01.B400FDA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 3B407100027 for ; Fri, 28 Jan 2022 14:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643381158; 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=d/V8v1bvClSoMbBpuZY4h2QTcquUZey/6mC5tcwWz8vA3TOz0tZdIt20uE7nfepc7LCuV5 oT6iZZ3bx5HP5+4BqvjdXn+FY6bhMNCSrfnogvzs5LEGizKQ5gqfP0RxxksYjk3BJ97IZD FwbVHuMZzxQ/cK2ZyB8a/pJiVRcPLCs= 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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3B407100027 X-Stat-Signature: 4qzosxwbenmn4rtb9hh73pyrc9jm5trk Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="d/V8v1bv"; spf=none (imf14.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1643381159-676468 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Oscar Salvador Acked-by: Michal Hocko --- 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)