Received: by 10.223.185.116 with SMTP id b49csp6112237wrg; Wed, 28 Feb 2018 04:18:27 -0800 (PST) X-Google-Smtp-Source: AH8x224qzQdoJ6NzP7H/ohqW0fVlHWwl9iVJMlKgELoeCiEEOU4SUMBE8WPHcDxmwWeVSk2XXF4/ X-Received: by 10.99.116.28 with SMTP id p28mr14141942pgc.306.1519820307163; Wed, 28 Feb 2018 04:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519820307; cv=none; d=google.com; s=arc-20160816; b=FK1bS+z46D/ZOwL6h+jjoyygnF/TVVdO2XqBnJzeJwMVM6cBEvNYjj4sSv8Hn7MiZR IhTPzjexSBdcFDpgQAvDpqF3JFoTOUdHU76ffK5d2UOrKl4DSfLclXxHy0NMIkjeffCJ 0kRgCfNjPNAOTTTH9os8H47GRVQKj0JxRu1zls4iqV55QYlIwa1Y4hcvYhFyzqflUhh4 lm/9/Odc/ihClbLv9RwyZve5wbY4HcLfCTERA1rlyKCrG/Uj7xO7CWejG6QGFyH5TLWL ylyGC4RmFSA8pinEO5MH5rCZXE9J4bm1bjyMfoiLnPuOcO6uuPHYj3KV06VVQmzTAgad 7oDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:sensitivity :importance:date:subject:cc:to:from:message-id:mime-version :arc-authentication-results; bh=OD1j3FnCxSbdYnzsBuDJc4MXUSQstpntywcbaiMl0T0=; b=c6wo3rkIDsrPtKz2yxB1fW1aiCqkOtXwO7gqdx+C2orjWMz454hYGYrFuvKCO0VkCU eK3Ghdnct5w5qSMWPhXBiTSVojnBMBEOR3xjuDKYxAUqfQ0yHFOXcoteXrlXRhdGiS6o GwQYeJmFx5aNdQqQBoYoREWf+JuvE4jaBGRxYH1ZPPez2lZLvq0j8yxPKPUDOQ/bgmuI cjIEnfJkBdlbGQL9WYDBGTkZnkcHc2Q4Q9f0AFlcEpjHIynE54ouEXIV8Ub0QcqLLI+B rqQFsM1jSiQm1TTDCv50cu5Co1rSDreKa+5uqVZZH0reBX2KLbz1wkFv0VxP4PUzmLkl QT4A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si971095pgn.310.2018.02.28.04.18.11; Wed, 28 Feb 2018 04:18:27 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427AbeB1MRa (ORCPT + 99 others); Wed, 28 Feb 2018 07:17:30 -0500 Received: from mout.gmx.net ([212.227.17.21]:59595 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbeB1MR2 (ORCPT ); Wed, 28 Feb 2018 07:17:28 -0500 Received: from [213.144.13.140] ([213.144.13.140]) by 3c-app-gmx-bs19.server.lan (via HTTP); Wed, 28 Feb 2018 13:17:16 +0100 MIME-Version: 1.0 Message-ID: From: "Lino Sanfilippo" To: "Arvind Yadav" Cc: "Cornelia Huck" , jwi@linux.vnet.ibm.com, ubraun@linux.vnet.ibm.com, davem@davemloft.net, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org Subject: Aw: Re: [PATCH] net: iucv: Free memory obtained by kzalloc Content-Type: text/plain; charset=UTF-8 Date: Wed, 28 Feb 2018 13:17:16 +0100 Importance: normal Sensitivity: Normal In-Reply-To: <78058d34-7cbb-a3e6-6471-e001b93a0523@gmail.com> References: <6fbfc0b8aa75852c4eed4d05e4c165a493304ced.1519811528.git.arvind.yadav.cs@gmail.com> <20180228113042.6a2f5177.cohuck@redhat.com> <20180228125629.3062ac1d.cohuck@redhat.com> <78058d34-7cbb-a3e6-6471-e001b93a0523@gmail.com> X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:uDY7uw3S+00zx3x0mBpASWpoGsm2Zo6YlGOoi2khI2a xoWz+x3QTZAd5wbSHirXJD5BmOjwTGRxJSAy1sOMJNdTWMsyR/ ahspvo3pbZTiaY/leRP8wfHmH1VFxx3Rtdxa+oMpLguME0JWSs EvlhB2mXwt5/UxDEzkEWwouefcEPGmjbQL1RwBDcvJ4TFzSj7Q UWU8LEtccbUIxigJ9yGvscmzIoQpD5Gp4+088T580iOPiFQhpL DbIzGY1raaFiIrzZYEgxb/ZDhLeTqlHXkr8t8tFCCYtEDsZLzV oFz2ZY= X-UI-Out-Filterresults: notjunk:1;V01:K0:S66t7Y5aESY=:sl62EUd2bHcGiSwq7aOzaB CIdJIhxGyp4nevlJIxIRo7rrJGd9qtDZHPyhZqaxO3/UjUtL2naxn6pFQR7wbAIQyT3AuxGrb Meci2JCgBk8xs2XECs7UDBME1KJyAewo4Q6GPpLY3HYrRWlAOqiz6PsXX6rxt4YRgVkvGy2qs jyUkPbOBwGxACN7ogfNOiA4oRxYzP6mfSTxkt8H5loYMzSXNI7FZKSC8Es+hEV99mojiuc0Ui htuGsRPtqRPYqCrb/WR5IVUxtB1NGZXzexnu+rec4EAcPc3YBQOUAdTGQqvXNA51D6dJ/O/Aa /gfQs8ygEf0rIYi3JrCFNfgylsIu97/nKlxWc3AUaNRapR8qrlOWy+YuEnqV0wJBLF8c63FsT 9ktb/pZ6Z5bPQVkbMOmme79ElteYtO1vXmDtMFk7xCuePSSG6zSV1elJysNx/v0IMwgPLl0/l 79b7m1KHDfeSGHD3d/6QVvKOzuCDCEeWMEE0u98vLbgumji01AX8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, > On Wednesday 28 February 2018 05:26 PM, Cornelia Huck wrote: > > On Wed, 28 Feb 2018 17:14:55 +0530 > > Arvind Yadav wrote: > > > >> On Wednesday 28 February 2018 04:00 PM, Cornelia Huck wrote: > >>> On Wed, 28 Feb 2018 15:24:16 +0530 > >>> Arvind Yadav wrote: > >>> > >>>> Free memory, if afiucv_iucv_init is not successful and > >>>> removing a IUCV driver. > >>>> > >>>> Signed-off-by: Arvind Yadav > >>>> --- > >>>> net/iucv/af_iucv.c | 5 ++++- > >>>> 1 file changed, 4 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c > >>>> index 1e8cc7b..eb0995a 100644 > >>>> --- a/net/iucv/af_iucv.c > >>>> +++ b/net/iucv/af_iucv.c > >>>> @@ -2433,9 +2433,11 @@ static int afiucv_iucv_init(void) > >>>> af_iucv_dev->driver = &af_iucv_driver; > >>>> err = device_register(af_iucv_dev); > >>>> if (err) > >>>> - goto out_driver; > >>>> + goto out_iucv_dev; > >>>> return 0; > >>>> > >>>> +out_iucv_dev: > >>>> + kfree(af_iucv_dev); > >>>> out_driver: > >>>> driver_unregister(&af_iucv_driver); > >>>> out_iucv: > >>>> @@ -2496,6 +2498,7 @@ static void __exit afiucv_exit(void) > >>>> { > >>>> if (pr_iucv) { > >>>> device_unregister(af_iucv_dev); > >>>> + kfree(af_iucv_dev); > >>>> driver_unregister(&af_iucv_driver); > >>>> pr_iucv->iucv_unregister(&af_iucv_handler, 0); > >>>> symbol_put(iucv_if); > >>> No, you must not use kfree() after you called device_register() (even > >>> if it was not successful!) -- see the comment for device_register(). > >> Yes, Your are right. First we need to call put_device() then kfree(). > >> I will send updated patch. > > No, that's not correct, either. device_register() will give up any > > reference it obtained, and the caller did not obtain any additional > > reference, so a put_device() would be wrong. A kfree() on a refcounted > > structure is wrong as well. > If you will see the comment for device_register() (drivers/base/core.c) > there is mentioned that > 'NOTE: _Never_ directly free @dev after calling this function, even > if it returned an error! Always use put_device() to give up the > reference initialized in this function instead.' > But as per you comment. we should not use. > Thanks, > In case that device_register() fails simply call device_put(). This will decrement the last reference and then free the memory. Regards, Lino