From nobody Fri May 17 07:47:05 2024 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=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1695406530; cv=none; d=zohomail.com; s=zohoarc; b=JUp6RwH4/d1RqXNdYW1iCUb29v9S+gyxfimtN8nI3U/x3ubUBCJnTUmoO5l7MtrQK8rLJJoRD2JLWf4W8kpDhMxxfUNK4XRaDXv+QSyfjYp3u1Rg1DoCpWXq+XmQ1bKwYs4Leh9QMPG0/+jemMs3o2I9QhO4gt7LAba40bXrPQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695406530; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=CpxQY1zQQfP+B92PZ/Ew3AvAau2WsZR51iMdTH0L4fk=; b=Ew03ie/VAACFoIcE5dtEggSPN9vHDnvHWQ/qtdDEerJd4RCESVYOlo4zUv5QvcKcaKJ+Z5inOVMKwTrblyEHJ09dXk09IdCJ5U6q0BGB6c3zwEZtfefP4KyQQI6tVLqU8MFag7CPoVU5ryithJhEXMbUFYfc96KFhD2YiKzMZp4= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695406530989733.4422286097378; Fri, 22 Sep 2023 11:15:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjkg5-0000Ii-3C; Fri, 22 Sep 2023 14:14:59 -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 <3ldkNZQYKCq4QfOiSfUccUZS.QcaeSai-RSjSZbcbUbi.cfU@flex--crauer.bounces.google.com>) id 1qjkfx-0000Dc-Sz for qemu-devel@nongnu.org; Fri, 22 Sep 2023 14:14:50 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ldkNZQYKCq4QfOiSfUccUZS.QcaeSai-RSjSZbcbUbi.cfU@flex--crauer.bounces.google.com>) id 1qjkfw-0007bo-E7 for qemu-devel@nongnu.org; Fri, 22 Sep 2023 14:14:49 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-cf4cb742715so3310083276.2 for ; Fri, 22 Sep 2023 11:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695406486; x=1696011286; darn=nongnu.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=CpxQY1zQQfP+B92PZ/Ew3AvAau2WsZR51iMdTH0L4fk=; b=2ldPONTtwhGtutIlpzBe8CCc80zI0cHwiJAkDtCsVnKxQNxKX/h4XFk0ZGpd5gscYS VDNxdBlauseGCXlc6XYjMBLusSaL4FcRvIHX/uIuofA5WEDR1rmT4iYhpO5P0lXVB+yp nIquUpCpmfAw1aHx4KsaNYFyiVG20VjDdVHiagB0tuWbc8eaGU6Nt7w/soQwn9qGSFXI vqEC2nLYElGch8LmZYA6zk6tCw3j4FwmER2I+R1Lm+VrzdCFyWj5is4C0mUXUP7dfCEb zggixbGDM0z/W1zTYX3S4JvrJyQCjFU9Nq9aNmNsp3EYv8/PNkg0gtWlPQ3sizE1vRdn cGAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695406486; x=1696011286; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CpxQY1zQQfP+B92PZ/Ew3AvAau2WsZR51iMdTH0L4fk=; b=Ky7CzzEDQWuuWmfA2LsOyJw4o+XHYjxsXdjFOZaIHjGFrnFNmwM//XsPilcBZ7iDDN msOKFRu+jomYnsVC9L8LjQzGx75Ne0TKY/O0ajcXh2bPp+WIEq7e5sDdL0AJK0o54Cip TYZtAu/x55KOB2u9Vu17cSUApIzyvBa1WLF8WDvcC1iYDQFZWVg2LUPye9i3VXQRdDHM fV0hxXJnyBWmzUZPCdBWkJfwueXmSCkZPlicf98QaTpmiXgOTwu3g2eXCUvZlRvd0wBl Ol8EvydchB8EGDoHYUv4k96c9RNcYZ2W35kjPHiFAt7CzqXsZEAfpO1HzkvL34RTzwa9 Hnjw== X-Gm-Message-State: AOJu0YxqkiEaXzdvW8TIywYqPh1tuusN2l+PAVNeV1pbXJosQUPCsKx0 dujUJf2y3C7FRRtAHo7aK8IbvjoNaqY= X-Google-Smtp-Source: AGHT+IEoc0swtCAp5VaPafolrfaOn4V07hJMimSsipP+2/xbdXVJ7vVauQoZbsLrA6mvoXp/xW4QL/SHSO8= X-Received: from crauer-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:100f]) (user=crauer job=sendgmr) by 2002:a05:6902:1689:b0:d7b:9902:fb3d with SMTP id bx9-20020a056902168900b00d7b9902fb3dmr1469ybb.0.1695406485945; Fri, 22 Sep 2023 11:14:45 -0700 (PDT) Date: Fri, 22 Sep 2023 18:14:11 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230922181411.2697135-1-crauer@google.com> Subject: [PATCH] hw/timer/npcm7xx_timer: Prevent timer from counting down past zero From: Chris Rauer To: peter.maydell@linaro.org, kfting@nuvoton.com, wuhaotsh@google.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Chris Rauer 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::b49; envelope-from=3ldkNZQYKCq4QfOiSfUccUZS.QcaeSai-RSjSZbcbUbi.cfU@flex--crauer.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, 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, USER_IN_DEF_DKIM_WL=-7.5 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1695406532381100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 32f5e021f8..a8bd93aeb2 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); } --=20 2.42.0.515.g380fc7ccd1-goog