On 5/22/24 06:40, Zhenzhong Duan wrote:
> Pointer opregion, host and lpc are allocated and freed in
> vfio_probe_igd_bar4_quirk(). Use g_autofree to automatically
> free them.
>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/vfio/igd.c | 27 ++++++++++++---------------
> 1 file changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
> index 1e79202f2b..d320d032a7 100644
> --- a/hw/vfio/igd.c
> +++ b/hw/vfio/igd.c
> @@ -368,7 +368,9 @@ static const MemoryRegionOps vfio_igd_index_quirk = {
> void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> {
> g_autofree struct vfio_region_info *rom = NULL;
> - struct vfio_region_info *opregion = NULL, *host = NULL, *lpc = NULL;
> + g_autofree struct vfio_region_info *opregion = NULL;
> + g_autofree struct vfio_region_info *host = NULL;
> + g_autofree struct vfio_region_info *lpc = NULL;
> VFIOQuirk *quirk;
> VFIOIGDQuirk *igd;
> PCIDevice *lpc_bridge;
> @@ -426,7 +428,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if ((ret || !rom->size) && !vdev->pdev.romfile) {
> error_report("IGD device %s has no ROM, legacy mode disabled",
> vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> /*
> @@ -437,7 +439,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> error_report("IGD device %s hotplugged, ROM disabled, "
> "legacy mode disabled", vdev->vbasedev.name);
> vdev->rom_read_failed = true;
> - goto out;
> + return;
> }
>
> /*
> @@ -450,7 +452,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if (ret) {
> error_report("IGD device %s does not support OpRegion access,"
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> ret = vfio_get_dev_region_info(&vdev->vbasedev,
> @@ -459,7 +461,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if (ret) {
> error_report("IGD device %s does not support host bridge access,"
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> ret = vfio_get_dev_region_info(&vdev->vbasedev,
> @@ -468,7 +470,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if (ret) {
> error_report("IGD device %s does not support LPC bridge access,"
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
> @@ -482,7 +484,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> error_report("IGD device %s failed to enable VGA access, "
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> /* Create our LPC/ISA bridge */
> @@ -490,7 +492,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if (ret) {
> error_report("IGD device %s failed to create LPC bridge, "
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> /* Stuff some host values into the VM PCI host bridge */
> @@ -498,14 +500,14 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> if (ret) {
> error_report("IGD device %s failed to modify host bridge, "
> "legacy mode disabled", vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> /* Setup OpRegion access */
> if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) {
> error_append_hint(&err, "IGD legacy mode disabled\n");
> error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> - goto out;
> + return;
> }
>
> /* Setup our quirk to munge GTT addresses to the VM allocated buffer */
> @@ -607,9 +609,4 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
> }
>
> trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, ggms_mb + gms_mb);
> -
> -out:
> - g_free(opregion);
> - g_free(host);
> - g_free(lpc);
> }