Skip to contentSkip to conversation

linux-2.6.18/backends: use kzalloc() in favor of kmalloc()+memset()

PATCH New Jan Beulich 1 participant 1 message Sep 16, 2011 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

drivers/xen/blkback/blkback.c +1 -2
@@ -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++)
drivers/xen/scsiback/emulate.c +1 -3
@@ -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) {
drivers/xen/scsiback/scsiback.c +1 -2
@@ -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++)
drivers/xen/usbback/usbback.c +1 -2
@@ -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++)

Subject: 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.

drivers/xen/blkback/blkback.c +1 -2
@@ -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++)
drivers/xen/scsiback/emulate.c +1 -3
@@ -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) {
drivers/xen/scsiback/scsiback.c +1 -2
@@ -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++)
drivers/xen/usbback/usbback.c +1 -2
@@ -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++)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel