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

[Xen-devel] [PATCH] linux-2.6.18/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>

--- a/drivers/xen/blkback/blkback.c
+++ b/drivers/xen/blkback/blkback.c
@@ -633,7 +633,7 @@ static int __init blkif_init(void)
 
        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 @@ static int __init blkif_init(void)
 
        blkif_interface_init();
 
-       memset(pending_reqs, 0, sizeof(pending_reqs));
        INIT_LIST_HEAD(&pending_free);
 
        for (i = 0; i < blkif_reqs; i++)
--- a/drivers/xen/scsiback/emulate.c
+++ b/drivers/xen/scsiback/emulate.c
@@ -246,13 +246,11 @@ static void __report_luns(pending_req_t 
        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) {
--- a/drivers/xen/scsiback/scsiback.c
+++ b/drivers/xen/scsiback/scsiback.c
@@ -687,7 +687,7 @@ static int __init scsiback_init(void)
 
        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 @@ static int __init scsiback_init(void)
        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++)
--- a/drivers/xen/usbback/usbback.c
+++ b/drivers/xen/usbback/usbback.c
@@ -1105,7 +1105,7 @@ static int __init usbback_init(void)
                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 @@ static int __init usbback_init(void)
        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++)



Attachment: xen-backends-kzalloc.patch
Description: Text document

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

 


Rackspace

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