summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>2025-01-20 15:09:40 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-02-17 11:36:25 +0100
commita7252cbdc244c1cc47cb8a843445fb864be92de8 (patch)
treec44b22e409ce7fecb47875d7da70ffc1964d6a83 /drivers
parent7ef6c0eae3e699e2b72019837d7633433ee43fb5 (diff)
downloadlinux-a7252cbdc244c1cc47cb8a843445fb864be92de8.tar.gz
linux-a7252cbdc244c1cc47cb8a843445fb864be92de8.tar.bz2
linux-a7252cbdc244c1cc47cb8a843445fb864be92de8.zip
of: address: Fix empty resource handling in __of_address_resource_bounds()
commit 15e2f65f2ecfeb8e39315522e2b5cfdc5651fc10 upstream. "resource->end" needs to always be equal to "resource->start + size - 1". The previous version of the function did not perform the "- 1" in case of an empty resource. Also make sure to allow an empty resource at address 0. Reported-by: Basharath Hussain Khaja <basharath@couthit.com> Closes: https://lore.kernel.org/lkml/20250108140414.13530-1-basharath@couthit.com/ Fixes: 1a52a094c2f0 ("of: address: Unify resource bounds overflow checking") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://lore.kernel.org/r/20250120-of-address-overflow-v1-1-dd68dbf47bce@linutronix.de Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/address.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 8770004d9b08..5c0663066a7f 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -200,17 +200,15 @@ static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
static int __of_address_resource_bounds(struct resource *r, u64 start, u64 size)
{
- u64 end = start;
-
if (overflows_type(start, r->start))
return -EOVERFLOW;
- if (size && check_add_overflow(end, size - 1, &end))
- return -EOVERFLOW;
- if (overflows_type(end, r->end))
- return -EOVERFLOW;
r->start = start;
- r->end = end;
+
+ if (!size)
+ r->end = wrapping_sub(typeof(r->end), r->start, 1);
+ else if (size && check_add_overflow(r->start, size - 1, &r->end))
+ return -EOVERFLOW;
return 0;
}