From fabb7430501c211430ba798a54a1cf1766557976 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Tue, 13 Aug 2019 15:07:53 +0200 Subject: [PATCH] util: Introduce virPCIDeviceConfigOpenWrite MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Only a handful of function need write access to the PCI config space. Create a wrapper function for those so that we can open it read only by default. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/util/virpci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index f4be907a10..c1dad1e69f 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -320,6 +320,12 @@ virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal) return virPCIDeviceConfigOpenInternal(dev, fatal); } +static int +virPCIDeviceConfigOpenWrite(virPCIDevicePtr dev) +{ + return virPCIDeviceConfigOpenInternal(dev, true); +} + static void virPCIDeviceConfigClose(virPCIDevicePtr dev, int cfgfd) { @@ -808,7 +814,7 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, dev->name); return -1; } - if ((parentfd = virPCIDeviceConfigOpen(parent, true)) < 0) + if ((parentfd = virPCIDeviceConfigOpenWrite(parent)) < 0) goto out; VIR_DEBUG("%s %s: doing a secondary bus reset", dev->id, dev->name); @@ -957,7 +963,7 @@ virPCIDeviceReset(virPCIDevicePtr dev, } VIR_DEBUG("Resetting device %s", dev->name); - if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0) + if ((fd = virPCIDeviceConfigOpenWrite(dev)) < 0) goto cleanup; if (virPCIDeviceInit(dev, fd) < 0) -- 2.47.2