From patchwork Thu Aug 31 10:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 718976 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp395648wrn; Thu, 31 Aug 2023 03:49:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE401ll4QumqvIJrpOqzBU71p8czvJVufS7cWNr+RDruwa9ZPuWDkndgtqZYW+pbau3rc0F X-Received: by 2002:ac8:5986:0:b0:412:206b:92e6 with SMTP id e6-20020ac85986000000b00412206b92e6mr2686371qte.16.1693478941939; Thu, 31 Aug 2023 03:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693478941; cv=none; d=google.com; s=arc-20160816; b=Uym1UQBjKGeYZ5owqGXuQlyoD2KNO7h0x+6ObNCwcGQoH1AdoBJCAZJFxhPZCSmXMR nB0xk9lVxAvLapL4qUF+gCfMxJMBJbvBC2fonpoP1lsLEI9FQgXgfLdBTxuSbkRCjpPX pM3vMnWgkAgiZkyTqdlrcEQaJ91/FbvA2BsdSnT4ZdxbphAEQHEa/C/aXFvuOUs2f4Y1 ZWzNDHySKz8CUDg2kC58JXsJxr/mPv4X1G50iZu/t8Pv4YI/vYhfEOpYMGuZkN7UFS2z 4rHu0N73Zqqh8dPutgpAXRKN56Q9ru/GZZwVqHVWUMr8KL2g4bhxsiHKWJHDkN3WOeEg Et+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=+VSlQGCsD1Pcew2GJP5QWEZRyhS81cLxeQnfhrofKf0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=aGb0WSzRuaxRqZ0J9bteuszZe4QbZmfGySjMiIvjP33R0vYDNPWzwOVmKPv99r3hEJ vU28a25hj0a4L2gAKG05xjjlDeSSsK4AvDB8CzgxwrTtiFt4viT9QrglUzzv2lr0TJ7f FrISFWoDGkWpk8z0Ci31YNLEHQ6QAHTjF621aF/t3v9oqZ0DcREWRMnwMXIzlX0qHWVi uu8XtJglK+0Hx7F6XZHXHYlhGsx+Z88Kov6xMufvbfxp4dPuEkO66HP1fK4VWpwB0IW8 BW8N1ouMsdwHZHmBit/VvqmjXcGHGk1eJ+C2n3jgwWM221R/swvtyxHD+1eedrWayHz5 koPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ex4ekol4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v7-20020ac85787000000b0040378f30d44si671177qta.172.2023.08.31.03.49.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2023 03:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ex4ekol4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbfBL-0003rO-1F; Thu, 31 Aug 2023 06:45:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbfBB-0003dh-Cl for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:37 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbfB5-00045D-Cy for qemu-devel@nongnu.org; Thu, 31 Aug 2023 06:45:35 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31dcd553fecso480210f8f.2 for ; Thu, 31 Aug 2023 03:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693478730; x=1694083530; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+VSlQGCsD1Pcew2GJP5QWEZRyhS81cLxeQnfhrofKf0=; b=ex4ekol4H36W4ge9il9DwlbDng9niFS7UMF5V7Zh5NpLS8DI64gOBXrRT5TtJVdydn rszjjThaTA5gg0Kpm5+n2CnkoOoS8A3xX0oAssNOMh0yd++NHEVWIVAtoa9LgmUZcEsB q/GJSHZgCYCZOz7f9rQBWmELMSUL5ElKbBxCGYMjbEgjUL5apQMoMXiBq3PVEf8vRX0B Cev9y7ri91X7vahKvcK9cWLgLNAQnt5lQgzvAOg5M9cHCYnGK9nQTQ2W4hdAcSymK9si 4i0acVL06DpJl5FAnU+kR7l98k/3BR1ufT07CwiVfkowLFRyJHjaTskA0rfOZ/+GmjFq akhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693478730; x=1694083530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+VSlQGCsD1Pcew2GJP5QWEZRyhS81cLxeQnfhrofKf0=; b=jJQKDF+FWBPUm8OZBLAMHXQubpyXZZszgDD9ERslGoGQ0IqGe4tWXUt99eHg1I6t0q f1Ur6rDrTC4t0Rig5WvxwQQyHqZXNE9I1uaj0AvQeWayJuTiMq2GNkSItCC0qQ3GwP8L /P4TX7Ejq6sawHqJ7n4zhw5q7RM78r1hLzSQZ3icffWf4MJZ/7zZ+6cGp17EzjUceIRb jT3hNxhHeg6ERYu5WQ4sxcXAMoHxbLM0E+vTXSfZJxM/xVe1dAF85A3FvNDXbRLu1pPI QqYg1RTMLIocS3SnO5jcXmtzRwRzUpjN+rP/EHTrJLV8xRJYWzi3hhLoRZ0xr5K5+45a 3kPA== X-Gm-Message-State: AOJu0YxUE9m1tbIvrv0G4H4b+fm792I1dnpNINuXSOY8EqQpkfXQc9MR nNGqGg2mRt/uFkth+ZRxluxY8vKARDgwHfILUF8= X-Received: by 2002:a5d:5487:0:b0:319:8a5a:ab5e with SMTP id h7-20020a5d5487000000b003198a5aab5emr3656194wrv.38.1693478729799; Thu, 31 Aug 2023 03:45:29 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l5-20020adfe585000000b0031c71693449sm1785524wrm.1.2023.08.31.03.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 03:45:29 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 21/24] rtc: Use time_t for passing and returning time offsets Date: Thu, 31 Aug 2023 11:45:16 +0100 Message-Id: <20230831104519.3520658-22-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831104519.3520658-1-peter.maydell@linaro.org> References: <20230831104519.3520658-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The functions qemu_get_timedate() and qemu_timedate_diff() take and return a time offset as an integer. Coverity points out that means that when an RTC device implementation holds an offset as a time_t, as the m48t59 does, the time_t will get truncated. (CID 1507157, 1517772). The functions work with time_t internally, so make them use that type in their APIs. Note that this won't help any Y2038 issues where either the device model itself is keeping the offset in a 32-bit integer, or where the hardware under emulation has Y2038 or other rollover problems. If we missed any cases of the former then hopefully Coverity will warn us about them since after this patch we'd be truncating a time_t in assignments from qemu_timedate_diff().) Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- include/sysemu/rtc.h | 4 ++-- softmmu/rtc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/sysemu/rtc.h b/include/sysemu/rtc.h index 159702b45b5..0fc8ad6fdf1 100644 --- a/include/sysemu/rtc.h +++ b/include/sysemu/rtc.h @@ -42,7 +42,7 @@ * The behaviour of the clock whose value this function returns will * depend on the -rtc command line option passed by the user. */ -void qemu_get_timedate(struct tm *tm, int offset); +void qemu_get_timedate(struct tm *tm, time_t offset); /** * qemu_timedate_diff: Return difference between a struct tm and the RTC @@ -53,6 +53,6 @@ void qemu_get_timedate(struct tm *tm, int offset); * a timestamp one hour further ahead than the current RTC time * then this function will return 3600. */ -int qemu_timedate_diff(struct tm *tm); +time_t qemu_timedate_diff(struct tm *tm); #endif diff --git a/softmmu/rtc.c b/softmmu/rtc.c index 4b2bf75dd67..4904581abeb 100644 --- a/softmmu/rtc.c +++ b/softmmu/rtc.c @@ -68,7 +68,7 @@ static time_t qemu_ref_timedate(QEMUClockType clock) return value; } -void qemu_get_timedate(struct tm *tm, int offset) +void qemu_get_timedate(struct tm *tm, time_t offset) { time_t ti = qemu_ref_timedate(rtc_clock); @@ -85,7 +85,7 @@ void qemu_get_timedate(struct tm *tm, int offset) } } -int qemu_timedate_diff(struct tm *tm) +time_t qemu_timedate_diff(struct tm *tm) { time_t seconds;