[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] xen/backends: use kzalloc() in favor of kmalloc()+memset()



# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxxxx>
# Date 1316273342 -3600
# Node ID f4f25124b1b6d926b6e19a499bf4a3fdc97f0157
# Parent  700f70b60d4b50e04228e54bf636ec882bf54968
xen/backends: use kzalloc() in favor of kmalloc()+memset()

This fixes the problem of three of those four memset()-s having
improper size arguments passed: Sizeof a pointer-typed expression
returns the size of the pointer, not that of the pointed to data.

Reported-by: Julia Lawall <julia@xxxxxxx>
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>
---


diff -r 700f70b60d4b -r f4f25124b1b6 drivers/xen/blkback/blkback.c
--- a/drivers/xen/blkback/blkback.c     Sat Aug 27 12:12:38 2011 +0100
+++ b/drivers/xen/blkback/blkback.c     Sat Sep 17 16:29:02 2011 +0100
@@ -633,7 +633,7 @@
 
        mmap_pages = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
 
-       pending_reqs          = kmalloc(sizeof(pending_reqs[0]) *
+       pending_reqs          = kzalloc(sizeof(pending_reqs[0]) *
                                        blkif_reqs, GFP_KERNEL);
        pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
                                        mmap_pages, GFP_KERNEL);
@@ -650,7 +650,6 @@
 
        blkif_interface_init();
 
-       memset(pending_reqs, 0, sizeof(pending_reqs));
        INIT_LIST_HEAD(&pending_free);
 
        for (i = 0; i < blkif_reqs; i++)
diff -r 700f70b60d4b -r f4f25124b1b6 drivers/xen/scsiback/emulate.c
--- a/drivers/xen/scsiback/emulate.c    Sat Aug 27 12:12:38 2011 +0100
+++ b/drivers/xen/scsiback/emulate.c    Sat Sep 17 16:29:02 2011 +0100
@@ -246,13 +246,11 @@
        alloc_len  = sizeof(struct scsi_lun) * alloc_luns
                                + VSCSI_REPORT_LUNS_HEADER;
 retry:
-       if ((buff = kmalloc(alloc_len, GFP_KERNEL)) == NULL) {
+       if ((buff = kzalloc(alloc_len, GFP_KERNEL)) == NULL) {
                printk(KERN_ERR "scsiback:%s kmalloc err\n", __FUNCTION__);
                goto fail;
        }
 
-       memset(buff, 0, alloc_len);
-
        one_lun = (struct scsi_lun *) &buff[8];
        spin_lock_irqsave(&info->v2p_lock, flags);
        list_for_each_entry(entry, head, l) {
diff -r 700f70b60d4b -r f4f25124b1b6 drivers/xen/scsiback/scsiback.c
--- a/drivers/xen/scsiback/scsiback.c   Sat Aug 27 12:12:38 2011 +0100
+++ b/drivers/xen/scsiback/scsiback.c   Sat Sep 17 16:29:02 2011 +0100
@@ -687,7 +687,7 @@
 
        mmap_pages = vscsiif_reqs * VSCSIIF_SG_TABLESIZE;
 
-       pending_reqs          = kmalloc(sizeof(pending_reqs[0]) *
+       pending_reqs          = kzalloc(sizeof(pending_reqs[0]) *
                                        vscsiif_reqs, GFP_KERNEL);
        pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
                                        mmap_pages, GFP_KERNEL);
@@ -702,7 +702,6 @@
        if (scsiback_interface_init() < 0)
                goto out_of_kmem;
 
-       memset(pending_reqs, 0, sizeof(pending_reqs));
        INIT_LIST_HEAD(&pending_free);
 
        for (i = 0; i < vscsiif_reqs; i++)
diff -r 700f70b60d4b -r f4f25124b1b6 drivers/xen/usbback/usbback.c
--- a/drivers/xen/usbback/usbback.c     Sat Aug 27 12:12:38 2011 +0100
+++ b/drivers/xen/usbback/usbback.c     Sat Sep 17 16:29:02 2011 +0100
@@ -1105,7 +1105,7 @@
                return -ENODEV;
 
        mmap_pages = usbif_reqs * USBIF_MAX_SEGMENTS_PER_REQUEST;
-       pending_reqs = kmalloc(sizeof(pending_reqs[0]) *
+       pending_reqs = kzalloc(sizeof(pending_reqs[0]) *
                        usbif_reqs, GFP_KERNEL);
        pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
                        mmap_pages, GFP_KERNEL);
@@ -1119,7 +1119,6 @@
        for (i = 0; i < mmap_pages; i++)
                pending_grant_handles[i] = USBBACK_INVALID_HANDLE;
 
-       memset(pending_reqs, 0, sizeof(pending_reqs));
        INIT_LIST_HEAD(&pending_free);
 
        for (i = 0; i < usbif_reqs; i++)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.