From fd7f57ccd3a6b27aad34b2356a57a6a8a34c71e2 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Thu, 9 Jul 2015 14:50:22 -0700 Subject: [PATCH] iommu/iommu-debug: Initialize debug device to 0 Currently the debug device structure is allocated with kmalloc, without initializing all of the fields in the structure. Later, those fields might be uses before they've every been assigned. For example, if a user executes the following code on a fresh boot: # cd /sys/kernel/debug/iommu/tests/some_device # echo 0 > attach The kernel crashes with something like this (assuming page poisoning is enabled): Unable to handle kernel paging request at virtual address aaaaaaaaaaaaaaaa pgd = ffffffc0a92a1000 [aaaaaaaaaaaaaaaa] *pgd=0000000000000000, *pud=0000000000000000 Fix this by initializing all the fields in the structure to 0 by using kzalloc instead of kmalloc. Change-Id: I3514bf7bf174e176ff7a310c7134d0f53e22d771 Signed-off-by: Mitchel Humpherys --- drivers/iommu/iommu-debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c index 72ebbac55b77..43c89697b5f4 100644 --- a/drivers/iommu/iommu-debug.c +++ b/drivers/iommu/iommu-debug.c @@ -673,7 +673,7 @@ static int snarf_iommu_devices(struct device *dev, void *ignored) if (!of_find_property(dev->of_node, "iommus", NULL)) return 0; - ddev = kmalloc(sizeof(*ddev), GFP_KERNEL); + ddev = kzalloc(sizeof(*ddev), GFP_KERNEL); if (!ddev) return -ENODEV; ddev->dev = dev;