From patchwork Thu Oct 19 13:35:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 735572 Delivered-To: patch@linaro.org Received: by 2002:adf:f0cd:0:b0:32d:baff:b0ca with SMTP id x13csp1519990wro; Thu, 19 Oct 2023 06:37:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWUD06bIgh3LaOvEYsF7s10r8JoQ/MOSHm323JqQp6jKMQFNwovxaUv1KVHp+TSBan7gvU X-Received: by 2002:a25:5386:0:b0:d15:7402:f7cd with SMTP id h128-20020a255386000000b00d157402f7cdmr1913826ybb.27.1697722659373; Thu, 19 Oct 2023 06:37:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697722659; cv=none; d=google.com; s=arc-20160816; b=TEjFnPgWC1Mdy8bmwvZJ8I/lwkmSrpv2lnc7Oo7ye37U9xnSSToJqMkwRFJWrDH/L4 47GTVmN/LIg/5i+LjMnILm30f6rSTH6GIkx8hYEsWGjU5nEUtPEmwJa7zrwdIp1AyoO8 SWKgX7aAezERj8vnaH4qme99iDHfH6Nzs8u6OC+wGJn9t+rjusgceKrN87usBAIqOg1v acUtm+4t9WAJuxLQYAUOeoIYjVy5UpMChuilGxaYzPTDcdoXw5cgA2JtX2llYZDqQdH9 wKQ7oN4PpxcoSqNKSwHnP+rKyLazHmv7ci38KD4HHXaXmmAQ+ZyQ9+J746QBqiqv3ij4 RGAg== 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=3ZO8XemeV6MKZJes6/JMerENEJvAmmFZYOx50CoERRE=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=kH+j16AdB9nP3+e5K9UnMNOp3dA45iUILNa7uHtttrsiJpe+DoQX6ZwU16GTIJkhFz mepyx0zZpjRrl67w4fkC9XdiA2EzMI21VcmrN6hUDu7SViHPTfhd0mrFrrxNo7FPWLP8 n1oFp9Pdzm3VQ4rh+hC1g1bLivCFbRHzagHp+LEJQ9lHWbRyVq+Uo/rxfzlji5fp17Eb R6ZRCiKVph/0GZQ0yMRrxIzNWagyEtIY1yi8HzzLUEg6KqbRhYcaIV3l6HfBkdGTUR7v FZO3wCz0VRHdfdtvfQtZiiA8NvpnGB29xlZYWbjJgSb+9KgjWi7ussn5duzo7jkI6/jD twag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l9IWPIs6; 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 ei6-20020ad45a06000000b0064c92f86b15si1529686qvb.145.2023.10.19.06.37.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Oct 2023 06:37:39 -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=l9IWPIs6; 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 1qtTCm-0003Y2-Bq; Thu, 19 Oct 2023 09:36:52 -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 1qtTBx-000246-DM for qemu-devel@nongnu.org; Thu, 19 Oct 2023 09:36:03 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtTBt-0001F1-6k for qemu-devel@nongnu.org; Thu, 19 Oct 2023 09:36:01 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-32d9d8284abso5191148f8f.3 for ; Thu, 19 Oct 2023 06:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697722549; x=1698327349; 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=3ZO8XemeV6MKZJes6/JMerENEJvAmmFZYOx50CoERRE=; b=l9IWPIs6XvPiDF938nzefTqci2yWJcHuj8ZlLqFXVID0Uhh9M3ufj17+E7/Iwzd+cq wiWZ7OwKHFhj7So6if4gtxiKTS1TDzWnORMt7G6Xm3hULrTa8MDhNzASw5prC+woKmr/ vQqXrSoOf6oNn4auETZcS9JAQt7d/bijzlygkY/CBgU0MiS1xhaIFC8JPDwZYt5cnBM7 +18pihWOSMugRlSjl1Wu3CsjceTGGwNnaHjvCNgXVnGO1sM29jWbyadPdv0iX77s5bSf 5epPQPLOFU6pwtQFXFI8SJUKLoQR64PLsZBQ/WWP6+WnE6+kSlrbG2HVMth51vjxKdJ+ W1kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697722549; x=1698327349; 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=3ZO8XemeV6MKZJes6/JMerENEJvAmmFZYOx50CoERRE=; b=fLV3nUoimuR0nN16F1Qntv8/92Ij2ZVtGM+R3KVYAQfs6LUAHNs1R8kGvt1iaGP3HL gsP0oVAiOIt5LdxgLl4QVi7Ue7UWW8vrkVT1H+02RAEWPfmnVNugvS2y6A2LQTyp5EQX pvOwBvSj5HZ4d1PmDTuJY0hDGKaL1XKXJHfBEjasbb6wVIM96gfNMATcPE04I12NDxTF 442GEierE/a81QTOLSWaZs/EHvoAu+B5soYZV12MiA2AvOlyrIiCcuWYX+JZoZmaH0Dn QMoATqGaOvtWBlopUo8Bfi0DG83oJsye+SP1iJPDVzhADugPHzK256owf04y1DgAhXrS DQIg== X-Gm-Message-State: AOJu0Yypum+/Ua0EqcDyu6o2fI01/WsShUuPASRXy87Z7mDxWLp7jeOA w0DLla4saEuonqip42Wm2+FobbljDO7H+WrHB2E= X-Received: by 2002:a05:6000:b92:b0:309:1532:8287 with SMTP id dl18-20020a0560000b9200b0030915328287mr1507404wrb.19.1697722549524; Thu, 19 Oct 2023 06:35:49 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d28-20020adf9b9c000000b0031f3ad17b2csm4512690wrc.52.2023.10.19.06.35.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 06:35:49 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 23/24] hw/timer/npcm7xx_timer: Prevent timer from counting down past zero Date: Thu, 19 Oct 2023 14:35:36 +0100 Message-Id: <20231019133537.2114929-24-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019133537.2114929-1-peter.maydell@linaro.org> References: <20231019133537.2114929-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.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 From: Chris Rauer The counter register is only 24-bits and counts down. If the timer is running but the qtimer to reset it hasn't fired off yet, there is a chance the regster read can return an invalid result. Signed-off-by: Chris Rauer Message-id: 20230922181411.2697135-1-crauer@google.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/timer/npcm7xx_timer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c index 32f5e021f85..a8bd93aeb2c 100644 --- a/hw/timer/npcm7xx_timer.c +++ b/hw/timer/npcm7xx_timer.c @@ -138,6 +138,9 @@ static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count) /* Convert a time interval in nanoseconds to a timer cycle count. */ static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns) { + if (ns < 0) { + return 0; + } return clock_ns_to_ticks(t->ctrl->clock, ns) / npcm7xx_tcsr_prescaler(t->tcsr); }