Skip to contentSkip to conversation

scsi: sd: cleanup gendisk if device_add_disk() failed

PATCH New Wenchao Hao 1 participant 1 message Mar 31, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sd: cleanup gendisk if device_add_disk() failed

We forget to call blk_cleanup_disk() when device_add_disk() failed. Which would cause memory leak of gendisk and sched_tags alloced in elevator_init_mq()

Reference:https://syzkaller.appspot.com/x/log.txt?x=13b41dcb700000

Reported-and-tested-by [email protected]
---
 drivers/scsi/sd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/sd.c +1 -0
index a390679cf458..4620a1158272 100644
@@ -3475,6 +3475,7 @@ static int sd_probe(struct device *dev)
 	error = device_add_disk(dev, gd, NULL);
 	if (error) {
 		put_device(&sdkp->disk_dev);
+		blk_cleanup_disk(gd);
 		goto out;
 	}
 
Signature · 1 line
2.32.0