Skip to content

Commit aafd753

Browse files
Bartosz GolaszewskiIngo Molnar
authored andcommitted
genirq/irq_sim: Shrink code by using <linux/cleanup.h> helpers
Use the new __free() mechanism to remove all gotos and simplify the error paths. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20240122124243.44002-5-brgl@bgdev.pl
1 parent 8dab7fd commit aafd753

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

kernel/irq/irq_sim.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2020 Bartosz Golaszewski <bgolaszewski@baylibre.com>
55
*/
66

7+
#include <linux/cleanup.h>
78
#include <linux/interrupt.h>
89
#include <linux/irq.h>
910
#include <linux/irq_sim.h>
@@ -163,33 +164,27 @@ static const struct irq_domain_ops irq_sim_domain_ops = {
163164
struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode,
164165
unsigned int num_irqs)
165166
{
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);
167169

168-
work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL);
169170
if (!work_ctx)
170-
goto err_out;
171+
return ERR_PTR(-ENOMEM);
171172

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);
175176

176177
work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs,
177178
&irq_sim_domain_ops,
178179
work_ctx);
179180
if (!work_ctx->domain)
180-
goto err_free_bitmap;
181+
return ERR_PTR(-ENOMEM);
181182

182183
work_ctx->irq_count = num_irqs;
183184
work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq);
185+
work_ctx->pending = no_free_ptr(pending);
184186

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;
193188
}
194189
EXPORT_SYMBOL_GPL(irq_domain_create_sim);
195190

0 commit comments

Comments
 (0)