From patchwork Thu Sep 5 02:31:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 2853876 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DB7579F494 for ; Thu, 5 Sep 2013 02:32:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D162202FE for ; Thu, 5 Sep 2013 02:32:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98F4620259 for ; Thu, 5 Sep 2013 02:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754235Ab3IECcC (ORCPT ); Wed, 4 Sep 2013 22:32:02 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44450 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752809Ab3IECcB (ORCPT ); Wed, 4 Sep 2013 22:32:01 -0400 Received: from deadeye.wl.decadent.org.uk ([192.168.4.101]) by shadbolt.decadent.org.uk with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1VHPMV-0000cx-RF; Thu, 05 Sep 2013 03:31:59 +0100 Received: from ben by deadeye.wl.decadent.org.uk with local (Exim 4.80) (envelope-from ) id 1VHPMV-00061G-7Z; Thu, 05 Sep 2013 03:31:59 +0100 Message-ID: <1378348319.27597.16.camel@deadeye.wl.decadent.org.uk> Subject: [PATCH v2 2/4] [media] lirc_bt829: Fix iomap and PCI device leaks From: Ben Hutchings To: Jarod Wilson , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, devel@driverdev.osuosl.org Date: Thu, 05 Sep 2013 03:31:59 +0100 In-Reply-To: <1378348215.27597.14.camel@deadeye.wl.decadent.org.uk> References: <1378348215.27597.14.camel@deadeye.wl.decadent.org.uk> X-Mailer: Evolution 3.4.4-3 Mime-Version: 1.0 X-SA-Exim-Connect-IP: 192.168.4.101 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We must call iounmap() and pci_dev_put() when removed and on the probe failure path. Signed-off-by: Ben Hutchings --- drivers/staging/media/lirc/lirc_bt829.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/lirc/lirc_bt829.c b/drivers/staging/media/lirc/lirc_bt829.c index 9c7be55..a61d233 100644 --- a/drivers/staging/media/lirc/lirc_bt829.c +++ b/drivers/staging/media/lirc/lirc_bt829.c @@ -82,6 +82,7 @@ static struct pci_dev *do_pci_probe(void) } if (pci_addr_phys == 0) { pr_err("no memory resource ?\n"); + pci_dev_put(my_dev); return NULL; } } else { @@ -119,13 +120,16 @@ static void atir_set_use_dec(void *data) int init_module(void) { struct pci_dev *pdev; + int rc; pdev = do_pci_probe(); if (pdev == NULL) return -ENODEV; - if (!atir_init_start()) - return -ENODEV; + if (!atir_init_start()) { + rc = -ENODEV; + goto err_put_dev; + } strcpy(atir_driver.name, "ATIR"); atir_driver.minor = -1; @@ -141,17 +145,28 @@ int init_module(void) atir_minor = lirc_register_driver(&atir_driver); if (atir_minor < 0) { pr_err("failed to register driver!\n"); - return atir_minor; + rc = atir_minor; + goto err_unmap; } dprintk("driver is registered on minor %d\n", atir_minor); return 0; + +err_unmap: + iounmap(pci_addr_lin); +err_put_dev: + pci_dev_put(pdev); + return rc; } void cleanup_module(void) { + struct pci_dev *pdev = to_pci_dev(atir_driver.dev); + lirc_unregister_driver(atir_minor); + iounmap(pci_addr_lin); + pci_dev_put(pdev); }