.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * IRQ offload/bypass manager |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2015 Red Hat, Inc. |
---|
5 | 6 | * Copyright (c) 2015 Linaro Ltd. |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | 7 | * |
---|
11 | 8 | * Various virtualization hardware acceleration techniques allow bypassing or |
---|
12 | 9 | * offloading interrupts received from devices around the host kernel. Posted |
---|
.. | .. |
---|
88 | 85 | { |
---|
89 | 86 | struct irq_bypass_producer *tmp; |
---|
90 | 87 | struct irq_bypass_consumer *consumer; |
---|
| 88 | + int ret; |
---|
91 | 89 | |
---|
92 | 90 | if (!producer->token) |
---|
93 | 91 | return -EINVAL; |
---|
.. | .. |
---|
101 | 99 | |
---|
102 | 100 | list_for_each_entry(tmp, &producers, node) { |
---|
103 | 101 | if (tmp->token == producer->token) { |
---|
104 | | - mutex_unlock(&lock); |
---|
105 | | - module_put(THIS_MODULE); |
---|
106 | | - return -EBUSY; |
---|
| 102 | + ret = -EBUSY; |
---|
| 103 | + goto out_err; |
---|
107 | 104 | } |
---|
108 | 105 | } |
---|
109 | 106 | |
---|
110 | 107 | list_for_each_entry(consumer, &consumers, node) { |
---|
111 | 108 | if (consumer->token == producer->token) { |
---|
112 | | - int ret = __connect(producer, consumer); |
---|
113 | | - if (ret) { |
---|
114 | | - mutex_unlock(&lock); |
---|
115 | | - module_put(THIS_MODULE); |
---|
116 | | - return ret; |
---|
117 | | - } |
---|
| 109 | + ret = __connect(producer, consumer); |
---|
| 110 | + if (ret) |
---|
| 111 | + goto out_err; |
---|
118 | 112 | break; |
---|
119 | 113 | } |
---|
120 | 114 | } |
---|
.. | .. |
---|
124 | 118 | mutex_unlock(&lock); |
---|
125 | 119 | |
---|
126 | 120 | return 0; |
---|
| 121 | +out_err: |
---|
| 122 | + mutex_unlock(&lock); |
---|
| 123 | + module_put(THIS_MODULE); |
---|
| 124 | + return ret; |
---|
127 | 125 | } |
---|
128 | 126 | EXPORT_SYMBOL_GPL(irq_bypass_register_producer); |
---|
129 | 127 | |
---|
.. | .. |
---|
182 | 180 | { |
---|
183 | 181 | struct irq_bypass_consumer *tmp; |
---|
184 | 182 | struct irq_bypass_producer *producer; |
---|
| 183 | + int ret; |
---|
185 | 184 | |
---|
186 | 185 | if (!consumer->token || |
---|
187 | 186 | !consumer->add_producer || !consumer->del_producer) |
---|
.. | .. |
---|
196 | 195 | |
---|
197 | 196 | list_for_each_entry(tmp, &consumers, node) { |
---|
198 | 197 | if (tmp->token == consumer->token || tmp == consumer) { |
---|
199 | | - mutex_unlock(&lock); |
---|
200 | | - module_put(THIS_MODULE); |
---|
201 | | - return -EBUSY; |
---|
| 198 | + ret = -EBUSY; |
---|
| 199 | + goto out_err; |
---|
202 | 200 | } |
---|
203 | 201 | } |
---|
204 | 202 | |
---|
205 | 203 | list_for_each_entry(producer, &producers, node) { |
---|
206 | 204 | if (producer->token == consumer->token) { |
---|
207 | | - int ret = __connect(producer, consumer); |
---|
208 | | - if (ret) { |
---|
209 | | - mutex_unlock(&lock); |
---|
210 | | - module_put(THIS_MODULE); |
---|
211 | | - return ret; |
---|
212 | | - } |
---|
| 205 | + ret = __connect(producer, consumer); |
---|
| 206 | + if (ret) |
---|
| 207 | + goto out_err; |
---|
213 | 208 | break; |
---|
214 | 209 | } |
---|
215 | 210 | } |
---|
.. | .. |
---|
219 | 214 | mutex_unlock(&lock); |
---|
220 | 215 | |
---|
221 | 216 | return 0; |
---|
| 217 | +out_err: |
---|
| 218 | + mutex_unlock(&lock); |
---|
| 219 | + module_put(THIS_MODULE); |
---|
| 220 | + return ret; |
---|
222 | 221 | } |
---|
223 | 222 | EXPORT_SYMBOL_GPL(irq_bypass_register_consumer); |
---|
224 | 223 | |
---|