aboutsummaryrefslogtreecommitdiff
path: root/virt/lib
diff options
context:
space:
mode:
authorMiaohe Lin <linmiaohe@huawei.com>2019-12-06 10:53:52 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-01-08 18:16:01 +0100
commit8262fe85b4edc5fb3dd7b9520bf5c6b4f027fa55 (patch)
tree2886bd99c836d3b8bd27bd3baff8ef190f10464f /virt/lib
parent885f7d6cb87eb15d62613c05d8012e9370fb5e27 (diff)
downloadlinux-stericsson-8262fe85b4edc5fb3dd7b9520bf5c6b4f027fa55.tar.gz
KVM: lib: use jump label to handle resource release in irq_bypass_register_consumer()
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> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/lib')
-rw-r--r--virt/lib/irqbypass.c19
1 files 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);