[PATCH] check for null while iterating over a scatterlist table

From: Rajnikant Bhojani
Date: Tue Apr 25 2017 - 03:39:11 EST


during iterating over a scatterlist table also need to check for NULL
along with number of scatterlist

Signed-off-by: Rajnikant Bhojani <rajnikant.bhojani@xxxxxxxxxxxxxxxx>
---

include/linux/scatterlist.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index cb3c8fe..f8dce12 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -146,7 +146,7 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
* Loop over each sg element, following the pointer to a new list if necessary
*/
#define for_each_sg(sglist, sg, nr, __i) \
- for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))
+ for (__i = 0, sg = (sglist); __i < (nr) && sg; __i++, sg = sg_next(sg))

/**
* sg_chain - Chain two sglists together
--
2.7.4