From: Gilad Ben-Yossef <gilad@benyossef.com>
Date: Sun, 7 Jan 2018 12:14:25 +0000 (+0000)
Subject: staging: ccree: handle end of sg list gracefully
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6e92010b012116d10a3750c0406e3da67f274498;p=linux.git

staging: ccree: handle end of sg list gracefully

If we are asked for number of entries of an offset bigger than the
sg list we should not crash.

Cc: stable@vger.kernel.org
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c
index 78288ed75281e..0f7126404a32c 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -94,7 +94,7 @@ static unsigned int cc_get_sgl_nents(struct device *dev,
 {
 	unsigned int nents = 0;
 
-	while (nbytes) {
+	while (nbytes && sg_list) {
 		if (sg_list->length) {
 			nents++;
 			/* get the number of bytes in the last entry */