From nobody Mon May 6 22:25:08 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1660831025; cv=none; d=zohomail.com; s=zohoarc; b=Qf4z9yLBGJTVX8p6KAk0c5ohe5pEMEOzEV+ufAP6zpJ9tM5R5EYrRAb2/g8UZEyIfVSmLVxLLePCAmVja0P1N3SSnus3tErq5u7RPjJdJzIUlAGD2FDZGn4vAbO2Gi3QNFclq89uPAgQWk+vXE/UJKMSOJK8gecfTGPpBL9jiz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660831025; h=Content-Transfer-Encoding:Cc: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=U9xOpGEBZ+FMG/fJxG2GJhXlUWOoFT9u3NruQ6RU9kM=; b=JlnpPvHxgmQWeH2Vg64LDYK8vG/NEEZhBgwHQhkyCTraYOrK8w5JV6cGOKidFi8WJRerFFxk3QBfp7nlfSCgYPFjWzkZVodqLTAGlFaY6wwoNNsj/UZZI6HfbgEgW+57KNCXKsoIgb7i7LabfzsoP6cuMtTxdn4YTjh7svMeN+M= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16608310259401000.6150929536892; Thu, 18 Aug 2022 06:57:05 -0700 (PDT) Received: from localhost ([::1]:47832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOg19-0006f1-DO for importer2@patchew.org; Thu, 18 Aug 2022 09:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOfyg-0004Z5-KC for qemu-devel@nongnu.org; Thu, 18 Aug 2022 09:54:31 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:39518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOfye-0002QJ-MQ for qemu-devel@nongnu.org; Thu, 18 Aug 2022 09:54:29 -0400 Received: by mail-wr1-x431.google.com with SMTP id r16so1826035wrm.6 for ; Thu, 18 Aug 2022 06:54:28 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d24-20020adfa358000000b0021ea1bcc300sm1624410wrb.56.2022.08.18.06.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=U9xOpGEBZ+FMG/fJxG2GJhXlUWOoFT9u3NruQ6RU9kM=; b=NG/Tb9UHXn6YsDmkmMlc/Vl+JejceB1LhuVP8xvxTGmVwiuz9yd+MUb8gaEY5KHlQK 4iDt1NTEBjmFEIWkL7Rlva7JeMU0EFOCIFfgqltkTJWWqj9383KO13iEQ7QcOx+b+CjL S8CEkOKivJ/H6jA6sYch5+uGDAoI3e8oMRrtWUX+ghdCjIX0H0S0Pt0yH+KhDqxXb47E oUZ1Eyfg0DkYM1fs4GpS0PLCW9ucuN0QzhCl3YnVLfhI1bKavkdeixnA9onAEopu5UUb hHVrDHPYHrz/TEIlyTpPUggVoTZicmzeBi0qsQuSWEOno4ltcH6d0uDRI2iYeJMdpNh0 bZ7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=U9xOpGEBZ+FMG/fJxG2GJhXlUWOoFT9u3NruQ6RU9kM=; b=beDo/Ue0Ar1N+cVd6THl0d8XJsIDNpBZigCH6yhFDTz9K0+E4uxhuBLW43q3wXeXyc REnR9sfCHtf4QjGh6RmUoycsMM38Fw0CAlLLgHobwUrDg2RJZiJL2alIl6kAefDbqn0C eO4GnlRVRN55G8wzjhps7kx6u+J4gwb3Op/5v8hX6EVDAGFEaf5qA+Y3wVJ1NPd6/PAa YUzOa0eaTRyGB6DiVF/42TyaSf2BK+iuLPTwvRj2HASsZlIGfBvV1yk56jX3HNn1ZC1Q VAbJxzjh9Rq7CBoASlDeC40La8Rz04dvLegNMoKiNhMuj/S6nNycztwY1HBcC4fRgbd1 bHZA== X-Gm-Message-State: ACgBeo35vCOjrWbkEruB5YPE4nNHBCRSh0UMPZhAn65aRr08WJYOqb5T ukptNhzgBj4/R7PdaiIDpz3tl132YZYn/w== X-Google-Smtp-Source: AA6agR6pr5vci0z/KCu5d30pP2ma7ZLwSWkao5jMOJLwjOiFGfzTIHknXIuaTP79hdOfOtU4CzWO0g== X-Received: by 2002:a05:6000:178e:b0:220:635f:eb13 with SMTP id e14-20020a056000178e00b00220635feb13mr1703032wrg.634.1660830866938; Thu, 18 Aug 2022 06:54:26 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum Subject: [PATCH v2 for-7.2 1/2] pci: Remove unused pci_get_*_by_mask() functions Date: Thu, 18 Aug 2022 14:54:20 +0100 Message-Id: <20220818135421.2515257-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220818135421.2515257-1-peter.maydell@linaro.org> References: <20220818135421.2515257-1-peter.maydell@linaro.org> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1660831027007100001 Content-Type: text/plain; charset="utf-8" The helper functions pci_get_{byte,word,long,quad}_by_mask() were added in 2012 in commit c9f50cea70a1596. In the decade since we have never added a single use of them. The helpers clearly aren't that helpful, so drop them rather than carrying around dead code. Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Reviewed-by: Paolo Bonzini --- include/hw/pci/pci.h | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index b54b6ef88fc..c79144bc5ef 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -692,13 +692,6 @@ pci_set_byte_by_mask(uint8_t *config, uint8_t mask, ui= nt8_t reg) pci_set_byte(config, (~mask & val) | (mask & rval)); } =20 -static inline uint8_t -pci_get_byte_by_mask(uint8_t *config, uint8_t mask) -{ - uint8_t val =3D pci_get_byte(config); - return (val & mask) >> ctz32(mask); -} - static inline void pci_set_word_by_mask(uint8_t *config, uint16_t mask, uint16_t reg) { @@ -707,13 +700,6 @@ pci_set_word_by_mask(uint8_t *config, uint16_t mask, u= int16_t reg) pci_set_word(config, (~mask & val) | (mask & rval)); } =20 -static inline uint16_t -pci_get_word_by_mask(uint8_t *config, uint16_t mask) -{ - uint16_t val =3D pci_get_word(config); - return (val & mask) >> ctz32(mask); -} - static inline void pci_set_long_by_mask(uint8_t *config, uint32_t mask, uint32_t reg) { @@ -722,13 +708,6 @@ pci_set_long_by_mask(uint8_t *config, uint32_t mask, u= int32_t reg) pci_set_long(config, (~mask & val) | (mask & rval)); } =20 -static inline uint32_t -pci_get_long_by_mask(uint8_t *config, uint32_t mask) -{ - uint32_t val =3D pci_get_long(config); - return (val & mask) >> ctz32(mask); -} - static inline void pci_set_quad_by_mask(uint8_t *config, uint64_t mask, uint64_t reg) { @@ -737,13 +716,6 @@ pci_set_quad_by_mask(uint8_t *config, uint64_t mask, u= int64_t reg) pci_set_quad(config, (~mask & val) | (mask & rval)); } =20 -static inline uint64_t -pci_get_quad_by_mask(uint8_t *config, uint64_t mask) -{ - uint64_t val =3D pci_get_quad(config); - return (val & mask) >> ctz32(mask); -} - PCIDevice *pci_new_multifunction(int devfn, bool multifunction, const char *name); PCIDevice *pci_new(int devfn, const char *name); --=20 2.25.1 From nobody Mon May 6 22:25:08 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1660831026; cv=none; d=zohomail.com; s=zohoarc; b=V2veEz1EdfMf8JD0G0XLhP629BrlCqoJRh8/uxBiwio+06l5y0Yz9QQ1fLMTUzlqUsj93ZhLrUMDLCsjBvvXaRXN7TR6+lSmqKa9h4rS7rg37tFMD8TpRwjxeUjcBm5LU5yS4Xf1col7/N3Prl+L35ZlIiecZaGuNLt/2iOWW2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660831026; h=Content-Transfer-Encoding:Cc: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=Ltb+NJhoIgMEPDlZ1x7AyzfdFhnHp9XW9U5V5+U+A1Q=; b=aFsLDXIooJgsOV7DLf2N4vQV2hplmKpwMOZlJ1MEbsYlafwhrxNrqsQ+kFWZsmr3OfRXJQ2qouu5X/93Vvnnl2Rk1WDU3/45D5sZimE4WZmkDavpp8BI/31XM2kbB0HFRbbosYoGqg+45oGyiqIREOFXO4f/F1n9OQbOGm0Fisk= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660831026745891.3291614550607; Thu, 18 Aug 2022 06:57:06 -0700 (PDT) Received: from localhost ([::1]:47836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOg1A-0006iM-S7 for importer2@patchew.org; Thu, 18 Aug 2022 09:57:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOfyi-0004aN-4b for qemu-devel@nongnu.org; Thu, 18 Aug 2022 09:54:32 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:33712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOfyf-0002QM-8G for qemu-devel@nongnu.org; Thu, 18 Aug 2022 09:54:30 -0400 Received: by mail-wr1-x42b.google.com with SMTP id k9so1857513wri.0 for ; Thu, 18 Aug 2022 06:54:28 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d24-20020adfa358000000b0021ea1bcc300sm1624410wrb.56.2022.08.18.06.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 06:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Ltb+NJhoIgMEPDlZ1x7AyzfdFhnHp9XW9U5V5+U+A1Q=; b=JObpoX0Y3Kug0QGnHDZsnKLCMdq/szECSkGMEguMXKw8ZPJyXKJOOe1SG0DKfN8/Os X9WkKt3jyDEP3+C+VOHO2DVA3FgwJO2mw1iZcYPssyiFKWjhwb/8JRgBLmiPW9LQwd4N PThNh+2k/aynqvYbMEBXYNQP6rg/y7Zux55nL/oOt9XoznIMv5+3hUbCIkoSDiyCZP3A fVk22+cJuSxQ7K0w/BS/KK9Sdd3Fm9wnYihoZ80Ul/gIGd75aMdn+mwV/QlkN7tstpqE nffnG4SalbL0Hi77zi8ryef7gieQmR6BlcUlZhn/+r0R6lZl1g2SP+FVScCvcpHBQhbR KeDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Ltb+NJhoIgMEPDlZ1x7AyzfdFhnHp9XW9U5V5+U+A1Q=; b=t7m4jx1pyvaP2gUrEYvUFHwSYPwxvodcLPFXGFHHBbul+KiwyMRzGjMBs8ljn/sLWK ppGlKIiYpY0Q6mkFblQwdjaco/MO4QgwbR2eTapY3SG4LzmJ47h/C17g/BaIBkPrUDYs 8n4Xr0wQgzWADPp/5DFFCxrel7RK5VNy4k9CTX1T2WnGnXWEvoepFTNoBiRlRDLvqnnZ rgJ0w5YMMhed1E3u4gA+NMZCOmEzEazMBWptxbNlyr9q2agWpJKMDiCqm/I8itirPGgB +/5JmEAgrPLg82/HNyeLUPrPvMJbNrFLDHk6m7S6dT6BXgw9elpc/KEz/N9flxo1342e 5tyg== X-Gm-Message-State: ACgBeo2Cp/MyxtA2gpWwN/WlORtbNn3+n0fweGy3d0nPS8En81ortoXh qGJfw3SIRGLdjWX6tMLgoTgja2oF1jejuQ== X-Google-Smtp-Source: AA6agR6gwqCGVH3EkoflvP9l/r4CKqjyW6cFkp2qhlr2GqrUrkiENpwlKGRUSiSKRSSOpzNaoZlPeg== X-Received: by 2002:a5d:5550:0:b0:221:6d3a:1984 with SMTP id g16-20020a5d5550000000b002216d3a1984mr1713716wrw.326.1660830867732; Thu, 18 Aug 2022 06:54:27 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum Subject: [PATCH v2 for-7.2 2/2] pci: Sanity check mask argument to pci_set_*_by_mask() Date: Thu, 18 Aug 2022 14:54:21 +0100 Message-Id: <20220818135421.2515257-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220818135421.2515257-1-peter.maydell@linaro.org> References: <20220818135421.2515257-1-peter.maydell@linaro.org> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1660831027017100002 Content-Type: text/plain; charset="utf-8" Coverity complains that in functions like pci_set_word_by_mask() we might end up shifting by more than 31 bits. This is true, but only if the caller passes in a zero mask. Help Coverity out by asserting that the mask argument is valid. Fixes: CID 1487168 Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Reviewed-by: Paolo Bonzini --- Note that only 1 of these 4 functions is used, and that only in 2 places in the codebase. In both cases the mask argument is a compile-time constant. v1->v2 changes: remove unnecessary masking --- include/hw/pci/pci.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index c79144bc5ef..97937cc9221 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -688,7 +688,10 @@ static inline void pci_set_byte_by_mask(uint8_t *config, uint8_t mask, uint8_t reg) { uint8_t val =3D pci_get_byte(config); - uint8_t rval =3D reg << ctz32(mask); + uint8_t rval; + + assert(mask); + rval =3D reg << ctz32(mask); pci_set_byte(config, (~mask & val) | (mask & rval)); } =20 @@ -696,7 +699,10 @@ static inline void pci_set_word_by_mask(uint8_t *config, uint16_t mask, uint16_t reg) { uint16_t val =3D pci_get_word(config); - uint16_t rval =3D reg << ctz32(mask); + uint16_t rval; + + assert(mask); + rval =3D reg << ctz32(mask); pci_set_word(config, (~mask & val) | (mask & rval)); } =20 @@ -704,7 +710,10 @@ static inline void pci_set_long_by_mask(uint8_t *config, uint32_t mask, uint32_t reg) { uint32_t val =3D pci_get_long(config); - uint32_t rval =3D reg << ctz32(mask); + uint32_t rval; + + assert(mask); + rval =3D reg << ctz32(mask); pci_set_long(config, (~mask & val) | (mask & rval)); } =20 @@ -712,7 +721,10 @@ static inline void pci_set_quad_by_mask(uint8_t *config, uint64_t mask, uint64_t reg) { uint64_t val =3D pci_get_quad(config); - uint64_t rval =3D reg << ctz32(mask); + uint64_t rval; + + assert(mask); + rval =3D reg << ctz32(mask); pci_set_quad(config, (~mask & val) | (mask & rval)); } =20 --=20 2.25.1