[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/28] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0
|
From: |
Philippe Mathieu-Daudé |
|
Subject: |
[PULL 18/28] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0 |
|
Date: |
Tue, 6 Aug 2024 14:51:46 +0200 |
From: Peter Maydell <peter.maydell@linaro.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 <peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20240731143617.3391947-4-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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 c8f1cf5a87..2f3d1dd509 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--;
--
2.45.2
- [PULL 09/28] hw/intc/loongson_ipi: Add LoongsonIPICommonClass::cpu_by_arch_id handler, (continued)
- [PULL 09/28] hw/intc/loongson_ipi: Add LoongsonIPICommonClass::cpu_by_arch_id handler, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 11/28] hw/intc/loongson_ipi: Move common code to loongson_ipi_common.c, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 10/28] hw/intc/loongson_ipi: Expose loongson_ipi_core_read/write helpers, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 12/28] hw/intc/loongarch_ipi: Add loongarch IPI support, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 13/28] hw/loongarch/virt: Replace Loongson IPI with LoongArch IPI, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 14/28] hw/intc/loongson_ipi: Restrict to MIPS, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 15/28] hw/sd/sdcard: Explicit dummy byte value, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 16/28] hw/sd/sdcard: Do not abort when reading DAT lines on invalid cmd state, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 17/28] hw/sd/sdhci: Reset @data_count index on invalid ADMA transfers, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 18/28] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0,
Philippe Mathieu-Daudé <=
- [PULL 19/28] hw/ide/atapi: Be explicit that assigning to s->lcyl truncates, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 20/28] hw/block/fdc-isa: Assert that isa_fdc_get_drive_max_chs() found something, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 23/28] system/vl.c: Expand OpenGL related errors, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 22/28] hw/display/virtio-gpu: Improve "opengl is not available" error message, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 24/28] ui/console: Note in '-display help' that some backends support suboptions, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 21/28] hw/ide/pci: Remove dead code from bmdma_prepare_buf(), Philippe Mathieu-Daudé, 2024/08/06
- [PULL 27/28] docs/specs/pci-ids: Add missing devices, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 25/28] hw/pci-host/gt64120: Set PCI base address register write mask, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 26/28] hw/pci-host/gt64120: Reset config registers during RESET phase, Philippe Mathieu-Daudé, 2024/08/06
- [PULL 28/28] docs/specs/pci-ids: Fix markup, Philippe Mathieu-Daudé, 2024/08/06