ac3a84
From 176ceed28620a9358c5528a039b74211187bcf13 Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Mon, 14 Nov 2022 00:09:34 +0900
ac3a84
Subject: [PATCH] sleep: drop unnecessary temporal vaiable and initialization
ac3a84
ac3a84
(cherry picked from commit 2ed56afeb3c26596dbe44858559c92307778ff82)
ac3a84
ac3a84
Related: #2151612
ac3a84
---
ac3a84
 src/sleep/sleep.c | 11 ++++++-----
ac3a84
 1 file changed, 6 insertions(+), 5 deletions(-)
ac3a84
ac3a84
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
ac3a84
index 11a2ba507d..039b123dcc 100644
ac3a84
--- a/src/sleep/sleep.c
ac3a84
+++ b/src/sleep/sleep.c
ac3a84
@@ -275,7 +275,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
ac3a84
         while (battery_is_low() == 0) {
ac3a84
                 _cleanup_close_ int tfd = -1;
ac3a84
                 struct itimerspec ts = {};
ac3a84
-                usec_t suspend_interval = sleep_config->hibernate_delay_usec, total_suspend_interval;
ac3a84
+                usec_t suspend_interval;
ac3a84
                 bool woken_by_timer;
ac3a84
 
ac3a84
                 tfd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK|TFD_CLOEXEC);
ac3a84
@@ -287,11 +287,12 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
ac3a84
                 if (r < 0)
ac3a84
                         return log_error_errno(r, "Error fetching battery capacity percentage: %m");
ac3a84
 
ac3a84
-                r = get_total_suspend_interval(last_capacity, &total_suspend_interval);
ac3a84
-                if (r < 0)
ac3a84
+                r = get_total_suspend_interval(last_capacity, &suspend_interval);
ac3a84
+                if (r < 0) {
ac3a84
                         log_debug_errno(r, "Failed to estimate suspend interval using previous discharge rate, ignoring: %m");
ac3a84
-                else
ac3a84
-                        suspend_interval = total_suspend_interval;
ac3a84
+                        /* In case of no battery or any errors, system suspend interval will be set to HibernateDelaySec=. */
ac3a84
+                        suspend_interval = sleep_config->hibernate_delay_usec;
ac3a84
+                }
ac3a84
 
ac3a84
                 usec_t before_timestamp = now(CLOCK_BOOTTIME);
ac3a84