* [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_*
@ 2019-12-06 2:53 linmiaohe
2019-12-06 2:53 ` [PATCH 1/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer() linmiaohe
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: linmiaohe @ 2019-12-06 2:53 UTC (permalink / raw)
To: pbonzini, alex.williamson; +Cc: linmiaohe, kvm, linux-kernel
From: Miaohe Lin <linmiaohe@huawei.com>
Use out_err jump label to help handle resource release.
It's a good practice to release resource in one place
and help eliminate some duplicated code.
Miaohe Lin (2):
KVM: lib: use jump label to handle resource release in
irq_bypass_register_consumer()
KVM: lib: use jump label to handle resource release in
irq_bypass_register_producer()
virt/lib/irqbypass.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
--
2.19.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer()
2019-12-06 2:53 [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* linmiaohe
@ 2019-12-06 2:53 ` linmiaohe
2019-12-06 2:53 ` [PATCH 2/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_producer() linmiaohe
2019-12-09 17:05 ` [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: linmiaohe @ 2019-12-06 2:53 UTC (permalink / raw)
To: pbonzini, alex.williamson; +Cc: linmiaohe, kvm, linux-kernel
From: Miaohe Lin <linmiaohe@huawei.com>
Use out_err jump label to handle resource release. It's a
good practice to release resource in one place and help
eliminate some duplicated code.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
virt/lib/irqbypass.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/virt/lib/irqbypass.c b/virt/lib/irqbypass.c
index 43de8ae78fa1..cb0c801b3bc2 100644
--- a/virt/lib/irqbypass.c
+++ b/virt/lib/irqbypass.c
@@ -179,6 +179,7 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
{
struct irq_bypass_consumer *tmp;
struct irq_bypass_producer *producer;
+ int ret;
if (!consumer->token ||
!consumer->add_producer || !consumer->del_producer)
@@ -193,20 +194,16 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
list_for_each_entry(tmp, &consumers, node) {
if (tmp->token == consumer->token || tmp == consumer) {
- mutex_unlock(&lock);
- module_put(THIS_MODULE);
- return -EBUSY;
+ ret = -EBUSY;
+ goto out_err;
}
}
list_for_each_entry(producer, &producers, node) {
if (producer->token == consumer->token) {
- int ret = __connect(producer, consumer);
- if (ret) {
- mutex_unlock(&lock);
- module_put(THIS_MODULE);
- return ret;
- }
+ ret = __connect(producer, consumer);
+ if (ret)
+ goto out_err;
break;
}
}
@@ -216,6 +213,10 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
mutex_unlock(&lock);
return 0;
+out_err:
+ mutex_unlock(&lock);
+ module_put(THIS_MODULE);
+ return ret;
}
EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_producer()
2019-12-06 2:53 [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* linmiaohe
2019-12-06 2:53 ` [PATCH 1/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer() linmiaohe
@ 2019-12-06 2:53 ` linmiaohe
2019-12-09 17:05 ` [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: linmiaohe @ 2019-12-06 2:53 UTC (permalink / raw)
To: pbonzini, alex.williamson; +Cc: linmiaohe, kvm, linux-kernel
From: Miaohe Lin <linmiaohe@huawei.com>
Use out_err jump label to handle resource release. It's a
good practice to release resource in one place and help
eliminate some duplicated code.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
virt/lib/irqbypass.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/virt/lib/irqbypass.c b/virt/lib/irqbypass.c
index cb0c801b3bc2..28fda42e471b 100644
--- a/virt/lib/irqbypass.c
+++ b/virt/lib/irqbypass.c
@@ -85,6 +85,7 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
{
struct irq_bypass_producer *tmp;
struct irq_bypass_consumer *consumer;
+ int ret;
if (!producer->token)
return -EINVAL;
@@ -98,20 +99,16 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
list_for_each_entry(tmp, &producers, node) {
if (tmp->token == producer->token) {
- mutex_unlock(&lock);
- module_put(THIS_MODULE);
- return -EBUSY;
+ ret = -EBUSY;
+ goto out_err;
}
}
list_for_each_entry(consumer, &consumers, node) {
if (consumer->token == producer->token) {
- int ret = __connect(producer, consumer);
- if (ret) {
- mutex_unlock(&lock);
- module_put(THIS_MODULE);
- return ret;
- }
+ ret = __connect(producer, consumer);
+ if (ret)
+ goto out_err;
break;
}
}
@@ -121,6 +118,10 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
mutex_unlock(&lock);
return 0;
+out_err:
+ mutex_unlock(&lock);
+ module_put(THIS_MODULE);
+ return ret;
}
EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_*
2019-12-06 2:53 [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* linmiaohe
2019-12-06 2:53 ` [PATCH 1/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer() linmiaohe
2019-12-06 2:53 ` [PATCH 2/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_producer() linmiaohe
@ 2019-12-09 17:05 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-12-09 17:05 UTC (permalink / raw)
To: linmiaohe, alex.williamson; +Cc: kvm, linux-kernel
On 06/12/19 03:53, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> Use out_err jump label to help handle resource release.
> It's a good practice to release resource in one place
> and help eliminate some duplicated code.
>
> Miaohe Lin (2):
> KVM: lib: use jump label to handle resource release in
> irq_bypass_register_consumer()
> KVM: lib: use jump label to handle resource release in
> irq_bypass_register_producer()
>
> virt/lib/irqbypass.c | 38 ++++++++++++++++++++------------------
> 1 file changed, 20 insertions(+), 18 deletions(-)
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-09 17:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 2:53 [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* linmiaohe
2019-12-06 2:53 ` [PATCH 1/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer() linmiaohe
2019-12-06 2:53 ` [PATCH 2/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_producer() linmiaohe
2019-12-09 17:05 ` [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.