On 4/9/25 18:30, Tomita Moeko wrote:
On 4/9/25 23:54, John Levon wrote:
On Wed, Apr 09, 2025 at 11:51:09PM +0800, Tomita Moeko wrote:

On 4/9/25 21:48, John Levon wrote:
Add these helpers that access config space and return an -errno style
return.

Signed-off-by: John Levon <john.le...@nutanix.com>
---
  hw/vfio/pci.c | 134 ++++++++++++++++++++++++++++++++++----------------
  1 file changed, 91 insertions(+), 43 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index ddeee33aa9..c3842d2f8d 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -964,6 +964,28 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
      }
  }
+/* "Raw" read of underlying config space. */
+static int vfio_pci_config_space_read(VFIOPCIDevice *vdev, off_t offset,
+                                      uint32_t size, void *data)

Returning ssize_t here might be better here to avoid casting issues,
though we would never read/write something exceeds INT32_MAX.

I considered this (and the later helpers in the patch), but most of the existing
code already uses int. Happy to look at fixing the callers too (e.g.
vfio_msi_setup()) if that's everyone's preference.

regards
john

I checked the code, caller casts return of pread/pwrite to int because
the `count` argument, bytes read/write at most, they passed does not
exceed int. Given that uint32_t can exceed int, returning ssize_t here
and let callers to determine cast or not is better I believe.
I have no strong preference. The less change the better I would say.

Thanks,

C.

Reply via email to