Skip to contentSkip to conversation

virtio-rng: cope if struct hwrng.name is changed to const

PATCH In review Stephen Rothwell 2 participants 4 messages May 15, 2014 – May 19, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 virtio-rng: cope if struct hwrng.name is changed to const

---
 drivers/char/hw_random/virtio-rng.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Based on the current virtio tree in linux-next.

drivers/char/hw_random/virtio-rng.c +4 -2
index 12e242bbb0f5..6319b133b7aa 100644
@@ -94,9 +94,11 @@ static int probe_common(struct virtio_device *vdev)
 {
 	int err, i;
 	struct virtrng_info *vi = NULL;
+	char *name;
 
 	vi = kmalloc(sizeof(struct virtrng_info), GFP_KERNEL);
-	vi->hwrng.name = kmalloc(40, GFP_KERNEL);
+	name = kmalloc(40, GFP_KERNEL);
+	vi->hwrng.name = name;
 	init_completion(&vi->have_data);
 
 	vi->hwrng.read = virtio_read;
@@ -117,7 +119,7 @@ static int probe_common(struct virtio_device *vdev)
 
 	i = 0;
 	do {
-		sprintf(vi->hwrng.name, "virtio_rng.%d", i++);
+		sprintf(name, "virtio_rng.%d", i++);
 		err = hwrng_register(&vi->hwrng);
 	} while (err == -EEXIST);
 
Signature · 5 lines
2.0.0.rc2

-- 
Cheers,
Stephen Rothwell                    [email protected]
#1 lore raw

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

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

---
 drivers/char/hw_random/virtio-rng.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
index 6319b133b7aa..73d7fc42d1a7 100644
@@ -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);
 
Signature · 5 lines
2.0.0.rc2

-- 
Cheers,
Stephen Rothwell                    [email protected]
#2 lore raw
In reply to Stephen Rothwell
Quoted 6 lines · Stephen Rothwell
---
 drivers/char/hw_random/virtio-rng.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Based on the current virtio tree in linux-next.

Actually, Sasha Levin did a nice cleanup which replaces these two, and restores the const.

I've applied them, so you should have it in today's linux-next.

Thanks,
Rusty.

#3 lore raw

Hi Rusty,

Quoted 7 lines · On Mon, 19 May 2014 09:30:53 +0930 Rusty Russell <[email protected]> wrote:
Quoted 5 lines · Stephen Rothwell
---
 drivers/char/hw_random/virtio-rng.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 1 line

Based on the current virtio tree in linux-next.

Actually, Sasha Levin did a nice cleanup which replaces these two, and restores the const.

I've applied them, so you should have it in today's linux-next.

Yep, saw that. Thanks.

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]