Received: by 10.213.65.68 with SMTP id h4csp421377imn; Wed, 4 Apr 2018 00:25:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48OMrSiOm+u/dNbZKL65QWaKLiXPatJpUmW+YYSXHBxr1gCXIqtPtYvMhguNZkGSZONV6uj X-Received: by 10.167.129.136 with SMTP id g8mr12990182pfi.19.1522826740787; Wed, 04 Apr 2018 00:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522826740; cv=none; d=google.com; s=arc-20160816; b=IM6BoP/gHu5TkRaLWZW+CdL/vHuqkBFkRlGG3XhOZ16E/aSST7/vT/c56WcHDre+CD EIdcNZ36ZXsHFc7HtUnHZx1DAghgx4O3qUEtWkXulFqVQDpni1JhFEOH4izupFwXV99/ jFiQfIoDAhGDHyhNews40mYWsMwWcpPCFonYv1LgBWxSXhWm/5kwfX276g8pFUl+ZxuI w2Cry5N36bhmz/jhrndoRAbxqZ4maUv8NYuw+qeTteEniJl7wR3ewNtr9Z4E1I9hNlJx cfSOPsOs9YS4muiQnW6DoabjRSwJO9zobA40i0bwI/JBVtIJo2g0XAyZ1IKeSK9Mk/uv W36Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:user-agent :in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter:arc-authentication-results; bh=UObsfukW7Uby2WtH01liO0pscaMHSQOi3I9/1pqJsVM=; b=TBEbUeGHmZ8oyi7z7tWb8NuNFo11/ZDpe/aAg6sgmtTlSrLhwtR6xuqScCEYR/1AGY ul6q1ksqaCQk5fwGg2jKaNJqrHHmv/sI7CeF6EInVsTvHvnXgunTr5umyOPDYl+Cvn1E sW1C+jEJ2FH9P0YSUK1PWg87Mw0F3r/bfGONh6h/STmoReuiIZmQ5XdEAQmBsY0uAMhP Z+Mh193t7siOXyJfD7zJ8k71OXFbAB2CecvKOeMl66LpBvMezd/ATecy0N28/1+oU44w SvF3qMNTAPrAePRF6Ow5bVYSzVhb5iuLbD6fWdZCwXTvZrDkHCBTjnHsVnmqLqOuR+d+ JStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Dm0m+2t4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si3617523pfb.166.2018.04.04.00.25.26; Wed, 04 Apr 2018 00:25:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Dm0m+2t4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751234AbeDDHYT (ORCPT + 99 others); Wed, 4 Apr 2018 03:24:19 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:17550 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeDDHYR (ORCPT ); Wed, 4 Apr 2018 03:24:17 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20180404072415epoutp0190af4cd7892e2690bc1eb6e349001309~iKsZ7hqUD0031300313epoutp01a; Wed, 4 Apr 2018 07:24:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20180404072415epoutp0190af4cd7892e2690bc1eb6e349001309~iKsZ7hqUD0031300313epoutp01a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1522826656; bh=UObsfukW7Uby2WtH01liO0pscaMHSQOi3I9/1pqJsVM=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=Dm0m+2t4Zvj+53sC2Dvv+Z0imV6GiRo8Ramufxv3a8KeK4qzgP9MrN57pEvChk6d/ rwkR65nsiRwRpJXZozI4TQXQ/RW9gzZoXGYBybUGmNIZz0tSzQeTh9c8JYBVo2VRn0 NmtnFiCbLwFALDhHX/8V91SzIU5wKrSX/5f21MAA= Received: from epsmges1p4.samsung.com (unknown [182.195.40.60]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180404072415epcas1p22bac13ae3f3e9f9906677dfdc3b585cf~iKsZmhb5F2380123801epcas1p2J; Wed, 4 Apr 2018 07:24:15 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id F0.B8.04226.F9D74CA5; Wed, 4 Apr 2018 16:24:15 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20180404072415epcas1p46b3af0ce31a5e68bfcd897544b94a513~iKsZMzTyk0837408374epcas1p4D; Wed, 4 Apr 2018 07:24:15 +0000 (GMT) X-AuditID: b6c32a38-d5bff70000001082-28-5ac47d9ffdbb Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D1.79.03849.F9D74CA5; Wed, 4 Apr 2018 16:24:15 +0900 (KST) Received: from ubuntu ([10.253.107.61]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P6N00KU7GKE4W30@mmp1.samsung.com>; Wed, 04 Apr 2018 16:24:14 +0900 (KST) Date: Wed, 04 Apr 2018 16:24:10 +0900 From: Ji-Hun Kim To: Dan Carpenter Cc: gregkh@linuxfoundation.org, baijiaju1990@gmail.com, forest@alittletooquiet.net, devel@driverdev.osuosl.org, y.k.oh@samsung.com, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, julia.lawall@lip6.fr, santhameena13@gmail.com Subject: Re: [PATCH v3] staging: vt6655: check for memory allocation failures Message-id: <20180404072410.GA31134@ubuntu> MIME-version: 1.0 Content-type: text/plain; charset="us-ascii" Content-disposition: inline In-reply-to: <20180403104052.6wbomdguifrmlmpz@mwanda> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkk+LIzCtJLcpLzFFi42LZdlhTV3d+7ZEog7b9yhbrJi5ksnj9bzqL xZ4zv9gt7k94xGrRvHg9m8WyB6cZLbbekra4vGsOm8XJbfIWW7p+sDpweTQ3vmf1uLfvMIvH zll32T32z13D7rF3S5bHx6e3WDz6tqxi9Pi8SS6AIyrVJiM1MSW1SCE1Lzk/JTMv3VbJOzje Od7UzMBQ19DSwlxJIS8xN9VWycUnQNctMwfoQiWFssScUqBQQGJxsZK+nU1RfmlJqkJGfnGJ rVK0oaGRnqGBuZ6RkZGeiXmslZEpUElCasayvuiC3SIVP559ZG9g3M3fxcjJISFgIvH7yWXG LkYuDiGBHYwS867dZIZwvjNKTPlwi62LkQOsatd3foj4bkaJnz/aWCGcl4wSR3vfs4GMYhFQ lXj1cwaYzSagKbGx+xojiC0ioCNxufMHO0gDs8A3Rol7nTeZQBLCAv4S/7pfsIDYvALaEp9X 32CEsAUlfky+BxZnBmo+e2wdI4QtLfHo7wx2EJtTwFRi/+H/rCC2qICKxJST29gg/nnNJrGm 2RDCdpE4v6aBBcIWlnh1fAs7xDfSEpeO2kKEqyUWXNkBVVIjcfP/UiYI21iit+cCM8RaPol3 X3tYIVp5JTrahCBKPCRuX/vEDmE7Ssz69BQacEcZJebuu8c+gVF2FpJvZiH5ZhaSbxYwMq9i FEstKM5NTy02LDDRK07MLS7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NWcdh6xWkXmYyM2S3+ Tatfyr45rNr7g6fw1Uq2ZnWdjMhPfge/hFadmlV6wbp8SVZ5+EGGvCbJi3f8DB8XR0mlHxZS YinOSDTUYi4qTgQAOuEIB4ECAAA= X-CMS-MailID: 20180404072415epcas1p46b3af0ce31a5e68bfcd897544b94a513 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180330024416epcas2p2f566f43a8f5af8b4ebc17659e3cf0ecf X-RootMTR: 20180330024416epcas2p2f566f43a8f5af8b4ebc17659e3cf0ecf References: <1522377844-23591-1-git-send-email-ji_hun.kim@samsung.com> <20180403104052.6wbomdguifrmlmpz@mwanda> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 03, 2018 at 01:40:52PM +0300, Dan Carpenter wrote: > > 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"); > > > > We need to handle the case where device_alloc_rx_buf() fails as well... Hi Dan, thanks for your comments! I will write a patch v5 including this fix. > Some years back, I wrote a post about error handling that might be > helpful: > https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ This post is very helpful to me, Thank you. > You are using "one err" and "do nothing" style error handling which are > described in the post. Sorry, I didn't fully understand "one err" and "do nothing" style error handling of this code. The reason using goto instead of returns directly was that for freeing previously allocated "rd_info"s in the for loop. Please see below comment. > > @@ -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; > > } > > Of course, Jia-Ju Bai is correct to say that this is a layering > violation. Each function should only clean up after its self. > > Also, this is a very typical "one err" style bug which I explain about > in my g+ post. The rule that applies here is that you should only free > things which have been allocated. Since we only partially allocated the > rd0 ring, device_free_rd0_ring() will crash when we do: > > dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma, > priv->rx_buf_sz, DMA_FROM_DEVICE); > > "rd_info" is NULL so rd_info->skb_dma is a NULL dereference. For dealing with this problem, I added below code on patch v3. I think it would not make Null dereferencing issues, because it will not enter dma_unmap_single(), if "rd_info" is Null. + 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); + } I would appreciate for your opinions what would be better way for freeing allocated "rd_info"s in the loop previously. Best regards, Ji-Hun