Received: by 10.213.65.68 with SMTP id h4csp3365775imn; Tue, 3 Apr 2018 03:45:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx48OtuJolQeCwz/UaYY91kEzyZjkgL5dArpMnUVcomeFEJsYk/hREO6yuxzTQwi8rgiYSnj/ X-Received: by 10.101.74.206 with SMTP id c14mr4008095pgu.337.1522752311132; Tue, 03 Apr 2018 03:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522752311; cv=none; d=google.com; s=arc-20160816; b=St7mcyP6Poznr2riBgGEp6fSmG6TvXUw6Np6mR65RoRlsT3HyKdtL8O2CsgUnXm+Uw BvKgagEKA95bQC/hsdohN3O0cLEKhUZqgokJgWlrx0YG9c+64BjKYsw/EJfwzBgR5w3V aOKCukE4yakm6NzqldNE4pRKqLUMOkvx8LpnvvqD4ybbSdqb7jCRiCD3oOni74x4qSit 3Jt2ja2rtDQ16tSb5vXFqyaQ3fq0F2Ab1rJNtysgrYM+jP2B7vDNERBrTZuJjXAH1hYT RDcShPgh59xIr58hZiXJzm9hkMjJX4nkNX3TdbdnMXEAHwdM8gALAo1a9WYga+Dpt4Bp Kovg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=vJnZbGHMH2PBwuJRaq+TgE6NJSvnmmy+kiS9cucTang=; b=dsSpFzLis95otpkz0YMGRgDF3YcUd9PkcxkvoE7Hp/I0VuFZ9I1JfC2k2FxT1LbNqX mxww28aT18thHfEccQFFQO9QwJ6CYw7dBm0DAkBwGJWOqog0jIrPB486cfc6xlSjcjEF yIRlZPCeVT8TFEfdokgmrIH6NgrNu4s7cQgwXCOiDQjMCiweeKG+ZmmZZcy0pHcz5X6F uO/ncG6kCa/+1V4XrkUID08zDnUbbdrCxUc3riC6UAOHd8Zoqm+a5xw3bwZeg+NVVg2D atlb5YwmxSdHFOwmhcjeFMzZgwad8BXW01HGcuugsR4XI44a6VH7j1g8bGaP5kqxnXAW WeCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=hTo07P2D; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si1752968pgn.696.2018.04.03.03.44.26; Tue, 03 Apr 2018 03:45:11 -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=@oracle.com header.s=corp-2017-10-26 header.b=hTo07P2D; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755098AbeDCKlO (ORCPT + 99 others); Tue, 3 Apr 2018 06:41:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41022 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754764AbeDCKlM (ORCPT ); Tue, 3 Apr 2018 06:41:12 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33Aevg6089568; Tue, 3 Apr 2018 10:41:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=vJnZbGHMH2PBwuJRaq+TgE6NJSvnmmy+kiS9cucTang=; b=hTo07P2DaJB7xGRTtkPovk09zP/Vgb/ONCf1VWXdrriiY5pFlY/KJdNUz1blmkWsbAAz LRboL47XsnHr7Su5SvdspQy1ipt/5NfXjdnhjiGmjsnWZZh+x4WcAMowPg5pbR4oPXUp N57StIk2rZSljaJEjGIdMOaSvZxB8Y2PshVH4ym/Rg7STnqr6sUXXpEvO10aJHtFoy0L aNWZ3KVijPwxfmVWak7cmyVdNGItY5rGJaXTEE9EZG77QhzlIcmmAKHMmULr3UPKJ0rk SAKr1RCrN0MR+6Urqs/ipC9NrVNsHR4DcLfbHhfbuDRkudF3HPBNOqGEhW+7/r7jdeBM Jg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2h482sr01f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 10:41:03 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w33Af3cF014891 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 10:41:03 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33Af1rW032113; Tue, 3 Apr 2018 10:41:01 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 03:41:01 -0700 Date: Tue, 3 Apr 2018 13:40:52 +0300 From: Dan Carpenter To: Ji-Hun Kim 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: <20180403104052.6wbomdguifrmlmpz@mwanda> References: <1522377844-23591-1-git-send-email-ji_hun.kim@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522377844-23591-1-git-send-email-ji_hun.kim@samsung.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8851 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030109 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 30, 2018 at 11:44:04AM +0900, Ji-Hun Kim wrote: > @@ -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; Don't initialize "ret". When you do that it disables static analysis to find uninitialized variable warnings. > > /* 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"); > We need to handle the case where device_alloc_rx_buf() fails as well... Some years back, I wrote a post about error handling that might be helpful: https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ You are using "one err" and "do nothing" style error handling which are described in the post. > @@ -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. regards, dan carpenter