Skip to contentSkip to conversation

md: bcache: check the return value of kzalloc() in detached_dev_do_request()

PATCH In review Jia-Ju Bai 2 participants 2 messages Mar 3, 2022 – Apr 7, 2022 bcache (block layer cache)

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH v2 1/1 md: bcache: check the return value of kzalloc() in detached_dev_do_request()

The function kzalloc() in detached_dev_do_request() can fail, so its return value should be checked.

Fixes bc082a55d25c ("bcache: fix inaccurate io state for detached bcache devices")

---
v2:
* Fix the error handling code when ddip is NULL.
Thank Coly for good advice.

---
 drivers/md/bcache/request.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/md/bcache/request.c +6 -0
index d15aae6c51c1..673a680240a9 100644
@@ -1107,6 +1107,12 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
 	 * which would call closure_get(&dc->disk.cl)
 	 */
 	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
+	if (!ddip) {
+		bio->bi_status = BLK_STS_RESOURCE;
+		bio->bi_end_io(bio);
+		return;
+	}
+
 	ddip->d = d;
 	/* Count on the bcache device */
 	ddip->orig_bdev = orig_bdev;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 22 lines · Jia-Ju Bai

The function kzalloc() in detached_dev_do_request() can fail, so its return value should be checked.

Fixes bc082a55d25c ("bcache: fix inaccurate io state for detached bcache devices")

---
v2:
* Fix the error handling code when ddip is NULL.
Thank Coly for good advice.

---
  drivers/md/bcache/request.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/md/bcache/request.c +0 -0
index d15aae6c51c1..673a680240a9 100644
@@ -1107,6 +1107,12 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,
  	 * which would call closure_get(&dc->disk.cl)
  	 */

drivers/md/bcache/request.c static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, · line 1118

Quoted 10 lines
drivers/md/bcache/request.c +6 -0
  	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
+	if (!ddip) {
+		bio->bi_status = BLK_STS_RESOURCE;
+		bio->bi_end_io(bio);
+		return;
+	}
+
  	ddip->d = d;
  	/* Count on the bcache device */
  	ddip->orig_bdev = orig_bdev;

Added into my testing queue.

Thanks.

Coly Li