mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
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>
This commit is contained in:
parent
885f7d6cb8
commit
8262fe85b4
@ -179,6 +179,7 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
|
|||||||
{
|
{
|
||||||
struct irq_bypass_consumer *tmp;
|
struct irq_bypass_consumer *tmp;
|
||||||
struct irq_bypass_producer *producer;
|
struct irq_bypass_producer *producer;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!consumer->token ||
|
if (!consumer->token ||
|
||||||
!consumer->add_producer || !consumer->del_producer)
|
!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) {
|
list_for_each_entry(tmp, &consumers, node) {
|
||||||
if (tmp->token == consumer->token || tmp == consumer) {
|
if (tmp->token == consumer->token || tmp == consumer) {
|
||||||
mutex_unlock(&lock);
|
ret = -EBUSY;
|
||||||
module_put(THIS_MODULE);
|
goto out_err;
|
||||||
return -EBUSY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry(producer, &producers, node) {
|
list_for_each_entry(producer, &producers, node) {
|
||||||
if (producer->token == consumer->token) {
|
if (producer->token == consumer->token) {
|
||||||
int ret = __connect(producer, consumer);
|
ret = __connect(producer, consumer);
|
||||||
if (ret) {
|
if (ret)
|
||||||
mutex_unlock(&lock);
|
goto out_err;
|
||||||
module_put(THIS_MODULE);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,6 +213,10 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
|
|||||||
mutex_unlock(&lock);
|
mutex_unlock(&lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
out_err:
|
||||||
|
mutex_unlock(&lock);
|
||||||
|
module_put(THIS_MODULE);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
|
EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user