Received: by 10.223.185.116 with SMTP id b49csp6106165wrg; Wed, 28 Feb 2018 04:11:58 -0800 (PST) X-Google-Smtp-Source: AG47ELuRB01kVSgVVDfM7XPlgt+K2WVQRJtaIcVM9VqBfuv7moyi/wUOGqzW9zfHYX/KHF95dXii X-Received: by 10.99.55.70 with SMTP id g6mr12416450pgn.284.1519819918396; Wed, 28 Feb 2018 04:11:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519819918; cv=none; d=google.com; s=arc-20160816; b=NLKIp/4AEFzlVggTkqu5v3MV+knZXU5JBgbbk8K4DvLBLVCGs5ayeiBjahOfBNw+VV XpCui53pLtLXiKSM0KANhOWVqOexu/4sNbIKWwXBFU3zH8CyZEzeQp3LJWZ1PfRVN0Xq AmVW6NYFwTu8kf3V5xd7WFg4rzsJpvd94nqnRT1iwrgfTXK/AUXRAzyfd761JjAQNKBl ZwgZA9KqBugy2eYEGwA+E9PctJcDwWLbAD9aq8RU9s2R1HG+S+YWqugzgVpNhRHgF2Ta GGK4H5S4F6au+3HfaBWwNCPm9n7zvOiQ4xVI+RXPesdC34e98y/K8CendD1oEbBniFaN 9bfw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature:arc-authentication-results; bh=9FD2Znr/ngnJvcYo0bqCd84oClS1AuaLeJUXxDchz7I=; b=0KE0erfZQ3o39Q0b3tuSH2jUXHZXYzRHFZ/XajYEe+mF/b6PlaBU6U/EiY0hc5r8o4 KAN3NbTSvh3Hxexq1UZQQflcpw7FIesfJweusx++7hiumgkwYPNLCQcZHkxVsfomBjr/ zivcmmRDvmI7RONRrhVOm7LXHZipCxdejt8vCo1e0lEn+9wGIITTXz87wuxiyC3mHpSJ sK3GDTdjlijhg1y5p6990eercJM5OQWmyHzQbd0F+JNPE3zSUnSWbpLqjhlO5w1GEGLL 3xb/mLHpXQXZ6XC5PfPCX4NWVnLyBi/oDve4wg17bVk8Pjvuf5tRaDM0LINKDuVbfvFL pE6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=naPzcCF0; 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 n10-v6si1210389plp.33.2018.02.28.04.11.43; Wed, 28 Feb 2018 04:11:58 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=naPzcCF0; 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 S932204AbeB1MKe (ORCPT + 99 others); Wed, 28 Feb 2018 07:10:34 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:38060 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932155AbeB1MK2 (ORCPT ); Wed, 28 Feb 2018 07:10:28 -0500 Received: by mail-io0-f194.google.com with SMTP id g21so2952688ioj.5; Wed, 28 Feb 2018 04:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=9FD2Znr/ngnJvcYo0bqCd84oClS1AuaLeJUXxDchz7I=; b=naPzcCF0fJmCqTW+hJae/q1loDM/yLF1oowAxc63mh0EeB8AwD2fkoknaSgLfn7NWb pxZmkeiSNb7jLWeT+lUmf/9HpwcFFgeKWq5SKwS8o8MkkIKkTWsdbGGGhp/wF1NQXW4k xD/gNB58kSXxTBK8Xy/9rP+yMiE1wiikbWCFwcoTl9ySsd9WhErMceyfW7bN0QYFjfdG iCGZlFxD1S3TDJN+V0J0Ow7vRWh66qGfnSK1CCyAjwgNvzPKaZZbcgbKxQiDQlieyj4j ITJlrVP5qtNMopMJLNoUtyRf4DYa3EdpLyNnCVCEghELzENJH9zR2mYH74cODfA/zZHa NMrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=9FD2Znr/ngnJvcYo0bqCd84oClS1AuaLeJUXxDchz7I=; b=XRaXxW7V6N7B2GJTc6CYbwZMvb+p7Buo1TPgkNyW36qnhUX285f4mdMoQuKBw3qRrV BdJUNqEPppYXNTrAa3mOcIxq7zqeHh3zPxHX0nruewuKzYEIcgnY1RrYXKhPRbZucYR6 OkdgqAk+PiQZe439IbB7OtiTTfe8xz00SHnOUMVj8doBntBdp49X99FcwASJ3ReZFSEz TMOHGRa7f1syaoafJ2f2DIyML7SnB8fvO3WbYjwhfbKnt1wP5svMReVUbt0Kyw7wO7Dx eprw1JXVPo22wBPzqizxI+ZS6b4ov0OQgeIGhIBfKsv2jqpmwUUSFx5SbQOkpztMtWE9 Miuw== X-Gm-Message-State: APf1xPC1NNjUtRRNNIzrIRaurFJnYY2qwljVXdLk1S2RkFaw/cV28TJl x1z9KcYZKbGxqKmBe3XYeLPLf58V X-Received: by 10.107.132.227 with SMTP id o96mr20534188ioi.58.1519819827556; Wed, 28 Feb 2018 04:10:27 -0800 (PST) Received: from [10.17.129.40] ([149.23.17.254]) by smtp.gmail.com with ESMTPSA id l16sm1610076iti.36.2018.02.28.04.10.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 04:10:27 -0800 (PST) Subject: Re: [PATCH] net: iucv: Free memory obtained by kzalloc To: Cornelia Huck References: <6fbfc0b8aa75852c4eed4d05e4c165a493304ced.1519811528.git.arvind.yadav.cs@gmail.com> <20180228113042.6a2f5177.cohuck@redhat.com> <20180228125629.3062ac1d.cohuck@redhat.com> 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 From: Arvind Yadav Message-ID: <78058d34-7cbb-a3e6-6471-e001b93a0523@gmail.com> Date: Wed, 28 Feb 2018 17:39:53 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20180228125629.3062ac1d.cohuck@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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,