Received: by 10.213.65.68 with SMTP id h4csp2195628imn; Thu, 29 Mar 2018 20:41:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx49cwQW6RtCWwm9wly6VAziEPwns8mUxq75BR/At1jK1fSgTYnWmyJig7v9uJw2O8g7a0Mn0 X-Received: by 10.99.132.72 with SMTP id k69mr7320637pgd.367.1522381267662; Thu, 29 Mar 2018 20:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522381267; cv=none; d=google.com; s=arc-20160816; b=PS/EvQxjFUFpKF1z64E96/A4vu15yMvuAHVn8fDj/BkCRn9XES/FIAqtWZsdNEBc1X gk1mqHYyPykmhiyILbkRfnaUwxj7wYbf39BXGOMGp60bjAySiMYMeNh2cJpKevfh1C2w b3CgZUZYAowH0Ay+wW8ocR1BcTHszQpo3XXu3djpUmMe5+EjAjmOGOANWPT7cwnMUWVv N2KDNpJqTXH8QKQM0BtcjDJ42PspHxkvGNHfyJTXD445YBCUtYu8W8QOuGTEXa0TBiQC jFHPHwVQwKfftJ7le4MNss3X0Nb/ptL3aa/zz/HKdmyHQPtV7AxDS0zC9+fADYK2yQkZ I3HA== 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=7rh2HVY2Sb68xx9eX+kwuRhXqdxMzRIrKLMeawGwGi0=; b=EaiV7mW1THUImOk0DGKMs38Qh2GwjHbz+RFhy3bIkBn/6YutsdN4q+y32ONKRDeLjB kFVlM4+Zy5lMRZBVXzYQGZ+pa47eFXM6txMl/UaPp6uaOsNnYEU5BFzQAz0DGhIB8V0L F7RSoifbpwlFjdDZZMkVMI/r8wPp7IDQirfugT/dbK3qNf1/c7CTdekizudhLxD9k6FI JZV3o8Huf6joThiI1cOHfuUuP9hevRSBRMDYzskfUN46bwEcEs9PvwRfDFoqYUo3/GwS EQnoDl7A7ilcVSBWWbtSnoofzkQPn/46WDjF4DCE5MSPh3mWKEuvDdcGcjRifpkdhcS+ Makw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=YyJ/tlqv; 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 c23-v6si3159334plk.406.2018.03.29.20.40.51; Thu, 29 Mar 2018 20:41:07 -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=YyJ/tlqv; 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 S1752783AbeC3Djk (ORCPT + 99 others); Thu, 29 Mar 2018 23:39:40 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:33809 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752645AbeC3Dji (ORCPT ); Thu, 29 Mar 2018 23:39:38 -0400 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20180330033936epoutp021d5a82d48e7f8d07317b2bfb5db58f1f~glZ0jkU292107821078epoutp02X; Fri, 30 Mar 2018 03:39:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20180330033936epoutp021d5a82d48e7f8d07317b2bfb5db58f1f~glZ0jkU292107821078epoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1522381176; bh=7rh2HVY2Sb68xx9eX+kwuRhXqdxMzRIrKLMeawGwGi0=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=YyJ/tlqvWM7SIYV+VdzCqsgc2mwu/GhQExZ1K95aNlG+iKfG57Xrtl7i1iZlTani0 sjnjJ+pQ+Q63VYBZg67O1yAMYu6HHIRNHfbOIPen0ihY1PyYIt3cWZTVP+yWTeg0XM Pp+hvitgfCsv+QSI+DtX0byE3joTPfzjzlW/wkJk= Received: from epsmges2p4.samsung.com (unknown [182.195.40.59]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20180330033935epcas1p3530884087ba243fbd0dd1d7fe276d92d~glZ0QPJoo1893918939epcas1p3Z; Fri, 30 Mar 2018 03:39:35 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 4C.CC.04082.771BDBA5; Fri, 30 Mar 2018 12:39:35 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20180330033935epcas2p3506493d3249f829de15e1c58116ebff1~glZzpNV1m2179921799epcas2p3F; Fri, 30 Mar 2018 03:39:35 +0000 (GMT) X-AuditID: b6c32a48-8c1ff70000000ff2-84-5abdb177152d Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 55.7B.03827.771BDBA5; Fri, 30 Mar 2018 12:39:35 +0900 (KST) Received: from ubuntu ([10.253.107.61]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P6D00E09WTYL620@mmp2.samsung.com>; Fri, 30 Mar 2018 12:39:35 +0900 (KST) Date: Fri, 30 Mar 2018 12:39:33 +0900 From: Ji-Hun Kim To: Jia-Ju Bai Cc: gregkh@linuxfoundation.org, forest@alittletooquiet.net, dartnorris@gmail.com, santhameena13@gmail.com, julia.lawall@lip6.fr, y.k.oh@samsung.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH v3] staging: vt6655: check for memory allocation failures Message-id: <20180330033933.GA26489@ubuntu> MIME-version: 1.0 Content-type: text/plain; charset="us-ascii" Content-disposition: inline In-reply-to: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnk+LIzCtJLcpLzFFi42LZdljTXLd8494ogy8HDCzWTVzIZHHm/Vkm iz1nfrFb3J/wiNWiefF6NotlD04zWmy9JW1xedccNouT2+QttnT9YHXg8mhufM/qcW/fYRaP nbPusnvsn7uG3WPvliyPvi2rGD0+b5ILYI9KtclITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw 1DW0tDBXUshLzE21VXLxCdB1y8wBOk5JoSwxpxQoFJBYXKykb2dTlF9akqqQkV9cYqsUbWho pGdoYK5nZGSkZ2Iea2VkClSSkJrRf/42U8FjgYqJf9+wNjB+5+li5OSQEDCR6LvSz9TFyMUh JLCDUWLz9AZ2COc7o8SsLwdYYKr+TVnMApHYwChxfesOVgjnJaPEyqXdTCBVLAKqEh9WrwCz 2QQ0JTZ2X2MEsUUE1CVOL9vFCmIzC3xhlFhyjAPEFhbwl/jX/QJsA6+AtsSxD2uYIWxBiR+T 77FA1OtInD22jhHClpZ49HcGO4jNKWAr8fblYbAaUQEViSknt7GBHCQh8JxN4u2580wQZ7tI XNnYzQphC0u8Or6FHcKWlni2aiMjhF0tseDKDqg3ayRu/l8K1Wss0dtzgRliMZ9Ex+G/QL0c QHFeiY42IYgSD4nb1z5BjXSUmPXpKTMkUM4ySkzc/4h5AqPsLCT/zELyzywk/yxgZF7FKJZa UJybnlpsVGCiV5yYW1yal66XnJ+7iRGcCLU8djAeOOdziFGAg1GJh1eBZW+U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MmIdht28eOm6RlTbrwm6NU0nPtFnYj/F/ZPrEnF6qfORJouPXY4Wzk0qVWIoz Eg21mIuKEwHtKr1HfgIAAA== X-CMS-MailID: 20180330033935epcas2p3506493d3249f829de15e1c58116ebff1 X-Msg-Generator: CA CMS-TYPE: 102P 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> 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:15:03AM +0800, Jia-Ju Bai wrote: > > > 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 > > But, those freeing function are already placed in the each device_init functions for allocation fail like below. @@ -550,20 +554,29 @@ static void device_init_rd0_ring(struct vnt_private *priv) + return 0; +error: + device_free_rd0_ring(priv); + return ret; Would freeing in the vnt_start() be better instead of freeing in device_init_rd0_ring function? Best regards, Ji-Hun