[PATCH 2/2] virtio-rng: some small tidy ups around kmalloc

From: Stephen Rothwell
Date: Thu May 15 2014 - 01:34:15 EST


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

Signed-off-by: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxxx

Attachment: signature.asc
Description: PGP signature