Skip to contentSkip to conversation

question about drivers/rtc/rtc-cmos.c

DISCUSSION Julia Lawall 3 participants 5 messages Dec 25, 2013 – Dec 27, 2013 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

The function cmos_do_probe contains the code:

		if (is_hpet_enabled()) {
                        int err;

                        rtc_cmos_int_handler = hpet_rtc_interrupt;
			err = hpet_register_irq_handler(cmos_interrupt);
                        if (err != 0) {
                                dev_warn(dev, "hpet_register_irq_handler "
                                                " failed in rtc_init().");
                                goto cleanup1;
                        }
                }

Is it intentional that the error code returned by hpet_register_irq_handler is put ina local variable that will not be seen at label cleanup1? The return value is retval, which is 0 at this point.

thanks,
julia

#1 lore raw
Quoted 3 lines · On Wed, 25 Dec 2013 20:32:12 +0100 (CET) Julia Lawall <[email protected]>…

Is it intentional that the error code returned by hpet_register_irq_handler is put ina local variable that will not be seen at label cleanup1? The return value is retval, which is 0 at this point.

Well, I'd say it's an error. Did you got it by hand or with one of your tools? ;)

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#2 lore raw
Quoted 10 lines · Alessandro Zummo
Quoted 3 lines · On Wed, 25 Dec 2013 20:32:12 +0100 (CET) Julia Lawall <[email protected]>…

Is it intentional that the error code returned by hpet_register_irq_handler is put ina local variable that will not be seen at label cleanup1? The return value is retval, which is 0 at this point.

Well, I'd say it's an error. Did you got it by hand or with one of your tools? ;)

Coccinelle. No idea if it an happen in real life.

I will drop err and replace it by retval.

julia

#3 lore raw
In reply to Julia Lawall
Quoted 14 lines · On Wed, 25 Dec 2013 20:32:12 +0100 (CET) Julia Lawall <[email protected]>…

The function cmos_do_probe contains the code:

		if (is_hpet_enabled()) {
                        int err;

                        rtc_cmos_int_handler = hpet_rtc_interrupt;
			err = hpet_register_irq_handler(cmos_interrupt);
                        if (err != 0) {
                                dev_warn(dev, "hpet_register_irq_handler "
                                                " failed in rtc_init().");
                                goto cleanup1;
                        }
                }
Quoted 3 lines

Is it intentional that the error code returned by hpet_register_irq_handler is put ina local variable that will not be seen at label cleanup1? The return value is retval, which is 0 at this point.

No, I'd say that's a bug. How does this look?

From: Andrew Morton <[email protected]>
Subject: drivers/rtc/rtc-cmos.c: propagate hpet_register_irq_handler() failure

If hpet_register_irq_handler() fails, cmos_do_probe() will incorrectly return 0.

---

 drivers/rtc/rtc-cmos.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/rtc/rtc-cmos.c renamed from drivers/rtc/rtc-cmos.c~drivers-rtc-rtc-cmosc-propagate-hpet_register_irq_handler-failure +2 -4
diff -puN drivers/rtc/rtc-cmos.c~drivers-rtc-rtc-cmosc-propagate-hpet_register_irq_handler-failure drivers/rtc/rtc-cmos.c
@@ -708,11 +708,9 @@ cmos_do_probe(struct device *dev, struct
 		irq_handler_t rtc_cmos_int_handler;
 
 		if (is_hpet_enabled()) {
-			int err;
-
 			rtc_cmos_int_handler = hpet_rtc_interrupt;
-			err = hpet_register_irq_handler(cmos_interrupt);
-			if (err != 0) {
+			retval = hpet_register_irq_handler(cmos_interrupt);
+			if (retval) {
 				dev_warn(dev, "hpet_register_irq_handler "
 						" failed in rtc_init().");
 				goto cleanup1;

_

#4 lore raw
Quoted 16 lines · Andrew Morton
Quoted 14 lines · On Wed, 25 Dec 2013 20:32:12 +0100 (CET) Julia Lawall <[email protected]>…

The function cmos_do_probe contains the code:

		if (is_hpet_enabled()) {
                        int err;

                        rtc_cmos_int_handler = hpet_rtc_interrupt;
			err = hpet_register_irq_handler(cmos_interrupt);
                        if (err != 0) {
                                dev_warn(dev, "hpet_register_irq_handler "
                                                " failed in rtc_init().");
                                goto cleanup1;
                        }
                }
Quoted 5 lines
Quoted 3 lines

Is it intentional that the error code returned by hpet_register_irq_handler is put ina local variable that will not be seen at label cleanup1? The return value is retval, which is 0 at this point.

No, I'd say that's a bug. How does this look?

That is what I was going to propose.

julia

Quoted 38 lines

From: Andrew Morton <[email protected]>
Subject: drivers/rtc/rtc-cmos.c: propagate hpet_register_irq_handler() failure

If hpet_register_irq_handler() fails, cmos_do_probe() will incorrectly return 0.

---

 drivers/rtc/rtc-cmos.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff -puN drivers/rtc/rtc-cmos.c~drivers-rtc-rtc-cmosc-propagate-hpet_register_irq_handler-failure drivers/rtc/rtc-cmos.c

drivers/rtc/rtc-cmos.c renamed from drivers/rtc/rtc-cmos.c~drivers-rtc-rtc-cmosc-propagate-hpet_register_irq_handler-failure +2 -4
@@ -708,11 +708,9 @@ cmos_do_probe(struct device *dev, struct
 		irq_handler_t rtc_cmos_int_handler;
 
 		if (is_hpet_enabled()) {
-			int err;
-
 			rtc_cmos_int_handler = hpet_rtc_interrupt;
-			err = hpet_register_irq_handler(cmos_interrupt);
-			if (err != 0) {
+			retval = hpet_register_irq_handler(cmos_interrupt);
+			if (retval) {
 				dev_warn(dev, "hpet_register_irq_handler "
 						" failed in rtc_init().");
 				goto cleanup1;

_