From nobody Fri Nov 29 01:37:39 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 86A1417BB4 for ; Wed, 25 Sep 2024 15:44:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727279043; cv=none; b=d92Q+aSqAH8ue5Esi5PkNDSnNKE39zLDoZ31h/GfNu33jigee3rQpY0byrGu4cO8maMdWLSHwhX6D8lJysM4dQwUQWkU4U/kKEMnrmwEazUd27b9SIWF8DYeR5vFKDJKhGnrR3NW85NL1wt5YPrnT+AGpxhX4wRk2iNOPPIqzYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727279043; c=relaxed/simple; bh=rFOs3yP2cOBTsiJkJ/FO03Pb+M8BQkMQ2nUOI+pby7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PpgQkuSFK5+B+J1c/3Rdx76ESCKwMrmT34Awk6gOcjxn0HhSXRunoOB2YNPWUfI+9lS5jv05nQZ3vOONWp2nvs3kYYB678UMAh11VJjnChRT4XLCwOUhe2bvxey6jPQmvmqtSKcfUWL2fwnAxFrUwEjMARqBPoQTvDswAc/TZkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NmV/OSdk; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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.b="NmV/OSdk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727279041; x=1758815041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rFOs3yP2cOBTsiJkJ/FO03Pb+M8BQkMQ2nUOI+pby7U=; b=NmV/OSdkKFud3CN5StAZvpHwMxEENnYSu5DvBRMXuwxE70vuZHbEJAfs Biu/1IzKLg1TpPx3ngT95+LgU7jSa8z6JxR+5cVP91NltVNO+7PdRf+oI CyBA5JZbjnUJGi5PLPU03NPd8TvVA/1CCuk7A3gAiKwyxavwmAZfdj0jd bMzQTQO4fqh6UWh9BFNJvRnIIsjMrLQYTFCYsjFbyRNbigmCtCEIT53wa T1xSyIVoc5KMUe1N4gD58dgbxa49e8crnGItN15js31JT3tJf0ed456pn e0YVbvXF+ceZC7PNXFvF7bvwePBf7drj6D/sTZfIcqROsOdPs0Mw4ral5 Q==; X-CSE-ConnectionGUID: dqLp00SyQSeRzFsh+ko3qA== X-CSE-MsgGUID: 9AviA2Q3QO2jQcO4FpFryQ== X-IronPort-AV: E=McAfee;i="6700,10204,11206"; a="26488841" X-IronPort-AV: E=Sophos;i="6.10,257,1719903600"; d="scan'208";a="26488841" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2024 08:44:01 -0700 X-CSE-ConnectionGUID: RF04esb5SQC8ADsxB+gErw== X-CSE-MsgGUID: g19OvBGlToOYx5eZZ0QyFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,257,1719903600"; d="scan'208";a="76748836" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 25 Sep 2024 08:43:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 42C7315C; Wed, 25 Sep 2024 18:43:58 +0300 (EEST) From: Andy Shevchenko To: linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Andy Shevchenko Subject: [PATCH v1 1/2] resource: Replace open coded resource_intersection() Date: Wed, 25 Sep 2024 18:43:34 +0300 Message-ID: <20240925154355.1170859-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240925154355.1170859-1-andriy.shevchenko@linux.intel.com> References: <20240925154355.1170859-1-andriy.shevchenko@linux.intel.com> 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 Content-Type: text/plain; charset="utf-8" The __region_intersects() uses open coded resource_intersection(). Replace it with existing API which also make more clear what we are checking. Signed-off-by: Andy Shevchenko --- kernel/resource.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index b730bd28b422..6880c0e283dd 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -539,17 +539,16 @@ static int __region_intersects(struct resource *paren= t, resource_size_t start, size_t size, unsigned long flags, unsigned long desc) { - resource_size_t ostart, oend; int type =3D 0; int other =3D 0; struct resource *p, *dp; + struct resource res, o; bool is_type, covered; - struct resource res; =20 res.start =3D start; res.end =3D start + size - 1; =20 for (p =3D parent->child; p ; p =3D p->sibling) { - if (!resource_overlaps(p, &res)) + if (!resource_intersection(p, &res, &o)) continue; is_type =3D (p->flags & flags) =3D=3D flags && (desc =3D=3D IORES_DESC_NONE || desc =3D=3D p->desc); @@ -570,8 +569,6 @@ static int __region_intersects(struct resource *parent,= resource_size_t start, * |-- "System RAM" --||-- "CXL Window 0a" --| */ covered =3D false; - ostart =3D max(res.start, p->start); - oend =3D min(res.end, p->end); for_each_resource(p, dp, false) { if (!resource_overlaps(dp, &res)) continue; @@ -580,17 +577,17 @@ static int __region_intersects(struct resource *paren= t, resource_size_t start, if (is_type) { type++; /* - * Range from 'ostart' to 'dp->start' + * Range from 'o.start' to 'dp->start' * isn't covered by matched resource. */ - if (dp->start > ostart) + if (dp->start > o.start) break; - if (dp->end >=3D oend) { + if (dp->end >=3D o.end) { covered =3D true; break; } /* Remove covered range */ - ostart =3D max(ostart, dp->end + 1); + o.start =3D max(o.start, dp->end + 1); } } if (!covered) --=20 2.43.0.rc1.1336.g36b5255a03ac From nobody Fri Nov 29 01:37:39 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 3CF9A1D5AD7 for ; Wed, 25 Sep 2024 15:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727279044; cv=none; b=HovXEmm6D79Zbt26n5ga59PPN9XQcCIAptka9axZ3vPKSYGN+VzE3MQMmmEWkkMMUiz4AtYU6qqahonYjRRQprIyPAy0f7OyprTKSFFHhkcD+KWTYFsfRXdkwtAZ6b7x4Je6tXvMWcFaT4IuqJywIKjkDkRoSHhemsNGz5e9yrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727279044; c=relaxed/simple; bh=MWXGrbZKhplb8b5pdAR8zTppw4TNyfFnSpLm65mxNg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dXa+6pVlvoGLe6oa7trlz1RitobvJYyP+qTkUn01PBRD8ILkMMaQc23lgvTXvuHTZEQEnGq1Jstvy4a1Ec/cjbSDtucTATPC5NWVAo587mbiDakfrm4nB0cYo4mkOsdAyk+wdhnSIEsTNGltTBuIetpyuJC1hzmbt4B3OCeS7mQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EXWy5Vr2; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none 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.b="EXWy5Vr2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727279043; x=1758815043; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MWXGrbZKhplb8b5pdAR8zTppw4TNyfFnSpLm65mxNg8=; b=EXWy5Vr25AF34kCJbthg5/oFeLd8OcAOQfUvEaa7MzyKcEDz1kXxn2Ft xlk5GeF79OilCf7g234A+O5oECtTi+qkR/MJxzPRZZRmsRqQBiTtNh2sV ByTTvGzY0cjXhCqG9hpTvAK5m5ivPXJcKthdUO9ZVyk8yC11sSdPXySdL C2Xn6RE3NWbqbi1iGQP7an2lUY07ork6UAOuX/gHR+wf4/Y9U4naOmzFh yKTHUAISaSSTn4mJyHV0aOVbao8qN4XikQwLhEYrY3dVf3HYozGc8jZi8 cJ3aghskfhw5OvkMYCKX5fT5AMDsASBQAxJG4zUIuP13DtY8P/k47BUQj w==; X-CSE-ConnectionGUID: 6jAZviWHRS6tuyGeY5j2zw== X-CSE-MsgGUID: RCpq5zMeQnWS+ijCkPaRzg== X-IronPort-AV: E=McAfee;i="6700,10204,11206"; a="51752543" X-IronPort-AV: E=Sophos;i="6.10,257,1719903600"; d="scan'208";a="51752543" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2024 08:44:01 -0700 X-CSE-ConnectionGUID: OpeOVUwgQUCWEHsaGrBRZA== X-CSE-MsgGUID: WUgH7Bn0R0SKdoldUzzWAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,257,1719903600"; d="scan'208";a="71411835" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa006.fm.intel.com with ESMTP; 25 Sep 2024 08:43:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4BE23565; Wed, 25 Sep 2024 18:43:58 +0300 (EEST) From: Andy Shevchenko To: linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Rasmus Villemoes , Andrew Morton , Andy Shevchenko Subject: [PATCH v1 2/2] resource: Introduce is_type_match() helper and use it Date: Wed, 25 Sep 2024 18:43:35 +0300 Message-ID: <20240925154355.1170859-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240925154355.1170859-1-andriy.shevchenko@linux.intel.com> References: <20240925154355.1170859-1-andriy.shevchenko@linux.intel.com> 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 Content-Type: text/plain; charset="utf-8" There are already a couple of places where we may replace a few lines of code by calling a helper, which increases readability while deduplicating the code. Introduce is_type_match() helper and use it. Signed-off-by: Andy Shevchenko --- kernel/resource.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 6880c0e283dd..2d266b5ff881 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -297,6 +297,11 @@ int release_resource(struct resource *old) =20 EXPORT_SYMBOL(release_resource); =20 +static bool is_type_match(struct resource *p, unsigned long flags, unsigne= d long desc) +{ + return (p->flags & flags) =3D=3D flags && (desc =3D=3D IORES_DESC_NONE ||= desc =3D=3D p->desc); +} + /** * find_next_iomem_res - Finds the lowest iomem resource that covers part = of * [@start..@end]. @@ -339,13 +344,9 @@ static int find_next_iomem_res(resource_size_t start, = resource_size_t end, if (p->end < start) continue; =20 - if ((p->flags & flags) !=3D flags) - continue; - if ((desc !=3D IORES_DESC_NONE) && (desc !=3D p->desc)) - continue; - /* Found a match, break */ - break; + if (is_type_match(p, flags, desc)) + break; } =20 if (p) { @@ -542,7 +543,7 @@ static int __region_intersects(struct resource *parent,= resource_size_t start, int type =3D 0; int other =3D 0; struct resource *p, *dp; struct resource res, o; - bool is_type, covered; + bool covered; =20 res.start =3D start; res.end =3D start + size - 1; @@ -550,9 +551,7 @@ static int __region_intersects(struct resource *parent,= resource_size_t start, for (p =3D parent->child; p ; p =3D p->sibling) { if (!resource_intersection(p, &res, &o)) continue; - is_type =3D (p->flags & flags) =3D=3D flags && - (desc =3D=3D IORES_DESC_NONE || desc =3D=3D p->desc); - if (is_type) { + if (is_type_match(p, flags, desc)) { type++; continue; } @@ -572,9 +571,7 @@ static int __region_intersects(struct resource *parent,= resource_size_t start, for_each_resource(p, dp, false) { if (!resource_overlaps(dp, &res)) continue; - is_type =3D (dp->flags & flags) =3D=3D flags && - (desc =3D=3D IORES_DESC_NONE || desc =3D=3D dp->desc); - if (is_type) { + if (is_type_match(dp, flags, desc)) { type++; /* * Range from 'o.start' to 'dp->start' --=20 2.43.0.rc1.1336.g36b5255a03ac