* [PATCH v4 1/2] staging: vt6655: check for memory allocation failures [not found] <CGME20180330055207epcas1p14d562f44802bac86a8a7cd95fe2d009f@epcas1p1.samsung.com> @ 2018-03-30 5:51 ` Ji-Hun Kim [not found] ` <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com> ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Ji-Hun Kim @ 2018-03-30 5:51 UTC (permalink / raw) To: gregkh, baijiaju1990, forest Cc: devel, y.k.oh, kernel-janitors, linux-kernel, julia.lawall, ji_hun.kim, santhameena13 There are no null pointer checking on rd_info and td_info values which are allocated by kzalloc. It has potential null pointer dereferencing issues. Implement error handling code on device_init_rd*, device_init_td* and vnt_start for the allocation failures. Signed-off-by: Ji-Hun Kim <ji_hun.kim@samsung.com> --- Changes v2: - Delete WARN_ON which can makes crashes on some machines. - Instead of return directly, goto freeing function for freeing previously allocated memory in the for loop after kzalloc() failed. - In the freeing function, add if statement for freeing to only allocated values. Changes v3: - Modify return type of device_init_rd*, device_init_td*. Then add returns error code at those functions and vnt_start as well. Changes v4: - Fix potential memory leaks from error handling code of device init functions in vnt_start(). drivers/staging/vt6655/device_main.c | 121 ++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 32 deletions(-) diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index fbc4bc6..c9752df 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -124,10 +124,10 @@ static void device_free_info(struct vnt_private *priv); static void device_print_info(struct vnt_private *priv); -static void device_init_rd0_ring(struct vnt_private *priv); -static void device_init_rd1_ring(struct vnt_private *priv); -static void device_init_td0_ring(struct vnt_private *priv); -static void device_init_td1_ring(struct vnt_private *priv); +static int device_init_rd0_ring(struct vnt_private *priv); +static int device_init_rd1_ring(struct vnt_private *priv); +static int device_init_td0_ring(struct vnt_private *priv); +static int device_init_td1_ring(struct vnt_private *priv); static int device_rx_srv(struct vnt_private *priv, unsigned int idx); static int device_tx_srv(struct vnt_private *priv, unsigned int idx); @@ -528,18 +528,22 @@ static void device_free_rings(struct vnt_private *priv) priv->tx0_bufs, priv->tx_bufs_dma0); } -static void device_init_rd0_ring(struct vnt_private *priv) +static int device_init_rd0_ring(struct vnt_private *priv) { int i; dma_addr_t curr = priv->rd0_pool_dma; struct vnt_rx_desc *desc; + int ret = 0; /* Init the RD0 ring entries */ for (i = 0; i < priv->opts.rx_descs0; i ++, curr += sizeof(struct vnt_rx_desc)) { desc = &priv->aRD0Ring[i]; desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL); - + if (!desc->rd_info) { + ret = -ENOMEM; + goto error; + } if (!device_alloc_rx_buf(priv, desc)) dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); @@ -550,20 +554,29 @@ static void device_init_rd0_ring(struct vnt_private *priv) if (i > 0) priv->aRD0Ring[i-1].next_desc = cpu_to_le32(priv->rd0_pool_dma); priv->pCurrRD[0] = &priv->aRD0Ring[0]; + + return 0; +error: + device_free_rd0_ring(priv); + return ret; } -static void device_init_rd1_ring(struct vnt_private *priv) +static int device_init_rd1_ring(struct vnt_private *priv) { int i; dma_addr_t curr = priv->rd1_pool_dma; struct vnt_rx_desc *desc; + int ret = 0; /* Init the RD1 ring entries */ for (i = 0; i < priv->opts.rx_descs1; i ++, curr += sizeof(struct vnt_rx_desc)) { desc = &priv->aRD1Ring[i]; desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL); - + if (!desc->rd_info) { + ret = -ENOMEM; + goto error; + } if (!device_alloc_rx_buf(priv, desc)) dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); @@ -574,6 +587,11 @@ static void device_init_rd1_ring(struct vnt_private *priv) if (i > 0) priv->aRD1Ring[i-1].next_desc = cpu_to_le32(priv->rd1_pool_dma); priv->pCurrRD[1] = &priv->aRD1Ring[0]; + + return 0; +error: + device_free_rd1_ring(priv); + return ret; } static void device_free_rd0_ring(struct vnt_private *priv) @@ -584,12 +602,12 @@ static void device_free_rd0_ring(struct vnt_private *priv) struct vnt_rx_desc *desc = &priv->aRD0Ring[i]; struct vnt_rd_info *rd_info = desc->rd_info; - dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, - priv->rx_buf_sz, DMA_FROM_DEVICE); - - dev_kfree_skb(rd_info->skb); - - kfree(desc->rd_info); + if (rd_info) { + dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, + priv->rx_buf_sz, DMA_FROM_DEVICE); + dev_kfree_skb(rd_info->skb); + kfree(desc->rd_info); + } } } @@ -601,27 +619,31 @@ static void device_free_rd1_ring(struct vnt_private *priv) struct vnt_rx_desc *desc = &priv->aRD1Ring[i]; struct vnt_rd_info *rd_info = desc->rd_info; - dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, - priv->rx_buf_sz, DMA_FROM_DEVICE); - - dev_kfree_skb(rd_info->skb); - - kfree(desc->rd_info); + if (rd_info) { + dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, + priv->rx_buf_sz, DMA_FROM_DEVICE); + dev_kfree_skb(rd_info->skb); + kfree(desc->rd_info); + } } } -static void device_init_td0_ring(struct vnt_private *priv) +static int device_init_td0_ring(struct vnt_private *priv) { int i; dma_addr_t curr; struct vnt_tx_desc *desc; + int ret = 0; curr = priv->td0_pool_dma; for (i = 0; i < priv->opts.tx_descs[0]; i++, curr += sizeof(struct vnt_tx_desc)) { desc = &priv->apTD0Rings[i]; desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL); - + if (!desc->td_info) { + ret = -ENOMEM; + goto error; + } desc->td_info->buf = priv->tx0_bufs + i * PKT_BUF_SZ; desc->td_info->buf_dma = priv->tx_bufs_dma0 + i * PKT_BUF_SZ; @@ -632,13 +654,19 @@ static void device_init_td0_ring(struct vnt_private *priv) if (i > 0) priv->apTD0Rings[i-1].next_desc = cpu_to_le32(priv->td0_pool_dma); priv->apTailTD[0] = priv->apCurrTD[0] = &priv->apTD0Rings[0]; + + return 0; +error: + device_free_td0_ring(priv); + return ret; } -static void device_init_td1_ring(struct vnt_private *priv) +static int device_init_td1_ring(struct vnt_private *priv) { int i; dma_addr_t curr; struct vnt_tx_desc *desc; + int ret = 0; /* Init the TD ring entries */ curr = priv->td1_pool_dma; @@ -646,7 +674,10 @@ static void device_init_td1_ring(struct vnt_private *priv) i++, curr += sizeof(struct vnt_tx_desc)) { desc = &priv->apTD1Rings[i]; desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL); - + if (!desc->td_info) { + ret = -ENOMEM; + goto error; + } desc->td_info->buf = priv->tx1_bufs + i * PKT_BUF_SZ; desc->td_info->buf_dma = priv->tx_bufs_dma1 + i * PKT_BUF_SZ; @@ -657,6 +688,11 @@ static void device_init_td1_ring(struct vnt_private *priv) if (i > 0) priv->apTD1Rings[i-1].next_desc = cpu_to_le32(priv->td1_pool_dma); priv->apTailTD[1] = priv->apCurrTD[1] = &priv->apTD1Rings[0]; + + return 0; +error: + device_free_td1_ring(priv); + return ret; } static void device_free_td0_ring(struct vnt_private *priv) @@ -667,8 +703,10 @@ static void device_free_td0_ring(struct vnt_private *priv) struct vnt_tx_desc *desc = &priv->apTD0Rings[i]; struct vnt_td_info *td_info = desc->td_info; - dev_kfree_skb(td_info->skb); - kfree(desc->td_info); + if (td_info) { + dev_kfree_skb(td_info->skb); + kfree(desc->td_info); + } } } @@ -680,8 +718,10 @@ static void device_free_td1_ring(struct vnt_private *priv) struct vnt_tx_desc *desc = &priv->apTD1Rings[i]; struct vnt_td_info *td_info = desc->td_info; - dev_kfree_skb(td_info->skb); - kfree(desc->td_info); + if (td_info) { + dev_kfree_skb(td_info->skb); + kfree(desc->td_info); + } } } @@ -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 err_init_rd0_ring; + ret = device_init_rd1_ring(priv); + if (ret) + goto err_init_rd1_ring; + ret = device_init_td0_ring(priv); + if (ret) + goto err_init_td0_ring; + ret = device_init_td1_ring(priv); + if (ret) + goto err_init_td1_ring; device_init_registers(priv); @@ -1178,6 +1226,15 @@ static int vnt_start(struct ieee80211_hw *hw) ieee80211_wake_queues(hw); return 0; + +err_init_td1_ring: + device_free_td0_ring(priv); +err_init_td0_ring: + device_free_rd1_ring(priv); +err_init_rd1_ring: + device_free_rd0_ring(priv); +err_init_rd0_ring: + return ret; } static void vnt_stop(struct ieee80211_hw *hw) -- 1.9.1 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com>]
* [PATCH v4 2/2] staging: vt6655: add handling memory leak on vnt_start() [not found] ` <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com> @ 2018-03-30 5:51 ` Ji-Hun Kim 2018-04-03 11:18 ` Dan Carpenter 0 siblings, 1 reply; 5+ messages in thread From: Ji-Hun Kim @ 2018-03-30 5:51 UTC (permalink / raw) To: gregkh, baijiaju1990, forest Cc: devel, y.k.oh, kernel-janitors, linux-kernel, julia.lawall, ji_hun.kim, santhameena13 There was no code for handling memory leaks of device_init_rings() and request_irq(). It needs to free allocated memory in the device_init_rings() , when request_irq() is failed. Add freeing sequences of irq and device init rings. Signed-off-by: Ji-Hun Kim <ji_hun.kim@samsung.com> --- It's additional memory leak handling patch from [PATCH v4 1/2] staging: vt6655: check for memory allocation failures drivers/staging/vt6655/device_main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index c9752df..3604f2d 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -1194,14 +1194,17 @@ static int vnt_start(struct ieee80211_hw *hw) int ret; priv->rx_buf_sz = PKT_BUF_SZ; - if (!device_init_rings(priv)) - return -ENOMEM; + ret = (int)device_init_rings(priv); + if (!ret) { + ret = -ENOMEM; + goto err_init_rings; + } ret = request_irq(priv->pcid->irq, vnt_interrupt, IRQF_SHARED, "vt6655", priv); if (ret) { dev_dbg(&priv->pcid->dev, "failed to start irq\n"); - return ret; + goto err_irq; } dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n"); @@ -1234,6 +1237,10 @@ static int vnt_start(struct ieee80211_hw *hw) err_init_rd1_ring: device_free_rd0_ring(priv); err_init_rd0_ring: + free_irq(priv->pcid->irq, priv); +err_irq: + device_free_rings(priv); +err_init_rings: return ret; } -- 1.9.1 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] staging: vt6655: add handling memory leak on vnt_start() 2018-03-30 5:51 ` [PATCH v4 2/2] staging: vt6655: add handling memory leak on vnt_start() Ji-Hun Kim @ 2018-04-03 11:18 ` Dan Carpenter 0 siblings, 0 replies; 5+ messages in thread From: Dan Carpenter @ 2018-04-03 11:18 UTC (permalink / raw) To: Ji-Hun Kim Cc: devel, y.k.oh, gregkh, kernel-janitors, linux-kernel, julia.lawall, baijiaju1990, forest, santhameena13 On Fri, Mar 30, 2018 at 02:51:55PM +0900, Ji-Hun Kim wrote: > There was no code for handling memory leaks of device_init_rings() and > request_irq(). It needs to free allocated memory in the device_init_rings() > , when request_irq() is failed. Add freeing sequences of irq and device > init rings. > > Signed-off-by: Ji-Hun Kim <ji_hun.kim@samsung.com> > --- > It's additional memory leak handling patch from > [PATCH v4 1/2] staging: vt6655: check for memory allocation failures > > drivers/staging/vt6655/device_main.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c > index c9752df..3604f2d 100644 > --- a/drivers/staging/vt6655/device_main.c > +++ b/drivers/staging/vt6655/device_main.c > @@ -1194,14 +1194,17 @@ static int vnt_start(struct ieee80211_hw *hw) > int ret; > > priv->rx_buf_sz = PKT_BUF_SZ; > - if (!device_init_rings(priv)) > - return -ENOMEM; > + ret = (int)device_init_rings(priv); There is only one call site. Just change device_init_rings() to return negative error codes or zero. > + if (!ret) { > + ret = -ENOMEM; > + goto err_init_rings; Just return directly since there is nothing to clean up. return -ENOMEM; > + } > > ret = request_irq(priv->pcid->irq, vnt_interrupt, > IRQF_SHARED, "vt6655", priv); > if (ret) { > dev_dbg(&priv->pcid->dev, "failed to start irq\n"); > - return ret; > + goto err_irq; This is a "come from" label name. It's better if the goto says what the goto does like "goto err_free_rings;" here. regards, dan carpenter _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] staging: vt6655: check for memory allocation failures 2018-03-30 5:51 ` [PATCH v4 1/2] staging: vt6655: check for memory allocation failures Ji-Hun Kim [not found] ` <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com> @ 2018-04-01 2:42 ` Jia-Ju Bai 2018-04-03 11:12 ` Dan Carpenter 2 siblings, 0 replies; 5+ messages in thread From: Jia-Ju Bai @ 2018-04-01 2:42 UTC (permalink / raw) To: Ji-Hun Kim, gregkh, forest Cc: devel, y.k.oh, kernel-janitors, linux-kernel, julia.lawall, santhameena13 On 2018/3/30 13:51, Ji-Hun Kim wrote: > There are no null pointer checking on rd_info and td_info values which > are allocated by kzalloc. It has potential null pointer dereferencing > issues. Implement error handling code on device_init_rd*, device_init_td* > and vnt_start for the allocation failures. > > Signed-off-by: Ji-Hun Kim <ji_hun.kim@samsung.com> > --- > Changes v2: > - Delete WARN_ON which can makes crashes on some machines. > - Instead of return directly, goto freeing function for freeing previously > allocated memory in the for loop after kzalloc() failed. > - In the freeing function, add if statement for freeing to only allocated > values. > > Changes v3: > - Modify return type of device_init_rd*, device_init_td*. Then add returns > error code at those functions and vnt_start as well. > > Changes v4: > - Fix potential memory leaks from error handling code of device init > functions in vnt_start(). > > drivers/staging/vt6655/device_main.c | 121 ++++++++++++++++++++++++++--------- > 1 file changed, 89 insertions(+), 32 deletions(-) > > diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c > index fbc4bc6..c9752df 100644 > --- a/drivers/staging/vt6655/device_main.c > +++ b/drivers/staging/vt6655/device_main.c > @@ -124,10 +124,10 @@ > static void device_free_info(struct vnt_private *priv); > static void device_print_info(struct vnt_private *priv); > > -static void device_init_rd0_ring(struct vnt_private *priv); > -static void device_init_rd1_ring(struct vnt_private *priv); > -static void device_init_td0_ring(struct vnt_private *priv); > -static void device_init_td1_ring(struct vnt_private *priv); > +static int device_init_rd0_ring(struct vnt_private *priv); > +static int device_init_rd1_ring(struct vnt_private *priv); > +static int device_init_td0_ring(struct vnt_private *priv); > +static int device_init_td1_ring(struct vnt_private *priv); > > static int device_rx_srv(struct vnt_private *priv, unsigned int idx); > static int device_tx_srv(struct vnt_private *priv, unsigned int idx); > @@ -528,18 +528,22 @@ static void device_free_rings(struct vnt_private *priv) > priv->tx0_bufs, priv->tx_bufs_dma0); > } > > -static void device_init_rd0_ring(struct vnt_private *priv) > +static int device_init_rd0_ring(struct vnt_private *priv) > { > int i; > dma_addr_t curr = priv->rd0_pool_dma; > struct vnt_rx_desc *desc; > + int ret = 0; > > /* Init the RD0 ring entries */ > for (i = 0; i < priv->opts.rx_descs0; > i ++, curr += sizeof(struct vnt_rx_desc)) { > desc = &priv->aRD0Ring[i]; > desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL); > - > + if (!desc->rd_info) { > + ret = -ENOMEM; > + goto error; > + } > if (!device_alloc_rx_buf(priv, desc)) > dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); > > @@ -550,20 +554,29 @@ static void device_init_rd0_ring(struct vnt_private *priv) > if (i > 0) > priv->aRD0Ring[i-1].next_desc = cpu_to_le32(priv->rd0_pool_dma); > priv->pCurrRD[0] = &priv->aRD0Ring[0]; > + > + return 0; > +error: > + device_free_rd0_ring(priv); > + return ret; > } > > -static void device_init_rd1_ring(struct vnt_private *priv) > +static int device_init_rd1_ring(struct vnt_private *priv) > { > int i; > dma_addr_t curr = priv->rd1_pool_dma; > struct vnt_rx_desc *desc; > + int ret = 0; > > /* Init the RD1 ring entries */ > for (i = 0; i < priv->opts.rx_descs1; > i ++, curr += sizeof(struct vnt_rx_desc)) { > desc = &priv->aRD1Ring[i]; > desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL); > - > + if (!desc->rd_info) { > + ret = -ENOMEM; > + goto error; > + } > if (!device_alloc_rx_buf(priv, desc)) > dev_err(&priv->pcid->dev, "can not alloc rx bufs\n"); > > @@ -574,6 +587,11 @@ static void device_init_rd1_ring(struct vnt_private *priv) > if (i > 0) > priv->aRD1Ring[i-1].next_desc = cpu_to_le32(priv->rd1_pool_dma); > priv->pCurrRD[1] = &priv->aRD1Ring[0]; > + > + return 0; > +error: > + device_free_rd1_ring(priv); > + return ret; > } > > static void device_free_rd0_ring(struct vnt_private *priv) > @@ -584,12 +602,12 @@ static void device_free_rd0_ring(struct vnt_private *priv) > struct vnt_rx_desc *desc = &priv->aRD0Ring[i]; > struct vnt_rd_info *rd_info = desc->rd_info; > > - dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, > - priv->rx_buf_sz, DMA_FROM_DEVICE); > - > - dev_kfree_skb(rd_info->skb); > - > - kfree(desc->rd_info); > + if (rd_info) { > + dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, > + priv->rx_buf_sz, DMA_FROM_DEVICE); > + dev_kfree_skb(rd_info->skb); > + kfree(desc->rd_info); > + } > } > } > > @@ -601,27 +619,31 @@ static void device_free_rd1_ring(struct vnt_private *priv) > struct vnt_rx_desc *desc = &priv->aRD1Ring[i]; > struct vnt_rd_info *rd_info = desc->rd_info; > > - dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, > - priv->rx_buf_sz, DMA_FROM_DEVICE); > - > - dev_kfree_skb(rd_info->skb); > - > - kfree(desc->rd_info); > + if (rd_info) { > + dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, > + priv->rx_buf_sz, DMA_FROM_DEVICE); > + dev_kfree_skb(rd_info->skb); > + kfree(desc->rd_info); > + } > } > } > > -static void device_init_td0_ring(struct vnt_private *priv) > +static int device_init_td0_ring(struct vnt_private *priv) > { > int i; > dma_addr_t curr; > struct vnt_tx_desc *desc; > + int ret = 0; > > curr = priv->td0_pool_dma; > for (i = 0; i < priv->opts.tx_descs[0]; > i++, curr += sizeof(struct vnt_tx_desc)) { > desc = &priv->apTD0Rings[i]; > desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL); > - > + if (!desc->td_info) { > + ret = -ENOMEM; > + goto error; > + } > desc->td_info->buf = priv->tx0_bufs + i * PKT_BUF_SZ; > desc->td_info->buf_dma = priv->tx_bufs_dma0 + i * PKT_BUF_SZ; > > @@ -632,13 +654,19 @@ static void device_init_td0_ring(struct vnt_private *priv) > if (i > 0) > priv->apTD0Rings[i-1].next_desc = cpu_to_le32(priv->td0_pool_dma); > priv->apTailTD[0] = priv->apCurrTD[0] = &priv->apTD0Rings[0]; > + > + return 0; > +error: > + device_free_td0_ring(priv); > + return ret; > } > > -static void device_init_td1_ring(struct vnt_private *priv) > +static int device_init_td1_ring(struct vnt_private *priv) > { > int i; > dma_addr_t curr; > struct vnt_tx_desc *desc; > + int ret = 0; > > /* Init the TD ring entries */ > curr = priv->td1_pool_dma; > @@ -646,7 +674,10 @@ static void device_init_td1_ring(struct vnt_private *priv) > i++, curr += sizeof(struct vnt_tx_desc)) { > desc = &priv->apTD1Rings[i]; > desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_KERNEL); > - > + if (!desc->td_info) { > + ret = -ENOMEM; > + goto error; > + } > desc->td_info->buf = priv->tx1_bufs + i * PKT_BUF_SZ; > desc->td_info->buf_dma = priv->tx_bufs_dma1 + i * PKT_BUF_SZ; > > @@ -657,6 +688,11 @@ static void device_init_td1_ring(struct vnt_private *priv) > if (i > 0) > priv->apTD1Rings[i-1].next_desc = cpu_to_le32(priv->td1_pool_dma); > priv->apTailTD[1] = priv->apCurrTD[1] = &priv->apTD1Rings[0]; > + > + return 0; > +error: > + device_free_td1_ring(priv); > + return ret; > } > > static void device_free_td0_ring(struct vnt_private *priv) > @@ -667,8 +703,10 @@ static void device_free_td0_ring(struct vnt_private *priv) > struct vnt_tx_desc *desc = &priv->apTD0Rings[i]; > struct vnt_td_info *td_info = desc->td_info; > > - dev_kfree_skb(td_info->skb); > - kfree(desc->td_info); > + if (td_info) { > + dev_kfree_skb(td_info->skb); > + kfree(desc->td_info); > + } > } > } > > @@ -680,8 +718,10 @@ static void device_free_td1_ring(struct vnt_private *priv) > struct vnt_tx_desc *desc = &priv->apTD1Rings[i]; > struct vnt_td_info *td_info = desc->td_info; > > - dev_kfree_skb(td_info->skb); > - kfree(desc->td_info); > + if (td_info) { > + dev_kfree_skb(td_info->skb); > + kfree(desc->td_info); > + } > } > } > > @@ -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 err_init_rd0_ring; > + ret = device_init_rd1_ring(priv); > + if (ret) > + goto err_init_rd1_ring; > + ret = device_init_td0_ring(priv); > + if (ret) > + goto err_init_td0_ring; > + ret = device_init_td1_ring(priv); > + if (ret) > + goto err_init_td1_ring; > > device_init_registers(priv); > > @@ -1178,6 +1226,15 @@ static int vnt_start(struct ieee80211_hw *hw) > ieee80211_wake_queues(hw); > > return 0; > + > +err_init_td1_ring: > + device_free_td0_ring(priv); > +err_init_td0_ring: > + device_free_rd1_ring(priv); > +err_init_rd1_ring: > + device_free_rd0_ring(priv); > +err_init_rd0_ring: > + return ret; > } > > static void vnt_stop(struct ieee80211_hw *hw) It looks okay now :) Best wishes, Jia-Ju Bai _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] staging: vt6655: check for memory allocation failures 2018-03-30 5:51 ` [PATCH v4 1/2] staging: vt6655: check for memory allocation failures Ji-Hun Kim [not found] ` <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com> 2018-04-01 2:42 ` [PATCH v4 1/2] staging: vt6655: check for memory allocation failures Jia-Ju Bai @ 2018-04-03 11:12 ` Dan Carpenter 2 siblings, 0 replies; 5+ messages in thread From: Dan Carpenter @ 2018-04-03 11:12 UTC (permalink / raw) To: Ji-Hun Kim Cc: devel, y.k.oh, gregkh, kernel-janitors, linux-kernel, julia.lawall, baijiaju1990, forest, santhameena13 This will crash. Please see my comments that I just posted to v3. regards, dan carpenter _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-03 11:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20180330055207epcas1p14d562f44802bac86a8a7cd95fe2d009f@epcas1p1.samsung.com>
2018-03-30 5:51 ` [PATCH v4 1/2] staging: vt6655: check for memory allocation failures Ji-Hun Kim
[not found] ` <CGME20180330055211epcas2p1a75c707cdf600cfd5027e253ef440861@epcas2p1.samsung.com>
2018-03-30 5:51 ` [PATCH v4 2/2] staging: vt6655: add handling memory leak on vnt_start() Ji-Hun Kim
2018-04-03 11:18 ` Dan Carpenter
2018-04-01 2:42 ` [PATCH v4 1/2] staging: vt6655: check for memory allocation failures Jia-Ju Bai
2018-04-03 11:12 ` Dan Carpenter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®