[PATCH 19/22] lib: scatterlist: don't assert last element for empty sglist
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Mar 13 00:34:42 PDT 2025
A BUG_ON in sg_last tries to verify that the last element in a scatter
gather list is indeed marked as such in its flags.
clang-analyzer warns that this would make the function fail for an empty
list, so let's add a NULL-check into the BUG_ON.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
lib/scatterlist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index f7b06013a552..6a4e1e91f8f1 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -105,7 +105,7 @@ struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents)
for_each_sg(sgl, sg, nents, i)
ret = sg;
- BUG_ON(!sg_is_last(ret));
+ BUG_ON(ret && !sg_is_last(ret));
return ret;
}
EXPORT_SYMBOL(sg_last);
--
2.39.5
More information about the barebox
mailing list