Skip to content

Commit 61a4e9e

Browse files
Timur Tabikumargala
authored andcommitted
powerpc: fix memory leaks in QE library
Fix two memory leaks in the Freescale QE library: add a missing kfree() in ucc_fast_init() and ucc_slow_init() if the ioremap() fails, and update ucc_fast_free() and ucc_slow_free() to call iounmap() if necessary. Based on a patch from Tony Breeds <tony@bakeyournoodle.com>. Signed-off-by: Timur Tabi <timur@freescale.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
1 parent d27a736 commit 61a4e9e

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎arch/powerpc/sysdev/qe_lib/ucc_fast.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
208208
uccf->uf_regs = ioremap(uf_info->regs, sizeof(struct ucc_fast));
209209
if (uccf->uf_regs == NULL) {
210210
printk(KERN_ERR "%s: Cannot map UCC registers\n", __func__);
211+
kfree(uccf);
211212
return -ENOMEM;
212213
}
213214

@@ -355,6 +356,9 @@ void ucc_fast_free(struct ucc_fast_private * uccf)
355356
if (uccf->ucc_fast_rx_virtual_fifo_base_offset)
356357
qe_muram_free(uccf->ucc_fast_rx_virtual_fifo_base_offset);
357358

359+
if (uccf->uf_regs)
360+
iounmap(uccf->uf_regs);
361+
358362
kfree(uccf);
359363
}
360364
EXPORT_SYMBOL(ucc_fast_free);

‎arch/powerpc/sysdev/qe_lib/ucc_slow.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** ucc
171171
uccs->us_regs = ioremap(us_info->regs, sizeof(struct ucc_slow));
172172
if (uccs->us_regs == NULL) {
173173
printk(KERN_ERR "%s: Cannot map UCC registers\n", __func__);
174+
kfree(uccs);
174175
return -ENOMEM;
175176
}
176177

@@ -367,10 +368,11 @@ void ucc_slow_free(struct ucc_slow_private * uccs)
367368
if (uccs->tx_base_offset)
368369
qe_muram_free(uccs->tx_base_offset);
369370

370-
if (uccs->us_pram) {
371+
if (uccs->us_pram)
371372
qe_muram_free(uccs->us_pram_offset);
372-
uccs->us_pram = NULL;
373-
}
373+
374+
if (uccs->us_regs)
375+
iounmap(uccs->us_regs);
374376

375377
kfree(uccs);
376378
}

0 commit comments

Comments
 (0)