From patchwork Wed Jan 18 08:11:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Yadav X-Patchwork-Id: 9522857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8B806020A for ; Wed, 18 Jan 2017 08:20:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BEA428543 for ; Wed, 18 Jan 2017 08:20:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F2C728545; Wed, 18 Jan 2017 08:20:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33A7B28543 for ; Wed, 18 Jan 2017 08:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751319AbdARIUr (ORCPT ); Wed, 18 Jan 2017 03:20:47 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33355 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdARIUr (ORCPT ); Wed, 18 Jan 2017 03:20:47 -0500 Received: by mail-pg0-f67.google.com with SMTP id 194so802801pgd.0 for ; Wed, 18 Jan 2017 00:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RMdN0VuX51bEmcRhmhsElzqSCRP1qnkBdVj3Ev9erc0=; b=INgN5db5T8mT0m9Ym3VVc1eFANbHC8LEhFpZp8iQqGxpli9UteVRvM5VItVUAQL7sD aeQKkeQfxepYf4UcO1/h5SbaYAx3bymmYJSpinrgp6+10s5DX6vxTfZgtZybBgIpHt+U sWv0JUgeuOjfD+96EhNZ7DXmZXs9qvddrZdl1wo+tn4yAJ7Hz66Zxn9P/6PngCorVSYz A44606VS1kriape1/UXO5g4jMcmHOG0+f3Uyw0+DLuC7McKrvte6FVBenLgTAtVpv5Wp nvDF3N7hpQvPuoLpXgzLW14ojtdnvfF+SP3XZjBbl4u/ptBamCVWeGYsm18Zr/USmIkV ag9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RMdN0VuX51bEmcRhmhsElzqSCRP1qnkBdVj3Ev9erc0=; b=kXos2xzbMNHwNuSzVDsbpD+oa6zT+x/QOaxtLpXnoOVFQeNKdlUknu4H2hf8ehzhZV NNrBaH7dBjpNptDYz0zKAJVS8C4N/epcPJzE3eC4fkY+lylfrEziogdPfpg0az8tP5ws GKhSZ6FrRzsEBWnq4c/Frkdo20mg7IsWBgJlTW0cd39KmJtbdwLSRWAswqwRIE2rF7aT gH18SLkDVY1flm6Cel36KOY3LLyxvgRe/llbk5tM6IYcApIvk/OTMgvowUf4DprtF3o/ yvLas0B2fTCMib0F2W9WEnW8jQz3s5Ohx5ocoQTT8/YdEYXwKTDJwEQcJi9xJN53dwVz 37Qg== X-Gm-Message-State: AIkVDXLCOIwEdIlbkcEPI6NrLP/rNPJmuPcEfc7WW3/qa80edpQ8aWzi1XIPZS9KOKQCYA== X-Received: by 10.84.150.129 with SMTP id h1mr3235947plh.9.1484727124425; Wed, 18 Jan 2017 00:12:04 -0800 (PST) Received: from symbol-HP-Z420-Workstation.zebra.lan ([223.31.70.102]) by smtp.googlemail.com with ESMTPSA id b1sm11818861pfa.28.2017.01.18.00.12.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 00:12:03 -0800 (PST) From: Arvind Yadav To: jejb@parisc-linux.org, deller@gmx.de Cc: linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] parisc : eisa :- Prevent resource leake and NULL error in error path Date: Wed, 18 Jan 2017 13:41:31 +0530 Message-Id: <1484727091-2357-1-git-send-email-arvind.yadav.cs@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here, If ioremap_nocache will fail. It will return NULL. Kernel can run into a NULL-pointer dereference. If eisa_probe will fail, Handle ERROR properly. -Release resource -Free irq line. -Unmap I/O memory from kernel address space. Signed-off-by: Arvind Yadav --- drivers/parisc/eisa.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c index 103095b..2c7f90f 100644 --- a/drivers/parisc/eisa.c +++ b/drivers/parisc/eisa.c @@ -334,7 +334,7 @@ static int __init eisa_probe(struct parisc_device *dev) result = request_irq(dev->irq, eisa_irq, IRQF_SHARED, "EISA", &eisa_dev); if (result) { printk(KERN_ERR "EISA: request_irq failed!\n"); - return result; + goto error_release; } /* Reserve IRQ2 */ @@ -358,6 +358,11 @@ static int __init eisa_probe(struct parisc_device *dev) } } eisa_eeprom_addr = ioremap_nocache(eisa_dev.eeprom_addr, HPEE_MAX_LENGTH); + if (!eisa_eeprom_addr) { + result = -ENOMEM; + printk(KERN_ERR "EISA: ioremap_nocache failed!\n"); + goto error_free_irq; + } result = eisa_enumerator(eisa_dev.eeprom_addr, &eisa_dev.hba.io_space, &eisa_dev.hba.lmmio_space); init_eisa_pic(); @@ -371,12 +376,21 @@ static int __init eisa_probe(struct parisc_device *dev) eisa_dev.root.slots = result; eisa_dev.root.dma_mask = 0xffffffff; /* wild guess */ if (eisa_root_register (&eisa_dev.root)) { + result = -ENOMEM; printk(KERN_ERR "EISA: Failed to register EISA root\n"); - return -1; + goto error_iounmap; } } return 0; + +error_iounmap: + iounmap(eisa_eeprom_addr); +error_free_irq: + free_irq(dev->irq, &eisa_dev); +error_release: + release_resource(&eisa_dev.hba.io_space); + return result; } static const struct parisc_device_id eisa_tbl[] = {