Skip to contentSkip to conversation

watchdog: aspeed: fix 64-bit division

PATCH In review Arnd Bergmann 4 participants 6 messages Mar 14, 2025 – Mar 18, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: aspeed: fix 64-bit division

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the new calculation causes a build failure:

ld.lld-21: error: undefined symbol: __aeabi_uldivmod

Since neither value is ever larger than a register, cast both sides into a uintptr_t.

Fixes 5c03f9f4d362 ("watchdog: aspeed: Update bootstatus handling")
---
 drivers/watchdog/aspeed_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/aspeed_wdt.c +1 -1
index 369635b38ca0..837e15701c0e 100644
@@ -254,7 +254,7 @@ static void aspeed_wdt_update_bootstatus(struct platform_device *pdev,
 
 	if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt")) {
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		idx = ((intptr_t)wdt->base & 0x00000fff) / resource_size(res);
+		idx = ((intptr_t)wdt->base & 0x00000fff) / (uintptr_t)resource_size(res);
 	}
 
 	scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 20 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the new calculation causes a build failure:

ld.lld-21: error: undefined symbol: __aeabi_uldivmod

Since neither value is ever larger than a register, cast both sides into a uintptr_t.

Fixes 5c03f9f4d362 ("watchdog: aspeed: Update bootstatus handling")
---
  drivers/watchdog/aspeed_wdt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/aspeed_wdt.c +0 -0
index 369635b38ca0..837e15701c0e 100644

drivers/watchdog/aspeed_wdt.c static void aspeed_wdt_update_bootstatus(struct platform_device *pdev, · line 260

Quoted 8 lines
drivers/watchdog/aspeed_wdt.c +1 -1
@@ -254,7 +254,7 @@ static void aspeed_wdt_update_bootstatus(struct platform_device *pdev,
 
  	if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt")) {
  		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		idx = ((intptr_t)wdt->base & 0x00000fff) / resource_size(res);
+		idx = ((intptr_t)wdt->base & 0x00000fff) / (uintptr_t)resource_size(res);
  	}
 
  	scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);

Does that help if the pointers are 64-bit on a 32-bit platform (multi_v7_lpae_defconfig) ?

Guenter

#2 lore raw
Quoted 11 lines · Guenter Roeck

drivers/watchdog/aspeed_wdt.c static void aspeed_wdt_update_bootstatus(struct platform_device *pdev, · line 260

Quoted 8 lines · Arnd Bergmann
  
  	if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt")) {
  		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/watchdog/aspeed_wdt.c +1 -1
-		idx = ((intptr_t)wdt->base & 0x00000fff) / resource_size(res);
+		idx = ((intptr_t)wdt->base & 0x00000fff) / (uintptr_t)resource_size(res);
  	}
 
  	scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);

Does that help if the pointers are 64-bit on a 32-bit platform (multi_v7_lpae_defconfig) ?

Yes, that is the problem: resource_size() returns a resource_size_t, so this is a 32-bit by 64-bit division.

Pointers are always 32-bit, CONFIG_LPAE only changes phys_addr_t and resource_size_t.

Arnd

maintainer
#3 lore raw
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Guenter Roeck

drivers/watchdog/aspeed_wdt.c static void aspeed_wdt_update_bootstatus(struct platform_device *pdev, · line 260

Quoted 8 lines · Arnd Bergmann
   
   	if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt")) {
   		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/watchdog/aspeed_wdt.c +1 -1
-		idx = ((intptr_t)wdt->base & 0x00000fff) / resource_size(res);
+		idx = ((intptr_t)wdt->base & 0x00000fff) / (uintptr_t)resource_size(res);
   	}
 
   	scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);

Does that help if the pointers are 64-bit on a 32-bit platform (multi_v7_lpae_defconfig) ?

Quoted 6 lines

Yes, that is the problem: resource_size() returns a resource_size_t, so this is a 32-bit by 64-bit division.

Pointers are always 32-bit, CONFIG_LPAE only changes phys_addr_t and resource_size_t.

Ok. Thanks for the clarification.

Guenter

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the new calculation causes a build failure:

ld.lld-21: error: undefined symbol: __aeabi_uldivmod

Since neither value is ever larger than a register, cast both sides into a uintptr_t.

Fixes 5c03f9f4d362 ("watchdog: aspeed: Update bootstatus handling")
Quoted 17 lines
---
  drivers/watchdog/aspeed_wdt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/aspeed_wdt.c +1 -1
index 369635b38ca0..837e15701c0e 100644
@@ -254,7 +254,7 @@ static void aspeed_wdt_update_bootstatus(struct platform_device *pdev,
 
  	if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt")) {
  		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		idx = ((intptr_t)wdt->base & 0x00000fff) / resource_size(res);
+		idx = ((intptr_t)wdt->base & 0x00000fff) / (uintptr_t)resource_size(res);
  	}
 
  	scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);
maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures, the new calculation causes a build failure:

ld.lld-21: error: undefined symbol: __aeabi_uldivmod

Since neither value is ever larger than a register, cast both sides into a uintptr_t.

Fixes 5c03f9f4d362 ("watchdog: aspeed: Update bootstatus handling")

Thanks,

Andrew