Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752947AbbFNRri (ORCPT ); Sun, 14 Jun 2015 13:47:38 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33824 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbbFNRra (ORCPT ); Sun, 14 Jun 2015 13:47:30 -0400 From: Takeshi Yoshimura To: Dominik Brodowski , Greg Kroah-Hartman , Vaishali Thakkar , linux-pcmcia@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Takeshi Yoshimura Subject: [PATCH 1/1] pcmcia: Fix resource leaks in yenta_probe() and _close() Date: Mon, 15 Jun 2015 02:43:59 +0900 Message-Id: <1434303839-2146-1-git-send-email-yos@sslab.ics.keio.ac.jp> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2455 Lines: 91 There are some resource leaks in yenta_probe() and _close(). I fixed the following issues with some code cleanups. Thanks to Dominik's suggestions. On the error path in yenta_probe(): - a requested irq is not released - yenta_free_resources() and pci_set_drvdata(dev, NULL) are not called In yenta_close(): - kfree(sock) is not called - sock->base is always set to non-NULL when yenta_close() is called, therefore the check in yenta_close() is not necessary. Signed-off-by: Takeshi Yoshimura --- drivers/pcmcia/yenta_socket.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 965bd84..440ccde 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -802,13 +802,13 @@ static void yenta_close(struct pci_dev *dev) else del_timer_sync(&sock->poll_timer); - if (sock->base) - iounmap(sock->base); + iounmap(sock->base); yenta_free_resources(sock); pci_release_regions(dev); pci_disable_device(dev); pci_set_drvdata(dev, NULL); + kfree(sock); } @@ -1259,25 +1259,34 @@ static int yenta_probe(struct pci_dev *dev, const struct pci_device_id *id) /* Register it with the pcmcia layer.. */ ret = pcmcia_register_socket(&socket->socket); - if (ret == 0) { - /* Add the yenta register attributes */ - ret = device_create_file(&dev->dev, &dev_attr_yenta_registers); - if (ret == 0) - goto out; - - /* error path... */ - pcmcia_unregister_socket(&socket->socket); - } + if (ret) + goto free_irq; + + /* Add the yenta register attributes */ + ret = device_create_file(&dev->dev, &dev_attr_yenta_registers); + if (ret) + goto unregister_socket; + return ret; + + /* error path... */ + unregister_socket: + pcmcia_unregister_socket(&socket->socket); + free_irq: + if (socket->cb_irq) + free_irq(socket->cb_irq, socket); + else + del_timer_sync(&socket->poll_timer); unmap: iounmap(socket->base); + yenta_free_resources(socket); release: pci_release_regions(dev); disable: pci_disable_device(dev); free: + pci_set_drvdata(dev, NULL); kfree(socket); - out: return ret; } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/