From nobody Sun May 24 18:41:13 2026 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6353284881 for ; Fri, 22 May 2026 13:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455735; cv=none; b=d+QckTiMg+7MgrehnLh9hLsDR3vqB2BvyDkWAZUUwl9QYZkN1v067S4Asn2blVrWHSvkGTUdd7im0IOxvTUn179Y+OlIQVe829wDklfHXof5MywelXrmfrmB7+XpOtONkSglOXl9XWH/OMT1KH2Am5S8aZ/59NCFCvA0Jrq5tGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455735; c=relaxed/simple; bh=nLzdQqHgnr4ejcdaN/B4IQRfV7ysyJlNnwwqiEsW3XQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=usHgbzQnBE4rDxvO6nwC7IGwwabb7QlEYBVLmPHrHh9Lmap2Tbws516TFFiWr8ivB0rXP5QJxY5h1oGJMpkwRuID2pY0uVzEHw4CvDps6vI27RmnHOoylVFOz+Io26K48TYWWyIcsRkaueU8rnl7t9jw0m+5F1K8qdmDeOIMTqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=txzCGNSz; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="txzCGNSz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779455731; 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=F+ecG0X94+FeO8dSnkv4AZz+6bKXxGyiG/aKDMvQzjg=; b=txzCGNSzXs/jXl8Ju7ZzwPkZ02mk5yPUjn6VMMJQn2dISDpR5LEDcnpAuv2phqU0Nv3n0j /pdijzPUrc0bU4zHLQDL7AXqH4i7rSaBB80MbgaU6nV56vvVUbRTpBw7OzKQzHM7ZUMhmu x+6mXDY9IxYM3pNx+52QddBplwUdokw= From: Kaitao Cheng To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com Cc: minchan@kernel.org, digetx@gmail.com, jhubbard@nvidia.com, gregkh@linuxfoundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng , Muchun Song Subject: [PATCH] mm/cma_sysfs: Skip inactive CMA areas in sysfs Date: Fri, 22 May 2026 21:14:34 +0800 Message-ID: <20260522131434.78532-1-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kaitao Cheng cma_activate_area() can fail after a CMA area has already been added to cma_areas[]. In that case the area is left in the global array, but it does not reach the point where CMA_ACTIVATED is set. cma_sysfs_init() currently walks all cma_area_count entries and creates sysfs files for every area, including ones that failed activation. These areas are not usable CMA areas and should not be exposed to userspace as valid CMA regions. Skip CMA areas that did not reach CMA_ACTIVATED when creating the sysfs objects. Since inactive entries can now be skipped, make the error unwind tolerate entries that never had cma_kobj initialized. Fixes: 43ca106fa8ec ("mm: cma: support sysfs") Reported-by: David Hildenbrand (Arm) Reported-by: Muchun Song Closes: https://lore.kernel.org/linux-mm/55481a8b-dcfc-4bef-ba59-aa0b43dca8= 8b@kernel.org/ Signed-off-by: Kaitao Cheng Acked-by: Muchun Song --- mm/cma_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/cma_sysfs.c b/mm/cma_sysfs.c index f52b696bc46d..d5bf792c6245 100644 --- a/mm/cma_sysfs.c +++ b/mm/cma_sysfs.c @@ -117,13 +117,16 @@ static int __init cma_sysfs_init(void) return -ENOMEM; =20 for (i =3D 0; i < cma_area_count; i++) { + cma =3D &cma_areas[i]; + if (!test_bit(CMA_ACTIVATED, &cma->flags)) + continue; + cma_kobj =3D kzalloc_obj(*cma_kobj); if (!cma_kobj) { err =3D -ENOMEM; goto out; } =20 - cma =3D &cma_areas[i]; cma->cma_kobj =3D cma_kobj; cma_kobj->cma =3D cma; err =3D kobject_init_and_add(&cma_kobj->kobj, &cma_ktype, @@ -138,7 +141,8 @@ static int __init cma_sysfs_init(void) out: while (--i >=3D 0) { cma =3D &cma_areas[i]; - kobject_put(&cma->cma_kobj->kobj); + if (cma->cma_kobj) + kobject_put(&cma->cma_kobj->kobj); } kobject_put(cma_kobj_root); =20 --=20 2.50.1 (Apple Git-155)