|
4 | 4 | * Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +#include <linux/cleanup.h> |
7 | 8 | #include <linux/interrupt.h>
|
8 | 9 | #include <linux/irq.h>
|
9 | 10 | #include <linux/irq_sim.h>
|
@@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = {
|
163 | 164 | struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode,
|
164 | 165 | unsigned int num_irqs)
|
165 | 166 | {
|
166 |
| - struct irq_sim_work_ctx *work_ctx; |
| 167 | + struct irq_sim_work_ctx *work_ctx __free(kfree) = |
| 168 | + kmalloc(sizeof(*work_ctx), GFP_KERNEL); |
167 | 169 |
|
168 |
| - work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); |
169 | 170 | if (!work_ctx)
|
170 |
| - goto err_out; |
| 171 | + return ERR_PTR(-ENOMEM); |
171 | 172 |
|
172 |
| - work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); |
173 |
| - if (!work_ctx->pending) |
174 |
| - goto err_free_work_ctx; |
| 173 | + unsigned long *pending __free(bitmap) = bitmap_zalloc(num_irqs, GFP_KERNEL); |
| 174 | + if (!pending) |
| 175 | + return ERR_PTR(-ENOMEM); |
175 | 176 |
|
176 | 177 | work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs,
|
177 | 178 | &irq_sim_domain_ops,
|
178 | 179 | work_ctx);
|
179 | 180 | if (!work_ctx->domain)
|
180 |
| - goto err_free_bitmap; |
| 181 | + return ERR_PTR(-ENOMEM); |
181 | 182 |
|
182 | 183 | work_ctx->irq_count = num_irqs;
|
183 | 184 | work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq);
|
| 185 | + work_ctx->pending = no_free_ptr(pending); |
184 | 186 |
|
185 |
| - return work_ctx->domain; |
186 |
| - |
187 |
| -err_free_bitmap: |
188 |
| - bitmap_free(work_ctx->pending); |
189 |
| -err_free_work_ctx: |
190 |
| - kfree(work_ctx); |
191 |
| -err_out: |
192 |
| - return ERR_PTR(-ENOMEM); |
| 187 | + return no_free_ptr(work_ctx)->domain; |
193 | 188 | }
|
194 | 189 | EXPORT_SYMBOL_GPL(irq_domain_create_sim);
|
195 | 190 |
|
|
0 commit comments