All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laura Garcia Liebana <nevola@gmail.com>
To: outreachy-kernel@googlegroups.com
Subject: [PATCH] staging: netlogic: Return zero pointer after failed kmalloc
Date: Thu, 18 Feb 2016 18:38:42 +0100	[thread overview]
Message-ID: <20160218173839.GA9157@sonyv> (raw)

Return a ZERO_SIZE_PTR in the xlr_config_spill function if the
kmalloc returns an invalid value. This change prevents a possible
segmentation fault as the invalid pointer is fed into PTR_ALIGN macro.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
---
 drivers/staging/netlogic/xlr_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/netlogic/xlr_net.c b/drivers/staging/netlogic/xlr_net.c
index 98e74d7..0015847 100644
--- a/drivers/staging/netlogic/xlr_net.c
+++ b/drivers/staging/netlogic/xlr_net.c
@@ -437,8 +437,10 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
 	base = priv->base_addr;
 	spill_size = size;
 	spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
-	if (!spill)
+	if (!spill) {
 		pr_err("Unable to allocate memory for spill area!\n");
+		return ZERO_SIZE_PTR;
+	}
 
 	spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
 	phys_addr = virt_to_phys(spill);
-- 
2.7.0



             reply	other threads:[~2016-02-18 17:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18 17:38 Laura Garcia Liebana [this message]
2016-02-23 20:42 ` [Outreachy kernel] [PATCH] staging: netlogic: Return zero pointer after failed kmalloc Julia Lawall
2016-02-23 22:36   ` Laura Garcia
2016-02-24  9:23     ` Julia Lawall
2016-02-24 16:47       ` Laura Garcia
2016-02-24 16:55         ` Julia Lawall

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=20160218173839.GA9157@sonyv \
    --to=nevola@gmail.com \
    --cc=outreachy-kernel@googlegroups.com \
    /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.