[PATCH 2/4] Bug Fix drivers/pci/intel-iommu.c: secure sg_next() calling

Fenghua Yu
2009-08-04T22:10:39Z

sg_next() is called only when sg is not NULL. This solves a kernel panic on
some platforms (e.g. ia64).

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>

---

drivers/pci/intel-iommu.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index bec29ed..54ee63d 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -1705,8 +1715,12 @@ static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
iov_pfn++;
pteval += VTD_PAGE_SIZE;
sg_res--;
- if (!sg_res)
- sg = sg_next(sg);
+ if (!sg_res) {
+ if (sg)
+ sg = sg_next(sg);
+ else
+ return 0;
+ }
}
return 0;
}