@@ -241,8 +241,13 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
int i, ents;
struct scatterlist *s;
- for_each_sg(sg, s, nents, i)
- kmemcheck_mark_initialized(sg_virt(s), s->length);
+ for_each_sg(sg, s, nents, i) {
+ void *addr = sg_try_virt(sg);
+
+ if (addr)
+ kmemcheck_mark_initialized(addr, s->length);
+ }
+
BUG_ON(!valid_dma_direction(dir));
ents = ops->map_sg(dev, sg, nents, dir, attrs);
BUG_ON(ents < 0);
@@ -298,6 +298,22 @@ static inline void *sg_virt(struct scatterlist *sg)
return page_address(sg_page(sg)) + sg->offset;
}
+/**
+ * sg_try_virt - Return virtual address of an sg entry or NULL if it is
+ * unmappable
+ * @sg: SG entry
+ *
+ * Description:
+ * This is the same as sg_virt but is safe to call with unmappable
+ * memory. This function will return NULL in case the sg is is
+ * unmappable.
+ *
+ **/
+static inline void *sg_try_virt(struct scatterlist *sg)
+{
+ return pfn_t_to_virt(sg->__pfn);
+}
+
int sg_nents(struct scatterlist *sg);
int sg_nents_for_len(struct scatterlist *sg, u64 len);
struct scatterlist *sg_next(struct scatterlist *);