Skip to content

Commit bbfdafa

Browse files
MiaoheLinbonzini
authored andcommitted
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>
1 parent 8262fe8 commit bbfdafa

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

virt/lib/irqbypass.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
8585
{
8686
struct irq_bypass_producer *tmp;
8787
struct irq_bypass_consumer *consumer;
88+
int ret;
8889

8990
if (!producer->token)
9091
return -EINVAL;
@@ -98,20 +99,16 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
9899

99100
list_for_each_entry(tmp, &producers, node) {
100101
if (tmp->token == producer->token) {
101-
mutex_unlock(&lock);
102-
module_put(THIS_MODULE);
103-
return -EBUSY;
102+
ret = -EBUSY;
103+
goto out_err;
104104
}
105105
}
106106

107107
list_for_each_entry(consumer, &consumers, node) {
108108
if (consumer->token == producer->token) {
109-
int ret = __connect(producer, consumer);
110-
if (ret) {
111-
mutex_unlock(&lock);
112-
module_put(THIS_MODULE);
113-
return ret;
114-
}
109+
ret = __connect(producer, consumer);
110+
if (ret)
111+
goto out_err;
115112
break;
116113
}
117114
}
@@ -121,6 +118,10 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
121118
mutex_unlock(&lock);
122119

123120
return 0;
121+
out_err:
122+
mutex_unlock(&lock);
123+
module_put(THIS_MODULE);
124+
return ret;
124125
}
125126
EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
126127

0 commit comments

Comments
 (0)