Received: by 10.223.185.116 with SMTP id b49csp6090899wrg; Wed, 28 Feb 2018 03:57:25 -0800 (PST) X-Google-Smtp-Source: AH8x227Gtpe7Fn6/s8fSnbxPCdBYGkiK7lrm3PbGlou3V0lXfuLhkyjt4lFc06ZSHWvoC8b9QDsu X-Received: by 2002:a17:902:8ec6:: with SMTP id x6-v6mr18040555plo.402.1519819045842; Wed, 28 Feb 2018 03:57:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519819045; cv=none; d=google.com; s=arc-20160816; b=OXCNpG2WY5hc5DgTK9yU+zWh55y/vz/nsdeern6btQxp5cr0k2VfDKyNai04HwA6aY PhAgxw2eHxIVlpBpNOP9g67SpcJ/MdPk28BLAHIl7OKQMLHyNjWm+hX1LuhGyJwJdPjE uNSgRvPF7tsrU5Gx7KHPzO8J9RljObdh75mcG19wsH0nPMiM7FvPjk2LH2JNgt+SVlWZ rc71sO8mkEBGVOKopuznDKrMU5RD2fMvGOGxtAN/3OwhrUpuN7zEs5OUD7lsuDegggVJ zhSScD12+Doog/0n5J9Det8vyVlkWFC9vOJXdFxjeCqUPVle2QIHe2AvWhG8DKAHl2hi JD2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=LS3cSFu4TuqCWpq7mg7JiyvD5xu7qTx8hoVyx8AJehA=; b=r0k2o2Y0mz4Yc4gMrKN8RO0uASpm9y5JxmDlqtFswyDJvsHm2k4roqjvkS7PIkY2t7 Wg2owQg+2PmtyrHmPhb28XKgmNLrf+gikaG1sOg0WhLmI8l/2ZjPJzePtS/A8cN3wEvf 6nEVqLVIRsup5PxKqRXtnYtZS7b7QOx/Q9ojSF1x+2+hybadyXF2mujtdiMFWeaY8OaF pCLkb21dc6QsMSloIosPFF4z1sYesqlthLhffTq0p85v6u6EWT0/gmyv2rLoCoPgEElm irHqMQHvrGbgR34p6KzKC8mPkILU2qy8Tl3idXBEqtUE4tEMJHTdqEhit9JibetSn6e9 TXgw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8-v6si1180646plk.192.2018.02.28.03.57.11; Wed, 28 Feb 2018 03:57:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279AbeB1L4f (ORCPT + 99 others); Wed, 28 Feb 2018 06:56:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52224 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752028AbeB1L4e (ORCPT ); Wed, 28 Feb 2018 06:56:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2FDF402290A; Wed, 28 Feb 2018 11:56:33 +0000 (UTC) Received: from gondolin (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D218215671B; Wed, 28 Feb 2018 11:56:32 +0000 (UTC) Date: Wed, 28 Feb 2018 12:56:29 +0100 From: Cornelia Huck To: Arvind Yadav Cc: 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: Re: [PATCH] net: iucv: Free memory obtained by kzalloc Message-ID: <20180228125629.3062ac1d.cohuck@redhat.com> In-Reply-To: References: <6fbfc0b8aa75852c4eed4d05e4c165a493304ced.1519811528.git.arvind.yadav.cs@gmail.com> <20180228113042.6a2f5177.cohuck@redhat.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Feb 2018 11:56:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Feb 2018 11:56:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.