From nobody Wed Feb 11 02:10:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1656928219; cv=none; d=zohomail.com; s=zohoarc; b=TtfCqU/5p9+9JHa6FMTkIGoj9rwie4fjIL66kbmakv6O11C3ohpQxdZLEBqnZIhXhRlLMDIKF1h04GRL0RL37MVDe1i2inCtCeK8Zz/x+TB6bDem9ERVWRGU/pgEn8KBu49oEJfrGqIv4UVLzsdJhTOzHpOOT8N60OF1kg9kAzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656928219; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PPqUahiWt2M7Eg8LZ9lJoQvj046orfAZ2qStTlP4KlU=; b=UyAQ6jNz+bFKGS5oIIpfkJmbUo0hkLFHZFpkYSLUyY5A7rY96dPSrKulGV1O0VpNZfYC6+x5+SOq9UkLYek+UkSgjlExYlxX1LKbxNjhPY7sDMD9KM/8HZdFKw3geg64v5Op80l5FJ2ZI0hufuSp7t4WbYHAIpEKJBDMLxjjdTk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656928219324675.516415907871; Mon, 4 Jul 2022 02:50:19 -0700 (PDT) Received: from localhost ([::1]:40324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8Iif-0002wZ-A7 for importer@patchew.org; Mon, 04 Jul 2022 05:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8ITh-0000wt-Cm for qemu-devel@nongnu.org; Mon, 04 Jul 2022 05:34:49 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:37668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8ITe-0004zB-97 for qemu-devel@nongnu.org; Mon, 04 Jul 2022 05:34:49 -0400 Received: by mail-pg1-x52d.google.com with SMTP id bh13so2501996pgb.4 for ; Mon, 04 Jul 2022 02:34:45 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id z5-20020aa79e45000000b00525b7f3e906sm15353355pfq.27.2022.07.04.02.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 02:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PPqUahiWt2M7Eg8LZ9lJoQvj046orfAZ2qStTlP4KlU=; b=SNJ9yR7wXI0SCMwatGbuW+9FViL3qfuFIcOlajfZJRnR1DJgCFECPJhezGtO4Fx38a L0gqZNbNG+2jjmrUtUJAOLn5dzQX3NpP5FKJERrfc9znWANV+n/fCirUDDA4MjKibxmN 2n/Ao/WGowEoutFeAgw96cFrIVDIA42LdUKk9m9SujuLS9gSIvO4yGUIxZLwX5TEjba2 Gq0x6UQblTB2//s6DSPWlhZmOIhn6oYrgd1X/ttH9PH+M6ARYFzpd4n/2vFX7kXo8TrW rDZpjqfo2CAKbliSoDWcXpQP8v4I/jHklFjDVXFuvs3hx+/W8zR+MR1WUnJCZm00Goj4 W6yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PPqUahiWt2M7Eg8LZ9lJoQvj046orfAZ2qStTlP4KlU=; b=4sDpzlFp98GbHZT8e6vWdepPE2sqBZcQ8qHKOCu9u75XY2wLMC0SiPdhb6Gxfr0bpJ 0MbCx9bLVBUmlvH5WIE+VRSgAgFGsnDPrA3mfvBG8qOBzblVFtLPa0cTzBW+VOrDUMpP lE92KwH4gH9pLgtKFXwmwgkzIH1BJ60FKcX3v4AXtNMeCN9013Rv7Vq276BKE1QKwjp+ TVcdKSYkkA6yvIx0o6lzHuXlGuKh8XXp0AQ90gia42K3OxrDe0eIrRNAYLkjv2xpCmM5 lcNC5eJfJ1lxY64easymDRcEaer4XtgxLWhVkU/w5N9WqITkn6QoJOG9TwXCqBNfHeKM 7BWg== X-Gm-Message-State: AJIora83X4suBHOFPUNxFDS4l+JA4/M1jvETBX18voG4Nsiss4CUSP8o 6XzpnI1u0YRPgcVdJo9q9RD/J2k34JNbWvM9 X-Google-Smtp-Source: AGRyM1vjkRFT1T46lELtVIC+32LcUFzWjoGzyVtOZjJvvWia1pRCzwkSUKN+OWCFQoobIUxMQtSYLw== X-Received: by 2002:a63:90c7:0:b0:40d:3c0d:33f4 with SMTP id a190-20020a6390c7000000b0040d3c0d33f4mr24329021pge.334.1656927284947; Mon, 04 Jul 2022 02:34:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Xiaojuan Yang Subject: [PULL 15/23] hw/rtc/ls7a_rtc: Fix uninitialied bugs and toymatch writing function Date: Mon, 4 Jul 2022 15:03:49 +0530 Message-Id: <20220704093357.983255-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220704093357.983255-1-richard.henderson@linaro.org> References: <20220704093357.983255-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1656928220225100001 Content-Type: text/plain; charset="utf-8" From: Xiaojuan Yang 1. Initialize the tm struct in toymatch_write() and ls7a_toy_start() to fix uninitialized bugs. 2. Fix toymatch_val_to_time function. By the document, when we calculate the expiration year, we should first get current year, and replace the 0-5 bits with toymatch's 26-31 bits. Fixes: Coverity CID 1489766, 1489763 Signed-off-by: Xiaojuan Yang Reviewed-by: Richard Henderson Message-Id: <20220701093407.2150607-2-yangxiaojuan@loongson.cn> Signed-off-by: Richard Henderson --- hw/rtc/ls7a_rtc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/rtc/ls7a_rtc.c b/hw/rtc/ls7a_rtc.c index fe6710310f..b88a90de8b 100644 --- a/hw/rtc/ls7a_rtc.c +++ b/hw/rtc/ls7a_rtc.c @@ -148,8 +148,9 @@ static inline uint64_t toy_time_to_val_year(struct tm t= m) return year; } =20 -static inline void toymatch_val_to_time(uint64_t val, struct tm *tm) +static inline void toymatch_val_to_time(LS7ARtcState *s, uint64_t val, str= uct tm *tm) { + qemu_get_timedate(tm, s->offset_toy); tm->tm_sec =3D FIELD_EX32(val, TOY_MATCH, SEC); tm->tm_min =3D FIELD_EX32(val, TOY_MATCH, MIN); tm->tm_hour =3D FIELD_EX32(val, TOY_MATCH, HOUR); @@ -158,17 +159,18 @@ static inline void toymatch_val_to_time(uint64_t val,= struct tm *tm) tm->tm_year +=3D (FIELD_EX32(val, TOY_MATCH, YEAR) - (tm->tm_year & 0x= 3f)); } =20 -static void toymatch_write(LS7ARtcState *s, struct tm *tm, uint64_t val, i= nt num) +static void toymatch_write(LS7ARtcState *s, uint64_t val, int num) { int64_t now, expire_time; + struct tm tm =3D {}; =20 /* it do not support write when toy disabled */ if (toy_enabled(s)) { s->toymatch[num] =3D val; /* caculate expire time */ now =3D qemu_clock_get_ms(rtc_clock); - toymatch_val_to_time(val, tm); - expire_time =3D now + (qemu_timedate_diff(tm) - s->offset_toy) * 1= 000; + toymatch_val_to_time(s, val, &tm); + expire_time =3D now + (qemu_timedate_diff(&tm) - s->offset_toy) * = 1000; timer_mod(s->toy_timer[num], expire_time); } } @@ -223,7 +225,7 @@ static void ls7a_toy_start(LS7ARtcState *s) { int i; uint64_t expire_time, now; - struct tm tm; + struct tm tm =3D {}; /* * need to recaculate toy offset * and expire time when enable it. @@ -236,7 +238,7 @@ static void ls7a_toy_start(LS7ARtcState *s) =20 /* recaculate expire time and enable timer */ for (i =3D 0; i < TIMER_NUMS; i++) { - toymatch_val_to_time(s->toymatch[i], &tm); + toymatch_val_to_time(s, s->toymatch[i], &tm); expire_time =3D now + (qemu_timedate_diff(&tm) - s->offset_toy) * = 1000; timer_mod(s->toy_timer[i], expire_time); } @@ -352,13 +354,13 @@ static void ls7a_rtc_write(void *opaque, hwaddr addr, } break; case SYS_TOYMATCH0: - toymatch_write(s, &tm, val, 0); + toymatch_write(s, val, 0); break; case SYS_TOYMATCH1: - toymatch_write(s, &tm, val, 1); + toymatch_write(s, val, 1); break; case SYS_TOYMATCH2: - toymatch_write(s, &tm, val, 2); + toymatch_write(s, val, 2); break; case SYS_RTCCTRL: /* get old ctrl */ --=20 2.34.1