WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] linux-2.6.18/backends: use kzalloc() in favor of kma

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] linux-2.6.18/backends: use kzalloc() in favor of kmalloc()+memset()
From: "Jan Beulich" <JBeulich@xxxxxxxx>
Date: Fri, 16 Sep 2011 08:41:23 +0100
Delivery-date: Fri, 16 Sep 2011 00:42:26 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] linux-2.6.18/backends: use kzalloc() in favor of kmalloc()+memset(), Jan Beulich <=