Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1779859pxb; Fri, 5 Feb 2021 00:55:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGYfgiinpnls3lNSx8oB91/suNz5s85c9i4SUoL1x5O/PTLWakznVe9eE96g0QLJo8bzK0 X-Received: by 2002:a50:d6c1:: with SMTP id l1mr2590787edj.336.1612515355176; Fri, 05 Feb 2021 00:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612515355; cv=none; d=google.com; s=arc-20160816; b=vurCGAen1nORv1E2BB6nHsDR+IE2tpQvildkPR72QfmLY6ajBwy8DvzaLajXpEkrtr +5gJbsMkbw0aiOzBpbVSIgaF9Q7bVD6B6K3/X22LX1ct+4L1pqt/e1ASXSlAHcJDPnkG EDNkY6OJULRIsqNTG3NSqfDlp2k1AgKPOWmFI4a463Sm+ye2uLIntBIib248/mla3KRQ hr1L3IwUoFa0lBCjiCoNye2UTqovPo+him/JribPW7ksKV6xGr0rZQktgOlAAypNLQlq 9hMvV8ss2V6iTTZXrXXNP+uZ4yVvHC4lEkZ7fo3YyD1bWiA7D7eQa+GzfnfvIMqgHsSB fMsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=UF771bN6aWBY/BbgXvYNGmbKSODghcb15xzEHcJ2vco=; b=zmlwG+oLz1U2bCyhsIn2D4MHfteUNN6uICjoyTURR7HF/yqYSNNj9S9zXb7kgVVfMA KklKHPRQpcJaIt7QXWugI5PUZHmWpDs7rPLCxTeGMTUvhpr0SiG1weY+NhlPaS3CTnoJ 5eU1n+eu3fNOXnQZx9Vj5fcklIf+x7TNkkvBkI4tI9cTIFADscXiQS0q7wC8GIEGpcYq zmVCkVSqLAZIuiMATfE5WvmGfBXIZdK4AFSLlnDxCxnyR8xuLSzYyz4lUorm5RnbcFiS sIvISS8D1LUdUZPaSOLbGnEGEY3B6W6NlVDzm4KlxYUY3Xh+LBntd8ZCVyq6Yr6A8+5l yPeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si4876269ejd.199.2021.02.05.00.55.30; Fri, 05 Feb 2021 00:55:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhBEIxM (ORCPT + 99 others); Fri, 5 Feb 2021 03:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbhBEIxI (ORCPT ); Fri, 5 Feb 2021 03:53:08 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB3DFC06178B for ; Fri, 5 Feb 2021 00:52:27 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7wqh-0006EF-6p; Fri, 05 Feb 2021 09:52:19 +0100 Received: from hardanger.blackshift.org (unknown [IPv6:2a03:f580:87bc:d400:8f9f:ac65:660b:ab5f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id F246C5D72D6; Fri, 5 Feb 2021 08:52:15 +0000 (UTC) Date: Fri, 5 Feb 2021 09:52:15 +0100 From: Marc Kleine-Budde To: Xulin Sun Cc: wg@grandegger.com, dmurphy@ti.com, sriram.dash@samsung.com, kuba@kernel.org, davem@davemloft.net, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xulinsun@gmail.com Subject: Re: [PATCH 2/2] can: m_can: m_can_class_allocate_dev(): remove impossible error return judgment Message-ID: <20210205085215.sgsvtys5z4gm3ict@hardanger.blackshift.org> References: <20210205072559.13241-1-xulin.sun@windriver.com> <20210205072559.13241-2-xulin.sun@windriver.com> <20210205081911.4xvabbzdtkvkpplq@hardanger.blackshift.org> <9cae961a-881d-8678-6ec3-0fd00c74c8ad@windriver.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5ixmah6qra6ivpgj" Content-Disposition: inline In-Reply-To: <9cae961a-881d-8678-6ec3-0fd00c74c8ad@windriver.com> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --5ixmah6qra6ivpgj Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 05.02.2021 16:46:16, Xulin Sun wrote: > On 2021/2/5 =E4=B8=8B=E5=8D=884:19, Marc Kleine-Budde wrote: > > On 05.02.2021 15:25:59, Xulin Sun wrote: > > > If the previous can_net device has been successfully allocated, its > > > private data structure is impossible to be empty, remove this redunda= nt > > > error return judgment. Otherwise, memory leaks for alloc_candev() will > > > be triggered. > > Your analysis is correct, the netdev_priv() will never fail. But how > > will this trigger a mem leak on alloc_candev()? I've removed that >=20 > The previous code judges the netdev_priv is empty, and then goto out. The > correct approach should add free_candev(net_dev) before goto. >=20 > The code Like: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 class_dev =3D netdev_priv(net_= dev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!class_dev) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 dev_err(dev, "Failed to init netdev cdevate"); > +=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 free_candev(net_dev); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 goto out; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >=20 > Otherwise, memory leaks for alloc_candev() will be triggered. No - as you said in the original patch description. The return value of netdev_priv() cannot be NULL, as net_dev is not NULL. > Now directly remove the impossible error return judgment to resolve > the above possible issue. Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --5ixmah6qra6ivpgj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEK3kIWJt9yTYMP3ehqclaivrt76kFAmAdBzwACgkQqclaivrt 76m8Wwf/XrNhbJ9LzHFhjVk8mBwZETNanYtNEHxJ7lZWEjMqjblzlefUvetmmfUA ft2uXaKHgJK5iWQiE8e8RFUzgKO/8Ff/whcfw7/YRtdQsGYQCIDhZ5L8xrIN1fr+ 1MocCKg08DuPBTa2hdRLn2zz3M1hOILVd6EcBolFHjWZ2obXuT6gT34AZ4tOXRwD 07w31mfqQ6tYwBCv8SmhiZ8TSTDyGajv+Kqb2lhatTEMT5QfZC40OO5meCJhSyDi LcRmnitxcpbxlZuxP1ymadM6Nb7/urHYW/YCIhmYAJE1Jca4EtJYjb2TQ84RGxnJ r/9unNZqAMepkLnGB+N7aXSGx9kAyg== =LRzj -----END PGP SIGNATURE----- --5ixmah6qra6ivpgj--