From nobody Sun Dec 29 19:14:57 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1720047168; cv=none; d=zohomail.com; s=zohoarc; b=ND0KUum4V3w13NHFeADAWw3LE3ZGWb2EvRimB9VCRTSyBWr2fUG+kLQZaIfj+WDPv6BgmOT9Bj7JxOPxxX7AezdxhLzwjrb1kQR5QB5xxk+1Cd17PMyznNTGcnTre3dBL0BEVRDlnWsoaMeLaDTvtKVBgHfDYBdb2QM4KsoAMJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720047168; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bN0cTm8m+n/A4V5Tgbpm0TUAfWebEt6LcyWQbTcpz4g=; b=UwOZtxxTHLK9s8PstDAwRuDqpD/T7kKWuKyaxMoZpiGGuhurZWTjrrsV7K9Lnrp05ss9VXwlINa2O9MyYFNKa3rHdwhdhMQGmPjDgEAhPZDoGMzWuskHr9uZHncLZiJTs0m9SCZsYaRN4e++8BkDFRMS/JrBxOp9KwgYmfD+xMk= 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 1720047168243452.3013479986205; Wed, 3 Jul 2024 15:52:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sP8oR-00088t-18; Wed, 03 Jul 2024 18:50:55 -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 1sP8oP-0007sn-5J for qemu-devel@nongnu.org; Wed, 03 Jul 2024 18:50:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sP8oN-0007aG-Ao for qemu-devel@nongnu.org; Wed, 03 Jul 2024 18:50:52 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-0aFcczPxOBumtE8voqanJw-1; Wed, 03 Jul 2024 18:50:48 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4257c42f035so31563265e9.3 for ; Wed, 03 Jul 2024 15:50:48 -0700 (PDT) Received: from redhat.com ([2a0d:6fc7:441:91a8:a47d:5a9:c02f:92f2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd634sm17094726f8f.9.2024.07.03.15.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 15:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720047049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bN0cTm8m+n/A4V5Tgbpm0TUAfWebEt6LcyWQbTcpz4g=; b=Eui+RqHgA0+BA8StBatp5vu1upqwU4ECUHdd1Y+hSk0AKYvga7GeSdkB4cYKKKOvxgxOLo R+5ZVnP6dUvYEHyEXJ8nvw1bhamFteiv2VAzxqw1t4pOcmsZNG8SHbhcJR952MOG0woVM0 rym91oxT+yyy/KaRN5RbSn5RPr8b4s4= X-MC-Unique: 0aFcczPxOBumtE8voqanJw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720047046; x=1720651846; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bN0cTm8m+n/A4V5Tgbpm0TUAfWebEt6LcyWQbTcpz4g=; b=YmxK1ChFTWiZXaSzcUKdkOQznq7LXh5San4VZpGKqakM4fs+Td2wPbCoEUSOL7crJW BM0916w4huw2OHlxk4WryQwS3UD11GRG3W3B8V8aQBh/sc7BjY58a7KBmA+2LDn5A4Vw wiSUfoUvmgiLX5cG3cr0run7x8j7R96PE2tRYoaFmo04sIbtLl9eREZcCB9a7Zsup9/e TbY6ZxYleb9lC46fWj46Z9AkzJ7XsZtgl8cZQlLMLCcuqhAK612yM2YJz4x/iN7SM1MI MZrG42OmIWK376ixGWrAbErxHPH9Wpp9AfJyjNcWUh9CjdMFdtOQ04b5JrzreQoF6g4x ArlA== X-Gm-Message-State: AOJu0YzW0AcIws4VBr5B1wB3UiY+YvNdQp6Qb9IQ1BoyRWsYOMgPK3kp EhintXVLgO62M3FMXnhbiyRoJ6hk+/wHReU502AF4JHg4VMb6ukhM1hz2Cn/rmVfIajr39zw4iJ IeuXtDLSvcEkaO+5Z0r/O9rnKFZPCfdMMCI6PZmShGaN6OA9RNLlKuKjm38DAYy+LMwRHMO+3Tf 6L2aBmXOOk4v7KPNlbZ7MSdJNA0pYYtA== X-Received: by 2002:a7b:cd95:0:b0:425:6dce:8c54 with SMTP id 5b1f17b1804b1-4264a48c4e0mr219965e9.33.1720047046520; Wed, 03 Jul 2024 15:50:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOSRByIk9k3rv668VG4ZZgH3goxRYz4rLRrmCDty5VxwTtGnPAQNDI+3zjtturXDoaidQjDg== X-Received: by 2002:a7b:cd95:0:b0:425:6dce:8c54 with SMTP id 5b1f17b1804b1-4264a48c4e0mr219825e9.33.1720047046024; Wed, 03 Jul 2024 15:50:46 -0700 (PDT) Date: Wed, 3 Jul 2024 18:50:42 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Markus Armbruster , Marcel Apfelbaum , Stefano Stabellini , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PULL v3 85/85] hw/pci: Replace -1 with UINT32_MAX for romsize Message-ID: <6a67577d8003428bdbeba61d32a9f8158f12624b.1720046570.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.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-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1720047169457100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki romsize is an uint32_t variable. Specifying -1 as an uint32_t value is obscure way to denote UINT32_MAX. Worse, if int is wider than 32-bit, it will change the behavior of a construct like the following: romsize =3D -1; if (romsize !=3D -1) { ... } When -1 is assigned to romsize, -1 will be implicitly casted into uint32_t, resulting in UINT32_MAX. On contrary, when evaluating romsize !=3D -1, romsize will be casted into int, and it will be a comparison of UINT32_MAX and -1, and result in false. Replace -1 with UINT32_MAX for statements involving the variable to clarify the intent and prevent potential breakage. Signed-off-by: Akihiko Odaki Reviewed-by: Markus Armbruster Message-Id: <20240627-reuse-v10-10-7ca0b8ed3d9f@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 8 ++++---- hw/xen/xen_pt_load_rom.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index fa85f87b1c..4c7be52951 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -70,7 +70,7 @@ static bool pcie_has_upstream_port(PCIDevice *dev); static Property pci_props[] =3D { DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1), DEFINE_PROP_STRING("romfile", PCIDevice, romfile), - DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, -1), + DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX), DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), @@ -2073,7 +2073,7 @@ static void pci_qdev_realize(DeviceState *qdev, Error= **errp) g_cmp_uint32, NULL); } =20 - if (pci_dev->romsize !=3D -1 && !is_power_of_2(pci_dev->romsize)) { + if (pci_dev->romsize !=3D UINT32_MAX && !is_power_of_2(pci_dev->romsiz= e)) { error_setg(errp, "ROM size %u is not a power of two", pci_dev->rom= size); return; } @@ -2359,7 +2359,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, return; } =20 - if (load_file || pdev->romsize =3D=3D -1) { + if (load_file || pdev->romsize =3D=3D UINT32_MAX) { path =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile); if (path =3D=3D NULL) { path =3D g_strdup(pdev->romfile); @@ -2378,7 +2378,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool = is_default_rom, pdev->romfile); return; } - if (pdev->romsize !=3D -1) { + if (pdev->romsize !=3D UINT_MAX) { if (size > pdev->romsize) { error_setg(errp, "romfile \"%s\" (%u bytes) " "is too large for ROM size %u", diff --git a/hw/xen/xen_pt_load_rom.c b/hw/xen/xen_pt_load_rom.c index 03422a8a71..6bc64acd33 100644 --- a/hw/xen/xen_pt_load_rom.c +++ b/hw/xen/xen_pt_load_rom.c @@ -53,7 +53,7 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, } fseek(fp, 0, SEEK_SET); =20 - if (dev->romsize !=3D -1) { + if (dev->romsize !=3D UINT_MAX) { if (st.st_size > dev->romsize) { error_report("ROM BAR \"%s\" (%ld bytes) is too large for ROM = size %u", rom_file, (long) st.st_size, dev->romsize); --=20 MST