iommu/amd: Implement dm_region call-backs
Hello Joerg Roedel,
The patch b61238c4a5e1: "iommu/amd: Implement dm_region call-backs" from May 28, 2015, leads to the following static checker warning:
drivers/iommu/amd_iommu.c:3153 amd_iommu_get_dm_regions() error: potential null dereference 'region'. (kzalloc returns null)
drivers/iommu/amd_iommu.c
3138 static void amd_iommu_get_dm_regions(struct device *dev,
3139 struct list_head *head)
3140 {
3141 struct unity_map_entry *entry;
3142 u16 devid;
3143
3144 devid = get_device_id(dev);
3145
3146 list_for_each_entry(entry, &amd_iommu_unity_map, list) {
3147 struct iommu_dm_region *region;
3148
3149 if (devid < entry->devid_start || devid > entry->devid_end)
3150 continue;
3151
3152 region = kzalloc(sizeof(*region), GFP_KERNEL);
No check here. We may not care and in that case just ignore this email. Or add GFP_NOFAIL to silence the warning if you want.
3153 region->start = entry->address_start; 3154 region->length = entry->address_end - entry->address_start; 3155 if (entry->prot & IOMMU_PROT_IR)
3156 region->prot |= IOMMU_READ;
3157 if (entry->prot & IOMMU_PROT_IW)
3158 region->prot |= IOMMU_WRITE;
3159
3160 list_add_tail(®ion->list, head);
3161 }
3162 }
regards,
dan carpenter
Quoted 7 lines · Dan Carpenter
Hello Joerg Roedel,
The patch
b61238c4a5e1: "iommu/amd: Implementdm_regioncall-backs" from May 28, 2015, leads to the following static checker warning:drivers/iommu/amd_iommu.c:3153 amd_iommu_get_dm_regions() error: potential null dereference 'region'. (kzalloc returns null)
Thanks for the report, I added a check for the return value and folded it back into the original patch.
What static checker do you use, btw?
Joerg
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Joerg Roedel
Quoted 5 lines · Dan Carpenter
Hello Joerg Roedel,
The patch
b61238c4a5e1: "iommu/amd: Implementdm_regioncall-backs" from May 28, 2015, leads to the following static checker warning:
Quoted 7 lines
Quoted 2 lines
drivers/iommu/amd_iommu.c:3153 amd_iommu_get_dm_regions() error: potential null dereference 'region'. (kzalloc returns null)Thanks for the report, I added a check for the return value and folded it back into the original patch.
What static checker do you use, btw?
I'm using Smatch.
The ERR_PTR stuff requires that you run
smatch_scripts/build_kernel_data.sh
At the start and that takes a couple hours.
regards,
dan carpenter
Quoted 10 lines · Dan Carpenter
Quoted 1 line · Joerg Roedel
What static checker do you use, btw?
I'm using Smatch.
The
ERR_PTRstuff requires that you run
smatch_scripts/build_kernel_data.shAt the start and that takes a couple hours.
I see, thanks.