Skip to contentSkip to conversation

scsi: scsi_transport_fc: fix possible memory leak

PATCH New Yang Yingliang 1 participant 1 message Nov 2, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsi_transport_fc: fix possible memory leak

Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array"), the name of device is allocated dynamically, it need be freed if device_add(dev) returns error, as comment of device_add() says, it should call put_device() to drop the reference on error.

Fix it by calling put_device(dev) so that the name can be freed in kobject_cleanup(). In fc_rport_dev_release() and fc_vport_dev_release(), it will put refcount of dev->parent and free the port, so the release code of them in error path can be removed.

Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 drivers/scsi/scsi_transport_fc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/scsi_transport_fc.c +2 -4
index 8934160c4a33..97f62db0ad31 100644
@@ -3129,8 +3129,7 @@ fc_remote_port_create(struct Scsi_Host *shost, int channel,
 	list_del(&rport->peers);
 	scsi_host_put(shost);			/* for fc_host->rport list */
 	spin_unlock_irqrestore(shost->host_lock, flags);
-	put_device(dev->parent);
-	kfree(rport);
+	put_device(dev);
 	return NULL;
 }
 
@@ -3930,8 +3929,7 @@ fc_vport_setup(struct Scsi_Host *shost, int channel, struct device *pdev,
 	scsi_host_put(shost);			/* for fc_host->vport list */
 	fc_host->npiv_vports_inuse--;
 	spin_unlock_irqrestore(shost->host_lock, flags);
-	put_device(dev->parent);
-	kfree(vport);
+	put_device(dev);
 
 	return error;
 }
Signature · 1 line
2.25.1