Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Timur Tabi and committed by
Kumar Gala
61a4e9e9 d27a736c

+9 -3
+4
arch/powerpc/sysdev/qe_lib/ucc_fast.c
··· 208 208 uccf->uf_regs = ioremap(uf_info->regs, sizeof(struct ucc_fast)); 209 209 if (uccf->uf_regs == NULL) { 210 210 printk(KERN_ERR "%s: Cannot map UCC registers\n", __func__); 211 + kfree(uccf); 211 212 return -ENOMEM; 212 213 } 213 214 ··· 355 354 356 355 if (uccf->ucc_fast_rx_virtual_fifo_base_offset) 357 356 qe_muram_free(uccf->ucc_fast_rx_virtual_fifo_base_offset); 357 + 358 + if (uccf->uf_regs) 359 + iounmap(uccf->uf_regs); 358 360 359 361 kfree(uccf); 360 362 }
+5 -3
arch/powerpc/sysdev/qe_lib/ucc_slow.c
··· 171 171 uccs->us_regs = ioremap(us_info->regs, sizeof(struct ucc_slow)); 172 172 if (uccs->us_regs == NULL) { 173 173 printk(KERN_ERR "%s: Cannot map UCC registers\n", __func__); 174 + kfree(uccs); 174 175 return -ENOMEM; 175 176 } 176 177 ··· 368 367 if (uccs->tx_base_offset) 369 368 qe_muram_free(uccs->tx_base_offset); 370 369 371 - if (uccs->us_pram) { 370 + if (uccs->us_pram) 372 371 qe_muram_free(uccs->us_pram_offset); 373 - uccs->us_pram = NULL; 374 - } 372 + 373 + if (uccs->us_regs) 374 + iounmap(uccs->us_regs); 375 375 376 376 kfree(uccs); 377 377 }