mirror of
https://github.com/torvalds/linux.git
synced 2024-12-31 23:31:29 +00:00
KVM: lib: use jump label to handle resource release in irq_bypass_register_producer()
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
8262fe85b4
commit
bbfdafa860
@ -85,6 +85,7 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
|
|||||||
{
|
{
|
||||||
struct irq_bypass_producer *tmp;
|
struct irq_bypass_producer *tmp;
|
||||||
struct irq_bypass_consumer *consumer;
|
struct irq_bypass_consumer *consumer;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!producer->token)
|
if (!producer->token)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -98,20 +99,16 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
|
|||||||
|
|
||||||
list_for_each_entry(tmp, &producers, node) {
|
list_for_each_entry(tmp, &producers, node) {
|
||||||
if (tmp->token == producer->token) {
|
if (tmp->token == producer->token) {
|
||||||
mutex_unlock(&lock);
|
ret = -EBUSY;
|
||||||
module_put(THIS_MODULE);
|
goto out_err;
|
||||||
return -EBUSY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry(consumer, &consumers, node) {
|
list_for_each_entry(consumer, &consumers, node) {
|
||||||
if (consumer->token == producer->token) {
|
if (consumer->token == producer->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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,6 +118,10 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
|
|||||||
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_producer);
|
EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user