Re: [PATCH v3] staging: vt6655: check for memory allocation failures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2018/3/30 10:44, Ji-Hun Kim wrote:
@@ -1165,10 +1205,18 @@ static int vnt_start(struct ieee80211_hw *hw)
  	}
dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
-	device_init_rd0_ring(priv);
-	device_init_rd1_ring(priv);
-	device_init_td0_ring(priv);
-	device_init_td1_ring(priv);
+	ret = device_init_rd0_ring(priv);
+	if (ret)
+		goto error;
+	ret = device_init_rd1_ring(priv);
+	if (ret)
+		goto error;
+	ret = device_init_td0_ring(priv);
+	if (ret)
+		goto error;
+	ret = device_init_td1_ring(priv);
+	if (ret)
+		goto error;
device_init_registers(priv); @@ -1178,6 +1226,8 @@ static int vnt_start(struct ieee80211_hw *hw)
  	ieee80211_wake_queues(hw);
return 0;
+error:
+	return ret;
  }

This code will lead to memory leaks when device_init_rd1_ring() fails, because the memory allocated by device_init_rd0_ring() is not freed.

I think this one will be better:
    ret = device_init_rd0_ring(priv);
    if (ret)
        goto error_init_rd0_ring;
    ret = device_init_rd1_ring(priv);
    if (ret)
        goto error_init_rd1_ring;
    ret = device_init_td0_ring(priv);
    if (ret)
        goto error_init_td0_ring;
    ret = device_init_td1_ring(priv);
    if (ret)
        goto error_init_td1_ring;
    ......
error_init_td1_ring:
    device_free_td0_ring(priv);
error_init_td0_ring:
    device_free_rd1_ring(priv);
error_init_rd1_ring:
    device_free_rd0_ring(priv);
error_init_rd0_ring:
    return ret;


Best wishes,
Jia-Ju Bai
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux