Skip to content

Commit 52bf4a9

Browse files
alexandrebellonidlezcano
authored andcommitted
clocksource/drivers/timer-atmel-pit: Properly handle error cases
The smatch utility reports a possible leak: smatch warnings: drivers/clocksource/timer-atmel-pit.c:183 at91sam926x_pit_dt_init() warn: possible memory leak of 'data' Ensure data is freed before exiting with an error. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Cc: stable@vger.kernel.org Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 4451d3f commit 52bf4a9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/clocksource/timer-atmel-pit.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
180180
data->base = of_iomap(node, 0);
181181
if (!data->base) {
182182
pr_err("Could not map PIT address\n");
183-
return -ENXIO;
183+
ret = -ENXIO;
184+
goto exit;
184185
}
185186

186187
data->mck = of_clk_get(node, 0);
187188
if (IS_ERR(data->mck)) {
188189
pr_err("Unable to get mck clk\n");
189-
return PTR_ERR(data->mck);
190+
ret = PTR_ERR(data->mck);
191+
goto exit;
190192
}
191193

192194
ret = clk_prepare_enable(data->mck);
193195
if (ret) {
194196
pr_err("Unable to enable mck\n");
195-
return ret;
197+
goto exit;
196198
}
197199

198200
/* Get the interrupts property */
199201
data->irq = irq_of_parse_and_map(node, 0);
200202
if (!data->irq) {
201203
pr_err("Unable to get IRQ from DT\n");
202-
return -EINVAL;
204+
ret = -EINVAL;
205+
goto exit;
203206
}
204207

205208
/*
@@ -227,7 +230,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
227230
ret = clocksource_register_hz(&data->clksrc, pit_rate);
228231
if (ret) {
229232
pr_err("Failed to register clocksource\n");
230-
return ret;
233+
goto exit;
231234
}
232235

233236
/* Set up irq handler */
@@ -236,7 +239,8 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
236239
"at91_tick", data);
237240
if (ret) {
238241
pr_err("Unable to setup IRQ\n");
239-
return ret;
242+
clocksource_unregister(&data->clksrc);
243+
goto exit;
240244
}
241245

242246
/* Set up and register clockevents */
@@ -254,6 +258,10 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
254258
clockevents_register_device(&data->clkevt);
255259

256260
return 0;
261+
262+
exit:
263+
kfree(data);
264+
return ret;
257265
}
258266
TIMER_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
259267
at91sam926x_pit_dt_init);

0 commit comments

Comments
 (0)