From patchwork Thu Jul 20 15:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 704586 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:365:b0:317:2194:b2bc with SMTP id f5csp573013wrf; Thu, 20 Jul 2023 09:03:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+03rSlV03UNHTT4RADAYft+PaAD/bzFdqU2C7Q9FudaDRfkEt6odAQCgOB8SbgvNovZNr X-Received: by 2002:a05:620a:2801:b0:75b:23a1:362e with SMTP id f1-20020a05620a280100b0075b23a1362emr31283860qkp.63.1689869008479; Thu, 20 Jul 2023 09:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689869008; cv=none; d=google.com; s=arc-20160816; b=xfHU+UmuVbUQzxI7CIskHhKkRWKUSU53M4i/3qlAFVel67U8OFPNRpdNq78GUjuwTW 4Hstg2rG/OYbXrmFJx/vW8B4DMCqSuMWWg3o7esjV8r2Z5CDruX+67ECEVi0875hyYd6 6WWbBMPSekHcCyfxTuSVyM3B9/rIB+ymAffMOAoF++AsQBSuMQAmrXb0CcStWWi6reiD b7wb+vmxRozGimHVOj8QEefiwaUdiQ2IIAeVWuRzwNZqL1pBYCnsuKvD5S4VYMqhgZom UBuocY/BBHP2XxoKUte5Er4dm22H94P5sRKFA+nbA3u/2I06W/+6ALJ+h7Hg744ILcVw FbCA== 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:cc:to :from:dkim-signature; bh=RqoBrwb3O6xPxonYvG2KesZmPgQJqZE5ArjMIGo47jo=; fh=lIqbxpHEzubfCCroXY/oPi4oahgr2te52JU7bS9LUSs=; b=taEZPLacPaqskHvnVEetPWdI49zoDHLd0me9fdiVI+z6LHHV3GIN0ghzTh53JztOI2 OprbvR8lG9Ivv1S9aLxUyci9HpxLhA/us9S6SzvwSDLJRCH9biEtRTfQi9e8FlKeQ3NU xH/p6+6niRn9XQuBLZwNQR0bRCtsbvQ4yM94Jl50Gb/8vQYTM7sm48On4awtk+QRCPa8 pDnVb/PE0DZgTfOObgyJ1xZ2VKEABfK/tNqkY2Pf85fNreBV/7i3eykmHaPy2YpxMgo4 ZgySStEXthb6HUK0OBgvp/Nua6aT6KFl8iJTmG2RNBYARC2g77lJD1bxF41e9+KOrIoT FibQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bRFrMk2s; 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 qr9-20020a05620a390900b00768436e7942si396277qkn.433.2023.07.20.09.03.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jul 2023 09:03:28 -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=bRFrMk2s; 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 1qMW3t-0000ZJ-NQ; Thu, 20 Jul 2023 11:59:29 -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 1qMW3i-0000Xh-C4 for qemu-devel@nongnu.org; Thu, 20 Jul 2023 11:59:25 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qMW3X-00054Z-Db for qemu-devel@nongnu.org; Thu, 20 Jul 2023 11:59:08 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f9fdb0ef35so1560254e87.0 for ; Thu, 20 Jul 2023 08:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689868746; x=1690473546; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RqoBrwb3O6xPxonYvG2KesZmPgQJqZE5ArjMIGo47jo=; b=bRFrMk2s1BnbFjrIcdW9Hd8QMDfK3AsqTdGpbkKZIUI8Wt5bboegGBH+XCE6hjQJkL MzhlYp48EjCxrA761wwJNMzeXOEHuZpKLJpYXlK/tyZdtnOIBjNIi7Rk1aUsrl8opS6v wNkJPHJWE13RRlIe8PPbY6XZl44unntey3lViRKNj6hhWGDIugeOG1WBDNBSgkElnt3f Qkj+7t3vuUp/QtmT0P8tXEqMHTA4CSw78UfmpvcxOuXlapZHmTrV1tayjeIvl3bPSYOB 7YS9SzYpW6yFes9QRGnZcTeI7aNur6btW9e74/LhJItBodALLwBvXQmF237s/mfrVDOw uGWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689868746; x=1690473546; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqoBrwb3O6xPxonYvG2KesZmPgQJqZE5ArjMIGo47jo=; b=UCyXRFnFntGweezxyFt/2sPTEnX65xQ8sKYptJNIWDAZSoE8A8b+u5Ctd41SeKGfgL tDilPaE3LdckSdKFdc6abJcSQj4SWt+2pq0otKyPyW4VBNzaQqKjeuRnt/Hxv0e9npr9 hS+DgeYpKxTJYlrRg6sSUQM/fhuXtnxHnHpYBH61qu2y9tb7DGLiOEaj0x9ywAc4k+Wn 6TNwdQRxQLzwpX1iBg5oMADkVDb/M5vSJw3gdjjaVc/HFEUH5/NLJRnnc0vNJFWArsyK kXGzSBT9AiyK6HJAgsxtNIOs2nOBu8fSuQQLDP3zzHgPOZrVGl/WYrm6u1Y9o7NkPMp3 07LA== X-Gm-Message-State: ABy/qLYhGBT1rXxuQmpyLAHZu8sJ79LHpz1YLC0U3e1mnMpVk+e9HozE YcbT9NyuWOUg+1sAaC+5it/5I3JdRlOIXR41/i0= X-Received: by 2002:a05:6512:1115:b0:4fa:f79f:85a with SMTP id l21-20020a056512111500b004faf79f085amr2124742lfg.69.1689868745881; Thu, 20 Jul 2023 08:59:05 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z5-20020a05600c220500b003fc02a410d0sm4187572wml.48.2023.07.20.08.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 08:59:05 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , Andrew Jeffery , Joel Stanley , Paolo Bonzini , =?utf-8?q?Herv=C3=A9_Poussineau?= Subject: [PATCH for-8.2 4/4] rtc: Use time_t for passing and returning time offsets Date: Thu, 20 Jul 2023 16:59:02 +0100 Message-Id: <20230720155902.1590362-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230720155902.1590362-1-peter.maydell@linaro.org> References: <20230720155902.1590362-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12c; envelope-from=peter.maydell@linaro.org; helo=mail-lf1-x12c.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+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;