Commit 45577464 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix various memory leaks

From: Yury Umanets <torque@ukrpost.net>

Thanks to smatch I have found few memory leaks and other related issues.
parent 43b6594e
...@@ -612,7 +612,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd ...@@ -612,7 +612,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
uref = &uref_multi->uref; uref = &uref_multi->uref;
if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
if (copy_from_user(uref_multi, (void *) arg, if (copy_from_user(uref_multi, (void *) arg,
sizeof(uref_multi))) sizeof(*uref_multi)))
goto fault; goto fault;
} else { } else {
if (copy_from_user(uref, (void *) arg, sizeof(*uref))) if (copy_from_user(uref, (void *) arg, sizeof(*uref)))
......
...@@ -194,7 +194,7 @@ static int emi26_load_firmware (struct usb_device *dev) ...@@ -194,7 +194,7 @@ static int emi26_load_firmware (struct usb_device *dev)
/* return 1 to fail the driver inialization /* return 1 to fail the driver inialization
* and give real driver change to load */ * and give real driver change to load */
return 1; err = 1;
wraperr: wraperr:
kfree(buf); kfree(buf);
......
...@@ -229,6 +229,8 @@ static int emi62_load_firmware (struct usb_device *dev) ...@@ -229,6 +229,8 @@ static int emi62_load_firmware (struct usb_device *dev)
goto wraperr; goto wraperr;
} }
kfree(buf);
/* return 1 to fail the driver inialization /* return 1 to fail the driver inialization
* and give real driver change to load */ * and give real driver change to load */
return 1; return 1;
......
...@@ -1938,6 +1938,19 @@ int __init atyfb_init(void) ...@@ -1938,6 +1938,19 @@ int __init atyfb_init(void)
if (i < 0) if (i < 0)
continue; continue;
rp = &pdev->resource[0];
if (rp->flags & IORESOURCE_IO)
rp = &pdev->resource[1];
addr = rp->start;
if (!addr)
continue;
res_start = rp->start;
res_size = rp->end - rp->start + 1;
if (!request_mem_region
(res_start, res_size, "atyfb"))
continue;
info = info =
kmalloc(sizeof(struct fb_info), GFP_ATOMIC); kmalloc(sizeof(struct fb_info), GFP_ATOMIC);
if (!info) { if (!info) {
...@@ -1960,19 +1973,6 @@ int __init atyfb_init(void) ...@@ -1960,19 +1973,6 @@ int __init atyfb_init(void)
info->fix = atyfb_fix; info->fix = atyfb_fix;
info->par = default_par; info->par = default_par;
rp = &pdev->resource[0];
if (rp->flags & IORESOURCE_IO)
rp = &pdev->resource[1];
addr = rp->start;
if (!addr)
continue;
res_start = rp->start;
res_size = rp->end - rp->start + 1;
if (!request_mem_region
(res_start, res_size, "atyfb"))
continue;
#ifdef __sparc__ #ifdef __sparc__
/* /*
* Map memory-mapped registers. * Map memory-mapped registers.
...@@ -2000,6 +2000,7 @@ int __init atyfb_init(void) ...@@ -2000,6 +2000,7 @@ int __init atyfb_init(void)
if (!default_par->mmap_map) { if (!default_par->mmap_map) {
printk printk
("atyfb_init: can't alloc mmap_map\n"); ("atyfb_init: can't alloc mmap_map\n");
kfree(default_par);
kfree(info); kfree(info);
release_mem_region(res_start, res_size); release_mem_region(res_start, res_size);
return -ENXIO; return -ENXIO;
...@@ -2217,6 +2218,9 @@ int __init atyfb_init(void) ...@@ -2217,6 +2218,9 @@ int __init atyfb_init(void)
ioremap(info->fix.mmio_start, 0x1000); ioremap(info->fix.mmio_start, 0x1000);
if (!default_par->ati_regbase) { if (!default_par->ati_regbase) {
#ifdef __sparc__
kfree(default_par->mmap_map);
#endif
kfree(default_par); kfree(default_par);
kfree(info); kfree(info);
release_mem_region(res_start, res_size); release_mem_region(res_start, res_size);
...@@ -2247,6 +2251,10 @@ int __init atyfb_init(void) ...@@ -2247,6 +2251,10 @@ int __init atyfb_init(void)
(char *) ioremap(addr, 0x800000); (char *) ioremap(addr, 0x800000);
if (!info->screen_base) { if (!info->screen_base) {
#ifdef __sparc__
kfree(default_par->mmap_map);
#endif
kfree(default_par);
kfree(info); kfree(info);
release_mem_region(res_start, res_size); release_mem_region(res_start, res_size);
return -ENXIO; return -ENXIO;
...@@ -2258,6 +2266,7 @@ int __init atyfb_init(void) ...@@ -2258,6 +2266,7 @@ int __init atyfb_init(void)
if (default_par->mmap_map) if (default_par->mmap_map)
kfree(default_par->mmap_map); kfree(default_par->mmap_map);
#endif #endif
kfree(default_par);
kfree(info); kfree(info);
release_mem_region(res_start, res_size); release_mem_region(res_start, res_size);
return -ENXIO; return -ENXIO;
...@@ -2326,6 +2335,7 @@ int __init atyfb_init(void) ...@@ -2326,6 +2335,7 @@ int __init atyfb_init(void)
memset(default_par, 0, sizeof(struct atyfb_par)); memset(default_par, 0, sizeof(struct atyfb_par));
info->fix = atyfb_fix; info->fix = atyfb_fix;
info->par = default_par;
/* /*
* Map the video memory (physical address given) to somewhere in the * Map the video memory (physical address given) to somewhere in the
...@@ -2357,6 +2367,7 @@ int __init atyfb_init(void) ...@@ -2357,6 +2367,7 @@ int __init atyfb_init(void)
} }
if (!aty_init(info, "ISA bus")) { if (!aty_init(info, "ISA bus")) {
kfree(default_par);
kfree(info); kfree(info);
/* This is insufficient! kernel_map has added two large chunks!! */ /* This is insufficient! kernel_map has added two large chunks!! */
return -ENXIO; return -ENXIO;
......
...@@ -721,8 +721,10 @@ static int ircomm_tty_write(struct tty_struct *tty, int from_user, ...@@ -721,8 +721,10 @@ static int ircomm_tty_write(struct tty_struct *tty, int from_user,
kbuf = kmalloc(count, GFP_KERNEL); kbuf = kmalloc(count, GFP_KERNEL);
if (kbuf == NULL) if (kbuf == NULL)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(kbuf, ubuf, count)) if (copy_from_user(kbuf, ubuf, count)) {
kfree(kbuf);
return -EFAULT; return -EFAULT;
}
} else } else
/* The buffer is already in kernel space */ /* The buffer is already in kernel space */
kbuf = (unsigned char *) ubuf; kbuf = (unsigned char *) ubuf;
...@@ -779,6 +781,8 @@ static int ircomm_tty_write(struct tty_struct *tty, int from_user, ...@@ -779,6 +781,8 @@ static int ircomm_tty_write(struct tty_struct *tty, int from_user,
self->max_header_size); self->max_header_size);
if (!skb) { if (!skb) {
spin_unlock_irqrestore(&self->spinlock, flags); spin_unlock_irqrestore(&self->spinlock, flags);
if (from_user)
kfree(kbuf);
return -ENOBUFS; return -ENOBUFS;
} }
skb_reserve(skb, self->max_header_size); skb_reserve(skb, self->max_header_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment