Messages in this thread Patch in this message | | | Date | Thu, 15 May 2014 15:33:42 +1000 | From | Stephen Rothwell <> | Subject | [PATCH 2/2] virtio-rng: some small tidy ups around kmalloc |
| |
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 [unhandled content-type:application/pgp-signature] | |