Received: by 10.213.65.68 with SMTP id h4csp2201708imn; Thu, 29 Mar 2018 20:52:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+in+qcAXRFSH/C0XS5uAgg+97J5ZuoO2O88Yr2RxNQCkqdf5Nqt/AKH101E5RpV8BmiqYP X-Received: by 10.101.69.73 with SMTP id x9mr7320120pgr.50.1522381949729; Thu, 29 Mar 2018 20:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522381949; cv=none; d=google.com; s=arc-20160816; b=dx44xTd+VEFQGbMODGf/4Dh88SnhBPzdRJt9txlv+2AwhAu6Z5muprTu8iwM9mSEXF MbWlU/ZvVR8fRM6gh5fGpc1nQ6FzKOaICOwXA9m/ZdKSrecEbJkdOxkJjyw79lKUWh4R HCeH15e7T4upe1GmulGJgxCGzIrJZqhr6V+UnQGUsdbiPc7GDESANjQnYbpvlcCQPmiz IFn7mIgQtXV3YklvdBsfDPN1jRoRN4sYCtEIZah+S5cYT2uG99DsMGSR+c/18LzbPsjh vqFPHeDjdNwFLtiLU+GTWd2KS+MxYSo+d1tl6lmUapfXpQZE9oX4uJCfL0RM/3kzsgTs VhPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=BqKNmh7Sn2yaKgVPcTiFAB2gIWOT6m3va4XO2zXwSnw=; b=rVfGOEDk/jDdHCGbJB50+LYbLdOrvke0FXN2zxGlCkj9VqpFNBH3Qh/vRTRAlvJvZL 3aZXKdhjnU/+HVDAwi98DPJR9ifxdiIpY6GCmdiAkbFciZsrK3Ke0TPMUFvgf16lW8OH V08UIPBGUoKWJV8BMMCmIJTq35EkKqVhlRmjEnPb/2HrdbvfrvfpjxVJX4+2t6NlZyST gfjhdB8ASUOjppmz92nBGKjMD6ZeMSAdzhVurWRWDwgf4Lw8tBFXObziMDAfu8m3NvMO s6VJrnEz0qsg5wR3zNGWinhlWoL06K7xuMB9LR8XG7Ow5dPtoPAoNZYIzUMROlTdi1it PxjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KYmisP5I; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x185si4923518pgb.649.2018.03.29.20.51.59; Thu, 29 Mar 2018 20:52:29 -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=@gmail.com header.s=20161025 header.b=KYmisP5I; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752971AbeC3Du3 (ORCPT + 99 others); Thu, 29 Mar 2018 23:50:29 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:46686 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752780AbeC3Du1 (ORCPT ); Thu, 29 Mar 2018 23:50:27 -0400 Received: by mail-pf0-f193.google.com with SMTP id h69so4637374pfe.13; Thu, 29 Mar 2018 20:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=BqKNmh7Sn2yaKgVPcTiFAB2gIWOT6m3va4XO2zXwSnw=; b=KYmisP5IqYqOdrppDNB+QZjQ+PzfmG5L5i351rJm89HcsZ3YHvJWmUYQbxLzRBnRi6 yFNPPZeDT/B0Tc0DQF5IsrDE/dlAvO5Ieo3fB08D9PzwLbm2OoNjsaRsf8duIyyjVHY+ 3y+H0y/KXMdwjTRwv4bJcc83TV3fi2lCmLqdA7pgfzS9uTOOIB5MD1WDhno8ED6qa/wH NzPtHCDzmJ4h+kh6u7Uf8MWpYw35n1aozkBbi4ibzYr5YFFJ8Ze/d0Z5QAsEx0vgFTV3 5eRJ89qx7ONaTtWfdRatru+P9r1QaSi5T7kiTUh2HQmSlGq1X5oU8QoDEs9SbFOgIGdr v9yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=BqKNmh7Sn2yaKgVPcTiFAB2gIWOT6m3va4XO2zXwSnw=; b=n1tov0b71vEkVnjupErh/kXIIDG9ZCuFsoMMOBwOr0FX039N3K80m8Cc17IfELxA34 AAp45pX23j91t8zU+cvQn9EUMh9W1RyOQgQCbjiz7UvKGtlX2PmKmh+u8r1ra6pdlf/Y vxBUfqj/y3qJya9MSJ7gXO2IohGjKIjnDTI4v/PvlsroClc5LvSWXWoDKluIp/AMIOzy xWnF4K8CKK5H4/lOxFPjeF72IgNBw4h6/fCp4DMfm1sKO0xW0B+JD+7ULxgVv1DO0DCA a+H0lVYpGKVAxVsUNew8BYfex1o2Gud8p0ykGPKGVTnVgGdPJ6G06Ad2ZwFpmU/uX0Fu inMQ== X-Gm-Message-State: AElRT7GwTXdaeVfarUsGMkec1bR8aVcGeok6EuIchyF3RN2tmGKSoZD1 bBpbpGupb0jw5Iggr+DuzIEaETLN X-Received: by 10.98.31.86 with SMTP id f83mr8600655pff.196.1522381827104; Thu, 29 Mar 2018 20:50:27 -0700 (PDT) Received: from ?IPv6:2402:f000:1:1501:200:5efe:166.111.70.50? ([2402:f000:1:1501:200:5efe:a66f:4632]) by smtp.gmail.com with ESMTPSA id d8sm8058221pfh.177.2018.03.29.20.50.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 20:50:26 -0700 (PDT) Subject: Re: [PATCH v3] staging: vt6655: check for memory allocation failures To: Ji-Hun Kim 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 References: <1522377844-23591-1-git-send-email-ji_hun.kim@samsung.com> <20180330033933.GA26489@ubuntu> From: Jia-Ju Bai Message-ID: Date: Fri, 30 Mar 2018 11:50:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180330033933.GA26489@ubuntu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/3/30 11:39, Ji-Hun Kim wrote: > 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. I think it is okay. I suppose that, for each device_init function, you only free the resources allocated in this function, and do not handle the resources in other functions. > @@ -550,20 +554,29 @@ static void device_init_rd0_ring(struct vnt_private *priv) > + return 0; > +error: > + device_free_rd0_ring(priv); > + return ret; This code is needed to free the resources allocated in this function. Best wishes, Jia-Ju Bai