From: linmiaohe <linmiaohe@huawei.com>
To: <pbonzini@redhat.com>, <alex.williamson@redhat.com>
Cc: <linmiaohe@huawei.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] KVM: lib: use jump label to handle resource release in irq_bypass_register_producer()
Date: Fri, 6 Dec 2019 10:53:53 +0800 [thread overview]
Message-ID: <1575600833-12839-3-git-send-email-linmiaohe@huawei.com> (raw)
In-Reply-To: <1575600833-12839-1-git-send-email-linmiaohe@huawei.com>
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
next prev parent reply other threads:[~2019-12-06 2:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-12-09 17:05 ` [PATCH 0/2] use jump label to handle resource release in irq_bypass_register_* Paolo Bonzini
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=1575600833-12839-3-git-send-email-linmiaohe@huawei.com \
--to=linmiaohe@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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 NNTP newsgroup(s).