Skip to contentSkip to conversation

scsi: hisi_sas: Add a missing call to kfree

PATCH In review Quentin Lambert 2 participants 6 messages Nov 19, 2016 – Nov 21, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: hisi_sas: Add a missing call to kfree

Most error branches following the call to hisi_sas_shost_alloc contain a call to kfree. This patch add these calls where they are missing.

This issue was found with Hector.

---
 drivers/scsi/hisi_sas/hisi_sas_main.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +4 -2
@@ -1503,8 +1503,10 @@ int hisi_sas_probe(struct platform_devic
 
 	arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
 	arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
-	if (!arr_phy || !arr_port)
-		return -ENOMEM;
+	if (!arr_phy || !arr_port) {
+		rc = -ENOMEM;
+		goto err_out_ha;
+	}
 
 	sha->sas_phy = arr_phy;
 	sha->sas_port = arr_port;
#1 lore raw
Quoted 5 lines · Quentin Lambert

Most error branches following the call to hisi_sas_shost_alloc contain a call to kfree. This patch add these calls where they are missing.

This issue was found with Hector.

I think that this patch is fine. However I have noticed that we should do a call to hisi_sas_free() for this failure, and later failures in the probe.

I can generate a patch for this.

Cheers,
John

Quoted 25 lines
---
 drivers/scsi/hisi_sas/hisi_sas_main.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +4 -2
@@ -1503,8 +1503,10 @@ int hisi_sas_probe(struct platform_devic
 
 	arr_phy = devm_kcalloc(dev, phy_nr, sizeof(void *), GFP_KERNEL);
 	arr_port = devm_kcalloc(dev, port_nr, sizeof(void *), GFP_KERNEL);
-	if (!arr_phy || !arr_port)
-		return -ENOMEM;
+	if (!arr_phy || !arr_port) {
+		rc = -ENOMEM;
+		goto err_out_ha;
+	}
 
 	sha->sas_phy = arr_phy;
 	sha->sas_port = arr_port;

.

#2 lore raw
Quoted 2 lines · John Garry

However I have noticed that we should do a call to hisi_sas_free() for this failure, and later failures in the probe.

I don't understand why, and would welcome the opportunity to learn something.

Quentin

#3 lore raw
Quoted 8 lines · Quentin Lambert
Quoted 2 lines · John Garry

However I have noticed that we should do a call to hisi_sas_free() for this failure, and later failures in the probe.

I don't understand why, and would welcome the opportunity to learn something.

We call hisi_sas_alloc() from hisi_sas_shost_alloc(); if we fail after this in hisi_sas_probe(), then we should free the memmories and workqueue got in hisi_sas_alloc(), which we don't.

Thanks,
John

Quoted 4 lines

Quentin

#4 lore raw
Quoted 6 lines · John Garry
Quoted 5 lines · Quentin Lambert
Quoted 2 lines · John Garry

However I have noticed that we should do a call to hisi_sas_free() for this failure, and later failures in the probe.

Quoted 7 lines
Quoted 3 lines

I don't understand why, and would welcome the opportunity to learn something.

We call hisi_sas_alloc() from hisi_sas_shost_alloc(); if we fail after this in hisi_sas_probe(), then we should free the memmories and workqueue got in hisi_sas_alloc(), which we don't.

Thanks.
Are you writing the patch or do you want me to do it?

Quentin

#5 lore raw
Quoted 12 lines · Quentin Lambert
Quoted 10 lines · John Garry
Quoted 8 lines · Quentin Lambert
Quoted 2 lines · John Garry

However I have noticed that we should do a call to hisi_sas_free() for this failure, and later failures in the probe.

I don't understand why, and would welcome the opportunity to learn something.

Quoted 6 lines
Quoted 3 lines

We call hisi_sas_alloc() from hisi_sas_shost_alloc(); if we fail after this in hisi_sas_probe(), then we should free the memmories and workqueue got in hisi_sas_alloc(), which we don't.

Thanks.
Are you writing the patch or do you want me to do it?

We can do it, thanks.

Quoted 3 lines

Quentin