From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756268AbdKNSks (ORCPT ); Tue, 14 Nov 2017 13:40:48 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:53610 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755901AbdKNSkk (ORCPT ); Tue, 14 Nov 2017 13:40:40 -0500 X-Google-Smtp-Source: AGs4zMZ+VGbbcff3yuYERbkNshN7eh4jO09ZRrS4N/rU/qLgA6RfmaYL3XMUWL9BQLGgzaengyw21A== Subject: Re: [PATCH] Input: davinci_keyscan: Free memory occupied by davinci key scan device To: Dmitry Torokhov References: <9203eaebf020cbebf5224221d789a0163490d654.1510666872.git.arvind.yadav.cs@gmail.com> <20171114181434.lpwhojwemzdruet6@dtor-ws> Cc: linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org From: arvindY Message-ID: <5A0B38A2.4070208@gmail.com> Date: Wed, 15 Nov 2017 00:10:34 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20171114181434.lpwhojwemzdruet6@dtor-ws> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 14 November 2017 11:44 PM, Dmitry Torokhov wrote: > On Tue, Nov 14, 2017 at 07:15:14PM +0530, Arvind Yadav wrote: >> Here, key_dev is NULL in input_free_device() and It will not free >> memory occupied by davinci key scan device. Move "key_dev = NULL" >> after input_free_device(). > No, this is absolutely wrong. It is disallowed to call > input_free_device() after calling input_unregister_device(), because > input core will free the device once the last reference is dropped. That > is why we set "key_dev" to NULL to turn input_free_device() into a noop. Yes, You are correct. Once device is unregistered it will get freed. Thanks, :) >> Signed-off-by: Arvind Yadav >> --- >> drivers/input/keyboard/davinci_keyscan.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/input/keyboard/davinci_keyscan.c b/drivers/input/keyboard/davinci_keyscan.c >> index b20a5d0..22cb8d2 100644 >> --- a/drivers/input/keyboard/davinci_keyscan.c >> +++ b/drivers/input/keyboard/davinci_keyscan.c >> @@ -290,13 +290,13 @@ static int __init davinci_ks_probe(struct platform_device *pdev) >> free_irq(davinci_ks->irq, davinci_ks); >> fail5: >> input_unregister_device(davinci_ks->input); >> - key_dev = NULL; >> fail4: >> iounmap(davinci_ks->base); >> fail3: >> release_mem_region(davinci_ks->pbase, davinci_ks->base_size); >> fail2: >> input_free_device(key_dev); >> + key_dev = NULL; >> fail1: >> kfree(davinci_ks); >> >> -- >> 1.9.1 >> > Thanks. >