rtc: don't finalize driver if initialization failed

This commit is contained in:
Miroslav Lichvar 2019-12-10 17:30:42 +01:00
parent 25bdee7a0e
commit a57e1eb542
2 changed files with 12 additions and 13 deletions

2
rtc.c
View file

@ -160,7 +160,7 @@ RTC_Initialise(int initial_set)
void void
RTC_Finalise(void) RTC_Finalise(void)
{ {
if (driver.fini) { if (driver_initialised) {
(driver.fini)(); (driver.fini)();
} }
} }

View file

@ -505,18 +505,7 @@ switch_interrupts(int on_off)
int int
RTC_Linux_Initialise(void) RTC_Linux_Initialise(void)
{ {
rtc_sec = MallocArray(time_t, MAX_SAMPLES); /* Try to open the device */
rtc_trim = MallocArray(double, MAX_SAMPLES);
system_times = MallocArray(struct timespec, MAX_SAMPLES);
/* Setup details depending on configuration options */
setup_config();
/* In case it didn't get done by pre-init */
coefs_file_name = CNF_GetRtcFile();
/* Try to open device */
fd = open(CNF_GetRtcDevice(), O_RDWR); fd = open(CNF_GetRtcDevice(), O_RDWR);
if (fd < 0) { if (fd < 0) {
LOG(LOGS_ERR, "Could not open RTC device %s : %s", LOG(LOGS_ERR, "Could not open RTC device %s : %s",
@ -527,6 +516,16 @@ RTC_Linux_Initialise(void)
/* Close on exec */ /* Close on exec */
UTI_FdSetCloexec(fd); UTI_FdSetCloexec(fd);
rtc_sec = MallocArray(time_t, MAX_SAMPLES);
rtc_trim = MallocArray(double, MAX_SAMPLES);
system_times = MallocArray(struct timespec, MAX_SAMPLES);
/* Setup details depending on configuration options */
setup_config();
/* In case it didn't get done by pre-init */
coefs_file_name = CNF_GetRtcFile();
n_samples = 0; n_samples = 0;
n_samples_since_regression = 0; n_samples_since_regression = 0;
n_runs = 0; n_runs = 0;