mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Amos Kong <akong@redhat.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] virtio-rng: some small tidy ups around kmalloc
Date: Thu, 15 May 2014 15:33:42 +1000	[thread overview]
Message-ID: <20140515153342.14a5d34b@canb.auug.org.au> (raw)
In-Reply-To: <20140515153140.49b8028b@canb.auug.org.au>

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

Include slab.h for kmalloc/kfree declaration and check the actual
allocations succeed.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 drivers/char/hw_random/virtio-rng.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 6319b133b7aa..73d7fc42d1a7 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -24,6 +24,7 @@
 #include <linux/virtio.h>
 #include <linux/virtio_rng.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 
 
 struct virtrng_info {
@@ -97,7 +98,13 @@ static int probe_common(struct virtio_device *vdev)
 	char *name;
 
 	vi = kmalloc(sizeof(struct virtrng_info), GFP_KERNEL);
+	if (!vi)
+		return -ENOMEM;
 	name = kmalloc(40, GFP_KERNEL);
+	if (!name) {
+		kfree(vi);
+		return -ENOMEM;
+	}
 	vi->hwrng.name = name;
 	init_completion(&vi->have_data);
 
-- 
2.0.0.rc2

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2014-05-15  5:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-15  5:31 [PATCH 1/2] virtio-rng: cope if struct hwrng.name is changed to const Stephen Rothwell
2014-05-15  5:33 ` Stephen Rothwell [this message]
2014-05-19  0:00 ` Rusty Russell
2014-05-19  1:55   ` Stephen Rothwell

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=20140515153342.14a5d34b@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=akong@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®