* [PATCH] vfio/platform: Use common error handling code in vfio_set_trigger()
@ 2024-01-15 17:16 Markus Elfring
2024-01-15 20:37 ` Alex Williamson
0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-01-15 17:16 UTC (permalink / raw)
To: kvm, kernel-janitors, Alex Williamson, Eric Auger; +Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 15 Jan 2024 18:08:29 +0100
Add a jump target so that a bit of exception handling can be better reused
in an if branch of this function.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/vfio/platform/vfio_platform_irq.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c
index 61a1bfb68ac7..8604ce4f3fee 100644
--- a/drivers/vfio/platform/vfio_platform_irq.c
+++ b/drivers/vfio/platform/vfio_platform_irq.c
@@ -193,8 +193,8 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index,
trigger = eventfd_ctx_fdget(fd);
if (IS_ERR(trigger)) {
- kfree(irq->name);
- return PTR_ERR(trigger);
+ ret = PTR_ERR(trigger);
+ goto free_name;
}
irq->trigger = trigger;
@@ -202,9 +202,10 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index,
irq_set_status_flags(irq->hwirq, IRQ_NOAUTOEN);
ret = request_irq(irq->hwirq, handler, 0, irq->name, irq);
if (ret) {
- kfree(irq->name);
eventfd_ctx_put(trigger);
irq->trigger = NULL;
+free_name:
+ kfree(irq->name);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vfio/platform: Use common error handling code in vfio_set_trigger()
2024-01-15 17:16 [PATCH] vfio/platform: Use common error handling code in vfio_set_trigger() Markus Elfring
@ 2024-01-15 20:37 ` Alex Williamson
2024-01-16 11:32 ` Markus Elfring
0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2024-01-15 20:37 UTC (permalink / raw)
To: Markus Elfring; +Cc: kvm, kernel-janitors, Eric Auger, LKML
On Mon, 15 Jan 2024 18:16:01 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 15 Jan 2024 18:08:29 +0100
>
> Add a jump target so that a bit of exception handling can be better reused
> in an if branch of this function.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/vfio/platform/vfio_platform_irq.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c
> index 61a1bfb68ac7..8604ce4f3fee 100644
> --- a/drivers/vfio/platform/vfio_platform_irq.c
> +++ b/drivers/vfio/platform/vfio_platform_irq.c
> @@ -193,8 +193,8 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index,
>
> trigger = eventfd_ctx_fdget(fd);
> if (IS_ERR(trigger)) {
> - kfree(irq->name);
> - return PTR_ERR(trigger);
> + ret = PTR_ERR(trigger);
> + goto free_name;
> }
>
> irq->trigger = trigger;
> @@ -202,9 +202,10 @@ static int vfio_set_trigger(struct vfio_platform_device *vdev, int index,
> irq_set_status_flags(irq->hwirq, IRQ_NOAUTOEN);
> ret = request_irq(irq->hwirq, handler, 0, irq->name, irq);
> if (ret) {
> - kfree(irq->name);
> eventfd_ctx_put(trigger);
> irq->trigger = NULL;
> +free_name:
> + kfree(irq->name);
> return ret;
> }
>
TBH, this doesn't seem like a worthwhile exit point consolidation. A
change like this might be justified if there were some common unlock
code that could be shared, but for a simple free and return errno by
jumping to a different exception block, rather than even a common exit
block, I don't see the value. Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: vfio/platform: Use common error handling code in vfio_set_trigger()
2024-01-15 20:37 ` Alex Williamson
@ 2024-01-16 11:32 ` Markus Elfring
2024-01-16 18:33 ` Alex Williamson
0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-01-16 11:32 UTC (permalink / raw)
To: Alex Williamson, Eric Auger, kvm, kernel-janitors; +Cc: LKML
> TBH, this doesn't seem like a worthwhile exit point consolidation. A
> change like this might be justified if there were some common unlock
> code that could be shared, but for a simple free and return errno by
> jumping to a different exception block, rather than even a common exit
> block, I don't see the value.
Can it be helpful to store the shown kfree() call only once
in this function implementation?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: vfio/platform: Use common error handling code in vfio_set_trigger()
2024-01-16 11:32 ` Markus Elfring
@ 2024-01-16 18:33 ` Alex Williamson
0 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2024-01-16 18:33 UTC (permalink / raw)
To: Markus Elfring; +Cc: Eric Auger, kvm, kernel-janitors, LKML
On Tue, 16 Jan 2024 12:32:23 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:
> > TBH, this doesn't seem like a worthwhile exit point consolidation. A
> > change like this might be justified if there were some common unlock
> > code that could be shared, but for a simple free and return errno by
> > jumping to a different exception block, rather than even a common exit
> > block, I don't see the value.
>
> Can it be helpful to store the shown kfree() call only once
> in this function implementation?
I don't believe it's worthwhile, it's a simple function with simple
exit paths and consolidating those exit paths for a trivial kfree() is
unnecessarily complex. Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-16 18:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15 17:16 [PATCH] vfio/platform: Use common error handling code in vfio_set_trigger() Markus Elfring
2024-01-15 20:37 ` Alex Williamson
2024-01-16 11:32 ` Markus Elfring
2024-01-16 18:33 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox