Skip to contentSkip to conversation

block: add NULL argument check to bioset_free()

PATCH New Tobin C. Harding 1 participant 1 message Oct 2, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: add NULL argument check to bioset_free()

Currently bioset_free() will oops if passed a NULL argument. Other kernel 'free' functions typically check for NULL arguments and return. The rule of least surprise dictates that bioset_free() should behave safely even if passed a NULL argument.

Add NULL argument check to bioset_free().

---

 block/bio.c | 3 +++
 1 file changed, 3 insertions(+)
block/bio.c +3 -0
index b38e962..780aecc 100644
@@ -1925,6 +1925,9 @@ mempool_t *biovec_create_pool(int pool_entries)
 
 void bioset_free(struct bio_set *bs)
 {
+	if (unlikely(!bs))
+		return;
+
 	if (bs->rescue_workqueue)
 		destroy_workqueue(bs->rescue_workqueue);
 
Signature · 1 line
2.7.4