* [PATCH] vfio/ap: Use g_autofree variable
@ 2024-04-24 12:54 Cédric Le Goater
2024-04-24 13:22 ` Markus Armbruster
2024-04-26 15:08 ` Anthony Krowiak
0 siblings, 2 replies; 3+ messages in thread
From: Cédric Le Goater @ 2024-04-24 12:54 UTC (permalink / raw)
To: Alex Williamson, Cédric Le Goater, Tony Krowiak, Halil Pasic,
Jason Herne, Thomas Huth
Cc: qemu-s390x, qemu-devel
Also change the return value of vfio_ap_register_irq_notifier() to be
a bool since it takes and 'Error **' argument. See the qapi/error.h
Rules section.
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/ap.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index 7c4caa5938636937680fec87e999249ac84a4498..8bb024e2fde4a1d72346dee4b662d762374326b9 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -70,14 +70,14 @@ static void vfio_ap_req_notifier_handler(void *opaque)
}
}
-static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
+static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
unsigned int irq, Error **errp)
{
int fd;
size_t argsz;
IOHandler *fd_read;
EventNotifier *notifier;
- struct vfio_irq_info *irq_info;
+ g_autofree struct vfio_irq_info *irq_info = NULL;
VFIODevice *vdev = &vapdev->vdev;
switch (irq) {
@@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
break;
default:
error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
- return;
+ return false;
}
if (vdev->num_irqs < irq + 1) {
error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)",
irq, vdev->num_irqs);
- return;
+ return false;
}
argsz = sizeof(*irq_info);
@@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
irq_info) < 0 || irq_info->count < 1) {
error_setg_errno(errp, errno, "vfio: Error getting irq info");
- goto out_free_info;
+ return false;
}
if (event_notifier_init(notifier, 0)) {
error_setg_errno(errp, errno,
"vfio: Unable to init event notifier for irq (%d)",
irq);
- goto out_free_info;
+ return false;
}
fd = event_notifier_get_fd(notifier);
@@ -123,9 +123,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
event_notifier_cleanup(notifier);
}
-out_free_info:
- g_free(irq_info);
-
+ return true;
}
static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
@@ -171,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
goto error;
}
- vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
- if (err) {
+ if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err)) {
/*
* Report this error, but do not make it a failing condition.
* Lack of this IRQ in the host does not prevent normal operation.
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vfio/ap: Use g_autofree variable
2024-04-24 12:54 [PATCH] vfio/ap: Use g_autofree variable Cédric Le Goater
@ 2024-04-24 13:22 ` Markus Armbruster
2024-04-26 15:08 ` Anthony Krowiak
1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2024-04-24 13:22 UTC (permalink / raw)
To: Cédric Le Goater
Cc: Alex Williamson, Tony Krowiak, Halil Pasic, Jason Herne,
Thomas Huth, qemu-s390x, qemu-devel
Cédric Le Goater <clg@redhat.com> writes:
> Also change the return value of vfio_ap_register_irq_notifier() to be
> a bool since it takes and 'Error **' argument. See the qapi/error.h
> Rules section.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
Split the patch?
If not, the bigger part by far is the return value change, so I'd put
that into the subject.
> ---
> hw/vfio/ap.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index 7c4caa5938636937680fec87e999249ac84a4498..8bb024e2fde4a1d72346dee4b662d762374326b9 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -70,14 +70,14 @@ static void vfio_ap_req_notifier_handler(void *opaque)
> }
> }
>
> -static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> +static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> unsigned int irq, Error **errp)
> {
> int fd;
> size_t argsz;
> IOHandler *fd_read;
> EventNotifier *notifier;
> - struct vfio_irq_info *irq_info;
> + g_autofree struct vfio_irq_info *irq_info = NULL;
> VFIODevice *vdev = &vapdev->vdev;
>
> switch (irq) {
> @@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> break;
> default:
> error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
> - return;
> + return false;
> }
>
> if (vdev->num_irqs < irq + 1) {
> error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)",
> irq, vdev->num_irqs);
> - return;
> + return false;
> }
>
> argsz = sizeof(*irq_info);
> @@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> irq_info) < 0 || irq_info->count < 1) {
> error_setg_errno(errp, errno, "vfio: Error getting irq info");
> - goto out_free_info;
> + return false;
> }
>
> if (event_notifier_init(notifier, 0)) {
> error_setg_errno(errp, errno,
> "vfio: Unable to init event notifier for irq (%d)",
> irq);
> - goto out_free_info;
> + return false;
> }
>
> fd = event_notifier_get_fd(notifier);
> @@ -123,9 +123,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> event_notifier_cleanup(notifier);
> }
>
> -out_free_info:
> - g_free(irq_info);
> -
> + return true;
> }
>
> static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
> @@ -171,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
> goto error;
> }
>
> - vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
> - if (err) {
> + if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err)) {
> /*
> * Report this error, but do not make it a failing condition.
> * Lack of this IRQ in the host does not prevent normal operation.
*/
error_report_err(err);
Not this patch's problem, but here goes anyway: since this isn't an
error, we shouldn't use error_report_err(). Would warn_report_err() be
appropriate? info_report_err() doesn't exist, but it could.
}
return;
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vfio/ap: Use g_autofree variable
2024-04-24 12:54 [PATCH] vfio/ap: Use g_autofree variable Cédric Le Goater
2024-04-24 13:22 ` Markus Armbruster
@ 2024-04-26 15:08 ` Anthony Krowiak
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Krowiak @ 2024-04-26 15:08 UTC (permalink / raw)
To: Cédric Le Goater, Alex Williamson, Halil Pasic, Jason Herne,
Thomas Huth
Cc: qemu-s390x, qemu-devel
On 4/24/24 8:54 AM, Cédric Le Goater wrote:
> Also change the return value of vfio_ap_register_irq_notifier() to be
> a bool since it takes and 'Error **' argument. See the qapi/error.h
> Rules section.
LGTM
Signed-off-by: Anthony Krowiak <akrowiak@linux.ibm.com>
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> hw/vfio/ap.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index 7c4caa5938636937680fec87e999249ac84a4498..8bb024e2fde4a1d72346dee4b662d762374326b9 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -70,14 +70,14 @@ static void vfio_ap_req_notifier_handler(void *opaque)
> }
> }
>
> -static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> +static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> unsigned int irq, Error **errp)
> {
> int fd;
> size_t argsz;
> IOHandler *fd_read;
> EventNotifier *notifier;
> - struct vfio_irq_info *irq_info;
> + g_autofree struct vfio_irq_info *irq_info = NULL;
> VFIODevice *vdev = &vapdev->vdev;
>
> switch (irq) {
> @@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> break;
> default:
> error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
> - return;
> + return false;
> }
>
> if (vdev->num_irqs < irq + 1) {
> error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)",
> irq, vdev->num_irqs);
> - return;
> + return false;
> }
>
> argsz = sizeof(*irq_info);
> @@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> irq_info) < 0 || irq_info->count < 1) {
> error_setg_errno(errp, errno, "vfio: Error getting irq info");
> - goto out_free_info;
> + return false;
> }
>
> if (event_notifier_init(notifier, 0)) {
> error_setg_errno(errp, errno,
> "vfio: Unable to init event notifier for irq (%d)",
> irq);
> - goto out_free_info;
> + return false;
> }
>
> fd = event_notifier_get_fd(notifier);
> @@ -123,9 +123,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
> event_notifier_cleanup(notifier);
> }
>
> -out_free_info:
> - g_free(irq_info);
> -
> + return true;
> }
>
> static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
> @@ -171,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
> goto error;
> }
>
> - vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err);
> - if (err) {
> + if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err)) {
> /*
> * Report this error, but do not make it a failing condition.
> * Lack of this IRQ in the host does not prevent normal operation.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-26 15:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 12:54 [PATCH] vfio/ap: Use g_autofree variable Cédric Le Goater
2024-04-24 13:22 ` Markus Armbruster
2024-04-26 15:08 ` Anthony Krowiak
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 NNTP newsgroup(s).