[libvirt PATCH 3/3] nodedev: handle null return from GetIOMMUGroupDev()

Erik Skultety eskultet at redhat.com
Wed Apr 14 06:05:17 UTC 2021


On Tue, Apr 13, 2021 at 03:49:33PM -0500, Jonathon Jongsma wrote:
> Coverity reported that this function can return NULL, so it should be
> handled properly.
> 
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
> ---
>  src/node_device/node_device_driver.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
> index 5f8995172d..2fcebd065b 100644
> --- a/src/node_device/node_device_driver.c
> +++ b/src/node_device/node_device_driver.c
> @@ -1192,9 +1192,18 @@ nodeDeviceDestroy(virNodeDevicePtr device)
>           * shouldn't try to remove the device. */
>          g_autofree char *vfiogroup =
>              virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid);
> -        VIR_AUTOCLOSE fd = open(vfiogroup, O_RDONLY);
> +        VIR_AUTOCLOSE fd = -1;
>          g_autofree char *errmsg = NULL;
>  
> +        if (!vfiogroup) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("Unable to determine iommu group for '%s'"),
> +                           def->name);

This will lead to error stacking - virMediatedDeviceGetIOMMUGroupDev already
reported an error for you at this point.

Erik




More information about the libvir-list mailing list