From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757331AbdJKIpc (ORCPT ); Wed, 11 Oct 2017 04:45:32 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:18518 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756760AbdJKIp3 (ORCPT ); Wed, 11 Oct 2017 04:45:29 -0400 From: Kishon Vijay Abraham I To: Arnd Bergmann , Greg Kroah-Hartman , Kishon Vijay Abraham I CC: , , , Subject: [PATCH 2/3] misc: pci_endpoint_test: Fix pci_endpoint_test not releasing resources on remove Date: Wed, 11 Oct 2017 14:14:37 +0530 Message-ID: <20171011084438.8296-3-kishon@ti.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171011084438.8296-1-kishon@ti.com> References: <20171011084438.8296-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) in pci_endpoint_test_remove returns '0' which results in pci_endpoint_test_remove returning early without releasing the resources. This is as a result of misc_device not having a valid name. Fix it here. Signed-off-by: Kishon Vijay Abraham I --- drivers/misc/pci_endpoint_test.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index e787a63a321a..5cb624b6fa0a 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -551,17 +551,24 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id); misc_device = &test->miscdev; misc_device->minor = MISC_DYNAMIC_MINOR; - misc_device->name = name; + misc_device->name = kstrdup(name, GFP_KERNEL); + if (!misc_device->name) { + err = -ENOMEM; + goto err_ida_remove; + } misc_device->fops = &pci_endpoint_test_fops, err = misc_register(misc_device); if (err) { dev_err(dev, "failed to register device\n"); - goto err_ida_remove; + goto err_kfree_name; } return 0; +err_kfree_name: + kfree(misc_device->name); + err_ida_remove: ida_simple_remove(&pci_endpoint_test_ida, id); @@ -592,6 +599,7 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) return; misc_deregister(&test->miscdev); + kfree(misc_device->name); ida_simple_remove(&pci_endpoint_test_ida, id); for (bar = BAR_0; bar <= BAR_5; bar++) { if (test->bar[bar]) -- 2.11.0