Skip to contentSkip to conversation

rtc: twl: Check return value of platform_get_irq()

PATCH In review Salah Triki 3 participants 3 messages Jul 24, 2025 – Jul 27, 2025 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: twl: Check return value of platform_get_irq()

platform_get_irq() may fail, so check its return value and propagate the error in case of failure.

---
 drivers/rtc/rtc-twl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/rtc/rtc-twl.c +5 -2
index e6106e67e1f4..992b3e1347f2 100644
@@ -224,8 +224,11 @@ static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct twl_rtc *twl_rtc = dev_get_drvdata(dev);
-	int irq = platform_get_irq(pdev, 0);
-	int ret;
+	int irq, ret;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
 
 	if (enabled) {
 		ret = set_rtc_irq_bit(twl_rtc,
Signature · 1 line
2.43.0
#1 lore raw
Quoted 13 lines · Salah Triki

platform_get_irq() may fail, so check its return value and propagate the error in case of failure.

---
 drivers/rtc/rtc-twl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/rtc/rtc-twl.c +0 -0
index e6106e67e1f4..992b3e1347f2 100644

drivers/rtc/rtc-twl.c static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled) · line 231

Quoted 10 lines
drivers/rtc/rtc-twl.c +5 -2
@@ -224,8 +224,11 @@ static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct twl_rtc *twl_rtc = dev_get_drvdata(dev);
-	int irq = platform_get_irq(pdev, 0);
-	int ret;
+	int irq, ret;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;

It won't ever fail because we know it already succeeded earlier.

Quoted 6 lines
drivers/rtc/rtc-twl.c +0 -0
 	if (enabled) {
 		ret = set_rtc_irq_bit(twl_rtc,
Signature · 1 line
2.43.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

…

Quoted 6 lines
Quoted 6 lines

+++ b/drivers/rtc/rtc-twl.c

drivers/rtc/rtc-twl.c +0 -1
@@ -224,8 +224,11 @@ static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct twl_rtc *twl_rtc = dev_get_drvdata(dev);
-	int irq = platform_get_irq(pdev, 0);
Quoted 8 lines

drivers/rtc/rtc-twl.c static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled) · line 231

Quoted 6 lines
drivers/rtc/rtc-twl.c +5 -1
-	int ret;
+	int irq, ret;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;

It won't ever fail because we know it already succeeded earlier.

An execution failure would be strange at this place after a successful function call within twl_rtc_probe(), wouldn't it?
https://elixir.bootlin.com/linux/v6.16-rc7/source/drivers/rtc/rtc-twl.c#L504-L519

Regards,
Markus