From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796431305; b=C5K/w6z1M9z+Z6WSnBcP0YRKUriehwshkohc70z3kop50DkMzDlg4yhqfXnhqUC4PrhO OF2Lszum45ca9E/oalMdFA1XN0E3f1sxFiF1383dg8LLaBdtUURgy71etmXEJx5B5tFVU QtznF0MevGXSRTiZ2PiGXA0JQKugU6f2zGV3FeG6Pez4ljEZJwTUJGTRPFC+sOtuK4i87 VfPDaxwa9dUg6LVwl8giV+C/kwM+us2QA0Xyfus2nnSY5lhXv9DrcROpM3MZH6NCxL6Sf DNqMwP4xDCHq2FTJ9JbVKu8qF3LuX0WdiXCQbvzj3poaXjLEP0/4p/LAsyeHi3dAj2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431305; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=cbmp9zyuBEicoorafvCUTCB+R0hJF5oUJk7lCfTEImE=; b=rrhCYUKvs6PuY3Y6CqMzXQh8lS8rA1SwFnM48qNQJQgT2M42CScl02G4yJmGpFmxLn7u anmVy8wglR/Uw4rwN1K1VSYxR06A0MRADoW3K4cUsh0S6a8Wj7W9tycjIhbcMhE6AWJYc ujf+gXkEx422+7z8hvQ+e2JLrYU0E0v8UhoJvnkQYT5eQCBQAD6+o+KHQRpVYsWTyKY8L p4gReVz7Q2mHyIjgTOB++MHNtX4BwyLfrkOVpBZldC+fmf3gXjXCIxVgiCJ0S1sE5JyR2 w+VwMIPoRFKKwb+nzQFkWdO24ZkWQrkXTdmvoGGRHZKMqErFIesQPiA0QdCaKN/LKrg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YslovSa0; arc=none smtp.remote-ip=192.198.163.10 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E894606A332 for ; Sat, 5 Dec 2026 00:41:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0E894606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YslovSa0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431305; x=1827967305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cbmp9zyuBEicoorafvCUTCB+R0hJF5oUJk7lCfTEImE=; b=YslovSa0M5utbibnMC65eXE8gYUpQ/m+v3gWXHOdVKlZwGwOAeUAObCB Py8DTgwCGOrqEYW2QiZn4lvD8M1aDhfcvPA9IghT2tiYSMtAhdiF/dfzu 7Bu6yqiGtRgbtOb5Ed6EzFABSEbwGY40OnM0K51BgethtFE3r2bugE+nV W9nXOlwg3v0VeG0atro6bzRCe60fH7U1/eEzGbw8EJE+zks4JslBT0SE3 noGyaZVjMqMHG8g4vp4qPm+JCq7AvWypcNyWx04wqssV/dXPB3u9LhWuA Yzz8VBy7Qij+PnlpGcgmt5P/ySaywS7ga7UpgWjVctbKTXpS3v+IUZTm5 Q==; X-CSE-ConnectionGUID: nYzCjv31T1a6hrM5X38gfQ== X-CSE-MsgGUID: FU66kkCWTaC9WsRPv1W17w== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5308290" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5308290" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:41:44 -0800 X-CSE-ConnectionGUID: Q03ui3yoTuiZCZ8m+3jixg== X-CSE-MsgGUID: zz+aD9BbSi2vELiBvOcXWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14464546" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:41:38 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Anthony Pighin , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 07/16] resource: Add release_leaf_resource() Date: Sat, 5 Dec 2026 02:39:42 +0200 Message-ID: <20261205003957.3304-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit release_resource() releases a resource together with its descendants. The descendants remain attached to the released resource and keep their addresses, so when the resource is placed elsewhere afterwards, the descendants may end up outside of their parent. Add release_leaf_resource() that does not release a resource that has children. Check for the children under resource_lock so that no child can be added in between. Signed-off-by: Ilpo Järvinen --- include/linux/ioport.h | 1 + kernel/resource.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index f7930b3dfd0a..f38800fb957d 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -244,6 +244,7 @@ extern struct resource soft_reserve_resource; extern struct resource *request_resource_conflict(struct resource *root, struct resource *new); extern int request_resource(struct resource *root, struct resource *new); extern int release_resource(struct resource *new); +int release_leaf_resource(struct resource *old); void release_child_resources(struct resource *new); extern void reserve_region_with_split(struct resource *root, resource_size_t start, resource_size_t end, diff --git a/kernel/resource.c b/kernel/resource.c index 68843852f342..2ea3fddf8769 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -326,6 +326,26 @@ int release_resource(struct resource *old) EXPORT_SYMBOL(release_resource); +/** + * release_leaf_resource - release a resource that has no children + * @old: resource pointer + * + * Unlike release_resource(), do not release @old if it has children as + * they would remain attached to @old with their addresses. + * + * Return: 0 on success, -EBUSY if @old has children, or -EINVAL if @old is + * not in a resource tree. + */ +int release_leaf_resource(struct resource *old) +{ + guard(write_lock)(&resource_lock); + + if (old->child) + return -EBUSY; + + return __release_resource(old, false); +} + static bool is_type_match(struct resource *p, unsigned long flags, unsigned long desc) { return (p->flags & flags) == flags && (desc == IORES_DESC_NONE || desc == p->desc); -- 2.47.3