From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796140848; b=0RNKe6wgM/PEZzxD3jqBrOki4FW0gMmQ3olUN4qqglbTe+Huzia63LfHxtTSXtpp0lxI lI+tTN+ufbUw4rAqen8Qh+x2N/Rsnfc9TTSHUNMD7vf4fegsOVodycZVfiwwCEBr8ecuR 1caFXUZPtNyBGEl9Sa6+0zTaQ6hu93aQWSTycPjvSPIumy6NRJcohQfdGP/AASiaIzd/o c6K0M1IXyc2q5+WVwYRMIYXYR3Xv+fs5rTg8qBCZXAY94069pqiWDIz6fmYVhB7El8nJU dmgoFFePStyFr0hwJ55gY38dU6rGLjaZaLwepdEdZ0NHzXhZqupbPrNIgumdtYRv9uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796140848; 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=l8Jb1urHmVwqCSWxq2hW/Maj3JrXi72/qBcS99hIhnc=; b=zGk0kfGGMeRlr6UjgmUfrwp7laxtD3ikWZC9/mOc8n6HJVdb18oEu11z2EXQ9lCf8Fpz e8b39HVJRQNhHqatXfUyQa8upxTAgm8V/GZBaGLtyJnlofUeNsTzbRVirzcxxC8tMaxGW IqXYHLHhGJOaV2GmfzsZK1r1NzpbGZhOPw9c4WT2bL6QZHHqkMt4mAwfAWu2Km0BrizKT GRlPHBZ1xVcfrrZXCxkdrB9Iukz5lzSSpFd1yJxucGbmilRXTTyhv5Iflszf039Bf5S9C EMduOuxTjIX4U8z4sdCJ2fS8G9uRGwAGoT55gsIDt5Xxbl/tzKaibB3KphIsC3brXww== 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=a6WtsoWg; arc=none smtp.remote-ip=192.198.163.14 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 DD379606A320 for ; Tue, 1 Dec 2026 16:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DD379606A320 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=a6WtsoWg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796140849; x=1827676849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l8Jb1urHmVwqCSWxq2hW/Maj3JrXi72/qBcS99hIhnc=; b=a6WtsoWgi+BoQV2EuSg2Ui1BYFoASo4/lrjroiYIaiCPZ5MaFjAGL7Aa 10M4xkZPPxHpfP4vrJZsO0mzXsK3XzxOdCKxNJkCaFMacugHKwqdoERGU 4sD5Sgpl99hU8DglUL8HGyO6HNHOxAoMFFAT8men2JJtYflre2iW0wEMm VP+v2MBsh/s8z7WiegrofkjwnbxnnPVjLH0ly1H2cB77L1ZiEil2BH2LR bDS7akZGjhxu1+nir5y6KKPkK9VyypiyDnkjCo3EWm1hqxFsn/6MOme6S ukolZGw9p+o+jISs/q0Eo22yIYttCWuMlXEsaBetPyUci7hcfHN1qdDmh g==; X-CSE-ConnectionGUID: yl1P/j/sQeeOAa2m6S4NGQ== X-CSE-MsgGUID: TRROu6uhQoqRLT3GWsEi8g== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4990360" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4990360" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:00:33 -0800 X-CSE-ConnectionGUID: Hob1PYu6TR28WqzLwwfmGw== X-CSE-MsgGUID: NiRmU8sXSRumPpRftyxsTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13264152" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:00:25 -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, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 07/15] resource: Add release_leaf_resource() Date: Tue, 1 Dec 2026 17:58:31 +0200 Message-ID: <20261201155844.2278-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> References: <20261201155844.2278-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..d4a4bbc80190 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, true); +} + 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