From patchwork Wed Jul 31 14:36:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 815653 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp773378wrs; Wed, 31 Jul 2024 07:37:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnSLeswz6vnt/vWNfLV2V/uVniUkBzK2sFT2dC2ds1z+kxXbzeFTFByYGYvJwdAsmU+nLi4/FMSglpvDw0E2JJ X-Google-Smtp-Source: AGHT+IEVtLDOfTB8WQlIKKbTDwx8+aNH+Rrxw2ZGWGgIKfw0LL7RPfNXrmM61Zj/WZGsCzkoXvPk X-Received: by 2002:a05:6359:a3a0:b0:1ac:660a:8a69 with SMTP id e5c5f4694b2df-1adc06864d4mr2310039155d.18.1722436674390; Wed, 31 Jul 2024 07:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722436674; cv=none; d=google.com; s=arc-20160816; b=gkfkBntWgUm2np1Odbnl4BlnMjNGzNmSAkNluUNIvMyspe4TIPbnhX8SJqY2gDmbUQ izLlIAaBitQSHertzHhAs2yny/6GysXFfXEC8UDdOaxTv6hG+R2nixr1Glt1L2QfvzhN 6KvcO6nuFM6dkZvkDT154cmY3JAG/ldCYx8JV7F2+rstPLd10INZYXiPsXb3jrlQNrE2 rRyHnBrV0Z8ukppMIA5s+WUQ4dnrzy1MFSmVNTrqI86tmsGZpfCOUYiqjmzOrWosImZ5 myMmoT7gUXtfqaEDCTI4UuSX/iCDFnSzd5VlRb8zahmIJrBb7tfCEpi9+45wWKo9Ca3+ ysdw== 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=MpfLEWhTNYsztTZUist4DkFQWGQUQxtEy7gAUiTdvXo=; fh=5quBhmNe3tsEAdid5ZAgwbHv9gtP/oew6yvM24yBrbo=; b=Xep4JxQy1ayf4Il+MhmAIdc+qa+ZaFCYn9UvgRnzNAykYdGd03BCzELO/HQ2BgLdYm BIQtgY0rSXA3nTpCEorpCwBa9TeviFKruH8AKOsmLBWZ1HY1CqEAiaDm6m1h1MCuunP6 gYP5vvlHBydtokt3/jzxlbCu+CHOouWpOpNwv093Ey97CaWILi/lBZYaXW0GhxzdBZDu zxAC5II6NVaSqdmyi3uHN2lEuqHXQGsCuO6Bwa5EayZ7edZbbHp0Eec1J35ex0bcIOQu XZJG56mBBzFUVFugR197kG5M5AsbHkYjk4MPFj4YFevFDWqlLVBXwn6P68DrETreFv4y zj9A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tq8FVuIZ; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6bb3f8ce212si157141266d6.119.2024.07.31.07.37.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2024 07:37:54 -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=Tq8FVuIZ; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZARQ-0004vG-22; Wed, 31 Jul 2024 10:36:36 -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 1sZARH-0004VG-Ud for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:29 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZARD-0002e8-NZ for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:25 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42816ca797fso33324295e9.2 for ; Wed, 31 Jul 2024 07:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722436581; x=1723041381; darn=nongnu.org; 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=MpfLEWhTNYsztTZUist4DkFQWGQUQxtEy7gAUiTdvXo=; b=Tq8FVuIZ4oEFqI6nBMVac+SJqystRDayQkDffmTxCqMlFGiatTFPaELmt4nbFhQgkI RHjYpIwECfIraswX7shyLQUNUkM49Ww/25ZZwzZjP3LJXWKYbUjDWbohFXjYHhdeBjPL jVLUUWPzUovcduuHDCr9rDk6Pij9ZfTCMHjqxtjJzIuYxCNxBXYfM+If+RbSsZVM6UOX R365xh+siLs0DE24jPRd+RdM4TqgjqcKCJqX4x6uHgklcqiX/oHqEHWv0s83zQlrv2Fi ntaT9tI7paUVCTDB2r756TDtQIaS3wjrxfziEZrVqtbYDhS7iJ4qgJT1z3O/e7GG31LN AT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722436581; x=1723041381; 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=MpfLEWhTNYsztTZUist4DkFQWGQUQxtEy7gAUiTdvXo=; b=YOOZ0O9U+0FJcotaER5DTrPcYW+kj99Z5H4JdGZ3wIBjDtSce5JR7MKqvfnr/u7LuC pANtvpqvQlj2sxkYqCWizX9i4ZUv8gjnhW11OsfGFZZu1PRgQy9qt/IfNWS/kGjFAhlA DHYhDNS1fvG0zIIfjAT2jNBSSZOdpKhJ6GB1mzkYrJOqz9ujqcMhA5ZYRdoAUkmRdl9+ y1bJpAdCE7DkQiiRwVWw9QDe0WKeCF1Fix8+BErVGsDUqxYh/iMk/NrINl/UlpZzVu+f aEnJNfMV93TCWfISD8ZTQocBB8ixejbvL8JpwKdFwxM7r9GAxcDjkBJfOTeVGLwBXI1G rVTw== X-Gm-Message-State: AOJu0Yyt7Iy1Na9KMYDt3eslY9IYVFnH0MAPjaJJNYkTpcVOyIsvvTj6 kcATexxHL5lmM74pH/s0ANIOwZYOZGKyaxaZTYV6DznRgz2KaoXt4US8bZbzfsbVNThbvZP6WWf G X-Received: by 2002:a05:600c:1392:b0:426:5d37:67f0 with SMTP id 5b1f17b1804b1-42811d8cc95mr101315565e9.13.1722436580664; Wed, 31 Jul 2024 07:36:20 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4282b89a86dsm23976025e9.1.2024.07.31.07.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 07:36:20 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , John Snow , Stefan Weil , "Richard W.M. Jones" , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org Subject: [PATCH 3/7] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0 Date: Wed, 31 Jul 2024 15:36:13 +0100 Message-Id: <20240731143617.3391947-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731143617.3391947-1-peter.maydell@linaro.org> References: <20240731143617.3391947-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.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=unavailable 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 In pflash_write() Coverity points out that we can decrement the unsigned pfl->counter below zero, which makes it wrap around. In fact this is harmless, because if pfl->counter is 0 at this point we also increment pfl->wcycle to 3, and the wcycle == 3 handling doesn't look at counter; the only way back into code which looks at the counter value is via wcycle == 1, which will reinitialize the counter. But it's arguably a little clearer to break early in the "counter == 0" if(), to avoid the decrement-below-zero. Resolves: Coverity CID 1547611 Signed-off-by: Peter Maydell Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daudé --- hw/block/pflash_cfi01.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index c8f1cf5a872..2f3d1dd509c 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -614,6 +614,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset, if (!pfl->counter) { trace_pflash_write(pfl->name, "block write finished"); pfl->wcycle++; + break; } pfl->counter--;