drivers/rtc/class.c: initialize rtc name early
authorAaro Koskinen <aaro.koskinen@iki.fi>
Thu, 16 Apr 2015 19:45:48 +0000 (12:45 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Apr 2015 13:04:01 +0000 (09:04 -0400)
In some error cases RTC name is used before it is initialized:

rtc-rs5c372 0-0032: clock needs to be set
rtc-rs5c372 0-0032: rs5c372b found, 24hr, driver version 0.6
rtc (null): read_time: fail to read
rtc-rs5c372 0-0032: rtc core: registered rtc-rs5c372 as rtc0

Fix by initializing the name early.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/class.c

index c29ba7e1430482c1ffe6c6ec92e1bd5cc7b06743..ea2a315df6b7bb5fb8fcae65cf4d21ce054f94b0 100644 (file)
@@ -221,15 +221,15 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
        rtc->pie_timer.function = rtc_pie_update_irq;
        rtc->pie_enabled = 0;
 
+       strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
+       dev_set_name(&rtc->dev, "rtc%d", id);
+
        /* Check to see if there is an ALARM already set in hw */
        err = __rtc_read_alarm(rtc, &alrm);
 
        if (!err && !rtc_valid_tm(&alrm.time))
                rtc_initialize_alarm(rtc, &alrm);
 
-       strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
-       dev_set_name(&rtc->dev, "rtc%d", id);
-
        rtc_dev_prepare(rtc);
 
        err = device_register(&rtc->dev);