All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch] PM / Hibernate: NULL dereferences on error paths
Date: Fri, 07 Oct 2011 13:24:53 +0000	[thread overview]
Message-ID: <20111007132453.GA31424@elgon.mountain> (raw)

These lines break if "data" is NULL.
	if (data[thr].thr)
		kthread_stop(data[thr].thr);
I rearranged it so the checks for NULL in the error handling code
aren't needed anymore.  And anyway both vfree() and free_page()
handle NULL pointers so the checks were redundant.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index d692842..32a17e0 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -528,15 +528,14 @@ static int save_image_lzo(struct swap_map_handle *handle,
 	page = (void *)__get_free_page(__GFP_WAIT | __GFP_HIGH);
 	if (!page) {
 		printk(KERN_ERR "PM: Failed to allocate LZO page\n");
-		ret = -ENOMEM;
-		goto out_clean;
+		return -ENOMEM;
 	}
 
 	data = vmalloc(sizeof(*data) * nr_threads);
 	if (!data) {
 		printk(KERN_ERR "PM: Failed to allocate LZO data\n");
 		ret = -ENOMEM;
-		goto out_clean;
+		goto out_page;
 	}
 	for (thr = 0; thr < nr_threads; thr++)
 		memset(&data[thr], 0, offsetof(struct cmp_data, go));
@@ -664,8 +663,9 @@ out_clean:
 		if (data[thr].thr)
 			kthread_stop(data[thr].thr);
 	}
-	if (data) vfree(data);
-	if (page) free_page((unsigned long)page);
+	vfree(data);
+out_page:
+	free_page((unsigned long)page);
 
 	return ret;
 }
@@ -978,15 +978,14 @@ static int load_image_lzo(struct swap_map_handle *handle,
 	page = vmalloc(sizeof(*page) * LZO_READ_PAGES);
 	if (!page) {
 		printk(KERN_ERR "PM: Failed to allocate LZO page\n");
-		error = -ENOMEM;
-		goto out_clean;
+		return -ENOMEM;
 	}
 
 	data = vmalloc(sizeof(*data) * nr_threads);
 	if (!data) {
 		printk(KERN_ERR "PM: Failed to allocate LZO data\n");
 		error = -ENOMEM;
-		goto out_clean;
+		goto out_page;
 	}
 	for (thr = 0; thr < nr_threads; thr++)
 		memset(&data[thr], 0, offsetof(struct dec_data, go));
@@ -1183,8 +1182,9 @@ out_clean:
 		if (data[thr].thr)
 			kthread_stop(data[thr].thr);
 	}
-	if (data) vfree(data);
-	if (page) vfree(page);
+	vfree(data);
+out_page:
+	vfree(page);
 
 	return error;
 }

             reply	other threads:[~2011-10-07 13:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-07 13:24 Dan Carpenter [this message]
2011-10-07 20:58 ` [patch] PM / Hibernate: NULL dereferences on error paths Bojan Smojver
2011-10-08 10:25 ` Bojan Smojver
2011-10-08 10:28 ` Bojan Smojver
2011-10-08 10:49 ` Dan Carpenter
2011-10-08 13:11 ` Bojan Smojver
2011-10-09 14:11 ` Dan Carpenter
2011-10-09 22:26 ` Bojan Smojver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111007132453.GA31424@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.