Skip to contentSkip to conversation

goldfish: Return error when device address is invalid

PATCH In review Kuan-Wei Chiu 2 participants 4 messages Jun 8 – Jun 24 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

cover goldfish: Return error when device address is invalid

A patch was submitted by Naveen for the goldfish serial driver to return an error immediately in of_to_plat() when dev_read_addr() fails, rather than deferring the failure to the probe() stage.

To maintain consistency across the goldfish driver family and better align with the driver model's fail fast design, this series applies the exact same logic to the goldfish timer and rtc drivers.

Inspired by Naveen's patch for the serial driver:
https://lore.kernel.org/u-boot/vgwnt6mnls3lf3zdm6mz5siztzkvppte4ykszbvifjzukvmksf@maaxe5agqpim/

Tested on qemu m68k virt board with date and sleep commands.

Kuan-Wei Chiu (2):
timer: goldfish: Return error when device address is invalid
rtc: goldfish: Return error when device address is invalid

 drivers/rtc/goldfish_rtc.c     | 8 ++++++--
 drivers/timer/goldfish_timer.c | 6 ++++--
 2 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
#1 lore raw

PATCH 1/2 timer: goldfish: Return error when device address is invalid

goldfish_timer_of_to_plat() currently returns success even when dev_read_addr() fails to find a valid address. This leaves plat->reg unset and defers the failure to probe().

Return -EINVAL immediately when the address is FDT_ADDR_T_NONE so the failure is reported at the of_to_plat stage where it belongs. This aligns the driver with the recent fix introduced in the goldfish serial driver by Naveen Kumar Chaudhary. [1]

---
 drivers/timer/goldfish_timer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/timer/goldfish_timer.c +4 -2
index 91277d7932a..59ce43fcb46 100644
@@ -45,8 +45,10 @@ static int goldfish_timer_of_to_plat(struct udevice *dev)
 	fdt_addr_t addr;
 
 	addr = dev_read_addr(dev);
-	if (addr != FDT_ADDR_T_NONE)
-		plat->reg = addr;
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	plat->reg = addr;
 
 	return 0;
 }
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
#2 lore raw

PATCH 2/2 rtc: goldfish: Return error when device address is invalid

In reply to Kuan-Wei Chiu

goldfish_rtc_of_to_plat() currently returns success even when dev_read_addr() fails to find a valid address. This leaves plat->reg unset (or 0) and defers the failure to probe().

Return -EINVAL immediately when the address is FDT_ADDR_T_NONE so the failure is reported at the of_to_plat stage where it belongs. This aligns the driver with the recent fix introduced in the goldfish serial driver by Naveen Kumar Chaudhary. [1]

---
 drivers/rtc/goldfish_rtc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/rtc/goldfish_rtc.c +6 -2
index 4892a63f8d8..652eec7dd0c 100644
@@ -80,9 +80,13 @@ static int goldfish_rtc_of_to_plat(struct udevice *dev)
 	struct goldfish_rtc_plat *plat = dev_get_plat(dev);
 	fdt_addr_t addr;
 
+	plat->reg = 0;
+
 	addr = dev_read_addr(dev);
-	if (addr != FDT_ADDR_T_NONE)
-		plat->reg = addr;
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	plat->reg = addr;
 
 	return 0;
 }
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
#3 lore raw
In reply to Kuan-Wei Chiu
Quoted 9 lines · Kuan-Wei Chiu

A patch was submitted by Naveen for the goldfish serial driver to return an error immediately in of_to_plat() when dev_read_addr() fails, rather than deferring the failure to the probe() stage.

To maintain consistency across the goldfish driver family and better align with the driver model's fail fast design, this series applies the exact same logic to the goldfish timer and rtc drivers.

[...]

Applied to u-boot/next, thanks!

[1/2] timer: goldfish: Return error when device address is invalid

      commit: 2bc9c58e7f09e5c5383ad63f85f35b686d63c0bf
[2/2] rtc: goldfish: Return error when device address is invalid
      commit: 47e9c542ee032e89f556adc73c2aeff3acb0e5a9
Signature · 1 line
Tom