From nobody Thu Dec 18 22:26:29 2025 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1602167256; cv=none; d=zohomail.com; s=zohoarc; b=Qzd3Z4ih2LRnbMRDT7OV3zKOANgLeowukO+8n54mT6bGV24HNwsv1WG7/9zC8edLa5wZYO7ulMyfunoxWYJstt96liVlX2kiTQ/JkOyhnnQKIuiFLBKXlD5DwtRPmVKWcJkeHeVK7SyPmezgc0rvJiep0CQBjZ+6HJvGMtqMUWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602167256; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9RUnT5Ix7DudVKkch5jxVyO4juXX54tuStniLRWABm0=; b=RPf33Ow35KOIMFHN/mwfX8Cw9Kl9NSnaRXi6zv8FEBsDCmlJUT1DZD/3bao4Owdpk4bxIYjpS539A/Q2463dxvuhj02kr+FpfGuB5xMnoplkmtP2lAsAwNPM3UNLwlXwyR2gs95Uqrv5nU79bKgivBGmeAM62FnXsJlyGence7s= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602167256499663.6714226703166; Thu, 8 Oct 2020 07:27:36 -0700 (PDT) Received: from localhost ([::1]:45136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQWtL-0005oS-7G for importer@patchew.org; Thu, 08 Oct 2020 10:27:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQWrv-0004BD-EH for qemu-devel@nongnu.org; Thu, 08 Oct 2020 10:26:07 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:46614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQWrr-0005y1-Kr for qemu-devel@nongnu.org; Thu, 08 Oct 2020 10:26:07 -0400 Received: by mail-wr1-x432.google.com with SMTP id n6so6546895wrm.13 for ; Thu, 08 Oct 2020 07:26:02 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id j1sm7905104wrc.28.2020.10.08.07.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 07:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9RUnT5Ix7DudVKkch5jxVyO4juXX54tuStniLRWABm0=; b=Vnna0l4au39C+KvMxRPK6rYHXMji8mnakh9bnZWGE5Ce4dhdphB4j+8LiPvAq9PuaN M+SuZ6+7hI3gZiyh3g6ro13Dh5nfZwfzXS0ITuSOtPVqPdFeX3NKsIKiC8DPk5Sjezmb /M25SHHuuppu64cqee08V7BzpFWj7d9jZAJuSgGAe5YP53T3oLR8iJDQnHrZQ+boEKJN Uvjahmmaf476lOCFzkQAqQxSt3ot0ql2XyEp1Fm+3wrHOU1kazLWiY2/oxUzuZ/Legj2 rr954683SC+Oga7vMxx3d6RRG1KKkiwNChtWVJoHkrUuuzNSDi1cWK//4TIj0BCNl7op XQGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9RUnT5Ix7DudVKkch5jxVyO4juXX54tuStniLRWABm0=; b=Puie3PJCGqtNBSibT+rxuNwAz8lUknL06d6MxL73pKjH2j+mNozOdegECuPMV3SaFZ ShBmPqnEjg8n1YR5kL5UCmvvqZzadXpdQaDgdg+3d83YTaWBqgh2QfZlU+OrmnSb60eI sx8BeM/2II0CJhM2gcS6fKpQlS49yqQOMe1AsBqyq7aQa6Jp5zRylXEFC36MTQfvBYSw 724oawwBg67ExEaKtM28I/OwOTEBbQr2X2ryrUpglOsvlHQwbHAiTGkfppQl+pSb3S2B FZNXNBQ85aYCYNJ1Aw7k2DOMr6uygT3w77DJ2AEsfRvbADlJX05PFCWaTpfuiXIMo++w 4vag== X-Gm-Message-State: AOAM530rdq3kStnfdlkLTIWAW0vErgBZmfStVy0rTj1Cmwmtzlt+WL6M YpWnURHU/ZdQGg3t4ELk3fofLERRqdJs8ycp X-Google-Smtp-Source: ABdhPJyl6SrHluJmalYx4QMGHgUqjX9qAApH/jWThyls+ErkEluXi8cqAhjSbz8wYHXn82M/qXQxNA== X-Received: by 2002:adf:e445:: with SMTP id t5mr9271764wrm.387.1602167161584; Thu, 08 Oct 2020 07:26:01 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 01/12] hw/ssi/npcm7xx_fiu: Fix handling of unsigned integer Date: Thu, 8 Oct 2020 15:25:46 +0100 Message-Id: <20201008142557.9845-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201008142557.9845-1-peter.maydell@linaro.org> References: <20201008142557.9845-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 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" X-ZohoMail-DKIM: pass (identity @linaro.org) From: Philippe Mathieu-Daud=C3=A9 Fix integer handling issues handling issue reported by Coverity: hw/ssi/npcm7xx_fiu.c: 162 in npcm7xx_fiu_flash_read() >>> CID 1432730: Integer handling issues (NEGATIVE_RETURNS) >>> "npcm7xx_fiu_cs_index(fiu, f)" is passed to a parameter that cann= ot be negative. 162 npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f)); hw/ssi/npcm7xx_fiu.c: 221 in npcm7xx_fiu_flash_write() 218 cs_id =3D npcm7xx_fiu_cs_index(fiu, f); 219 trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs= _id, addr, 220 size, v); >>> CID 1432729: Integer handling issues (NEGATIVE_RETURNS) >>> "cs_id" is passed to a parameter that cannot be negative. 221 npcm7xx_fiu_select(fiu, cs_id); Since the index of the flash can not be negative, return an unsigned type. Reported-by: Coverity (CID 1432729 & 1432730: NEGATIVE_RETURNS) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Havard Skinnemoen Message-id: 20200919132435.310527-1-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/ssi/npcm7xx_fiu.c | 12 ++++++------ hw/ssi/trace-events | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c index 104e8f2b963..5040132b074 100644 --- a/hw/ssi/npcm7xx_fiu.c +++ b/hw/ssi/npcm7xx_fiu.c @@ -103,7 +103,8 @@ enum NPCM7xxFIURegister { * Returns the index of flash in the fiu->flash array. This corresponds to= the * chip select ID of the flash. */ -static int npcm7xx_fiu_cs_index(NPCM7xxFIUState *fiu, NPCM7xxFIUFlash *fla= sh) +static unsigned npcm7xx_fiu_cs_index(NPCM7xxFIUState *fiu, + NPCM7xxFIUFlash *flash) { int index =3D flash - fiu->flash; =20 @@ -113,20 +114,19 @@ static int npcm7xx_fiu_cs_index(NPCM7xxFIUState *fiu,= NPCM7xxFIUFlash *flash) } =20 /* Assert the chip select specified in the UMA Control/Status Register. */ -static void npcm7xx_fiu_select(NPCM7xxFIUState *s, int cs_id) +static void npcm7xx_fiu_select(NPCM7xxFIUState *s, unsigned cs_id) { trace_npcm7xx_fiu_select(DEVICE(s)->canonical_path, cs_id); =20 if (cs_id < s->cs_count) { qemu_irq_lower(s->cs_lines[cs_id]); + s->active_cs =3D cs_id; } else { qemu_log_mask(LOG_GUEST_ERROR, "%s: UMA to CS%d; this module has only %d chip selec= ts", DEVICE(s)->canonical_path, cs_id, s->cs_count); - cs_id =3D -1; + s->active_cs =3D -1; } - - s->active_cs =3D cs_id; } =20 /* Deassert the currently active chip select. */ @@ -206,7 +206,7 @@ static void npcm7xx_fiu_flash_write(void *opaque, hwadd= r addr, uint64_t v, NPCM7xxFIUFlash *f =3D opaque; NPCM7xxFIUState *fiu =3D f->fiu; uint32_t dwr_cfg; - int cs_id; + unsigned cs_id; int i; =20 if (fiu->active_cs !=3D -1) { diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events index 2f83ef833fb..612d3d6087a 100644 --- a/hw/ssi/trace-events +++ b/hw/ssi/trace-events @@ -19,4 +19,4 @@ npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect= CS%d" npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s of= fset: 0x%04" PRIx64 " value: 0x%08" PRIx32 npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s o= ffset: 0x%04" PRIx64 " value: 0x%08" PRIx32 npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int= size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%"= PRIx64 -npcm7xx_fiu_flash_write(const char *id, int cs, uint64_t addr, unsigned in= t size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%= " PRIx64 +npcm7xx_fiu_flash_write(const char *id, unsigned cs, uint64_t addr, unsign= ed int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value= : 0x%" PRIx64 --=20 2.20.1