From: "Cédric Le Goater" <clg@redhat.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com
Subject: Re: [PATCH v2 01/11] vfio/pci: Use g_autofree in vfio_realize
Date: Tue, 14 May 2024 17:45:04 +0200 [thread overview]
Message-ID: <9d615831-a907-43dd-972c-2defa6645759@redhat.com> (raw)
In-Reply-To: <20240507064252.457884-2-zhenzhong.duan@intel.com>
On 5/7/24 08:42, Zhenzhong Duan wrote:
> Local pointer name is allocated before vfio_attach_device() call
> and freed after the call.
>
> Same for tmp when calling realpath().
>
> Use 'g_autofree' to avoid the g_free() calls.
>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/vfio/pci.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 64780d1b79..576b21e2bb 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2946,12 +2946,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
> ERRP_GUARD();
> VFIOPCIDevice *vdev = VFIO_PCI(pdev);
> VFIODevice *vbasedev = &vdev->vbasedev;
> - char *tmp, *subsys;
> + char *subsys;
> Error *err = NULL;
> int i, ret;
> bool is_mdev;
> char uuid[UUID_STR_LEN];
> - char *name;
> + g_autofree char *name = NULL;
> + g_autofree char *tmp = NULL;
>
> if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
> if (!(~vdev->host.domain || ~vdev->host.bus ||
> @@ -2982,7 +2983,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
> */
> tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
> subsys = realpath(tmp, NULL);
> - g_free(tmp);
> is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
> free(subsys);
>
> @@ -3003,7 +3003,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>
> ret = vfio_attach_device(name, vbasedev,
> pci_device_iommu_address_space(pdev), errp);
> - g_free(name);
> if (ret) {
> goto error;
> }
next prev parent reply other threads:[~2024-05-14 15:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 6:42 [PATCH v2 00/11] VFIO: misc cleanups Zhenzhong Duan
2024-05-07 6:42 ` [PATCH v2 01/11] vfio/pci: Use g_autofree in vfio_realize Zhenzhong Duan
2024-05-14 15:45 ` Cédric Le Goater [this message]
2024-05-07 6:42 ` [PATCH v2 02/11] vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range() Zhenzhong Duan
2024-05-14 15:45 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 03/11] vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool Zhenzhong Duan
2024-05-07 7:27 ` Cédric Le Goater
2024-05-07 7:34 ` Duan, Zhenzhong
2024-05-15 16:28 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 04/11] vfio: Make VFIOIOMMUClass::setup() " Zhenzhong Duan
2024-05-07 6:42 ` [PATCH v2 05/11] vfio: Make VFIOIOMMUClass::add_window() and its wrapper " Zhenzhong Duan
2024-05-07 6:42 ` [PATCH v2 06/11] vfio/container: Make vfio_connect_container() " Zhenzhong Duan
2024-05-14 16:00 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 07/11] vfio/container: Make vfio_set_iommu() " Zhenzhong Duan
2024-05-14 16:00 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 08/11] vfio/container: Make vfio_get_device() " Zhenzhong Duan
2024-05-14 16:01 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 09/11] vfio/iommufd: Make iommufd_cdev_*() " Zhenzhong Duan
2024-05-14 16:02 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 10/11] vfio/cpr: Make vfio_cpr_register_container() " Zhenzhong Duan
2024-05-14 16:02 ` Cédric Le Goater
2024-05-07 6:42 ` [PATCH v2 11/11] backends/iommufd: Make iommufd_backend_*() " Zhenzhong Duan
2024-05-14 16:03 ` Cédric Le Goater
2024-05-14 3:46 ` [PATCH v2 00/11] VFIO: misc cleanups Duan, Zhenzhong
2024-05-16 16:30 ` Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9d615831-a907-43dd-972c-2defa6645759@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=chao.p.peng@intel.com \
--cc=eric.auger@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).