From patchwork Wed Aug 8 12:03:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10559829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC36613BB for ; Wed, 8 Aug 2018 12:04:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C649E2A9E4 for ; Wed, 8 Aug 2018 12:04:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA44F2A9F5; Wed, 8 Aug 2018 12:04:07 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5F95B2A9E4 for ; Wed, 8 Aug 2018 12:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Q9cWxNyoZbunUeJPmQe4x2ujuCpzSUA6/ll9lXcPY9Q=; b=MVlWL7Y+0bbxDW X7Rv8omSjMrvF5MaxBBhEqrhKLYRuea7toFvfBU7twAgDQFpSYmP5bummD/kqyA3m6Vk3EVQBLirK uUVHPZE/NL/X/erd3nSiTEzPV1g+7sHRJle1nl+5uea+PYWBVPp9QT5Cye0TmxIHTEqKRQdxmb0qE KuKOTKE2qPzfIuAp7Ups4PD5GOHg6uoCy1EO7xZyYxDJCgOnsMkb8bnOLGcbxqXaSgRlWy4coUcBR LbsdRYKGXtJRlg2A7yQhsJ1vSl/2CjqJfPYqO09LzOBojeamXAv1Ur5+zcuA15mYNnLu/Hs3CK93r EHinb9DTznPvrMLlIZsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnNC7-0008Ck-Rl; Wed, 08 Aug 2018 12:04:03 +0000 Received: from userp2120.oracle.com ([156.151.31.85]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnNC4-00080m-5g for linux-arm-kernel@lists.infradead.org; Wed, 08 Aug 2018 12:04:01 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w78BxiJV011241; Wed, 8 Aug 2018 12:03:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=KYec9+n3qUBOCziNFGWXpnJMQbb6SVsNV4pdryci0fM=; b=0xfqSPD2dLSYehLTJs3CAmyRZm3FyaFHgJCNsuToMFmWHHUreFAVwN8uqgkO5WzoPX73 HF9Sd02kHOXzHXhS+KaLnI19dwETQ25+sBxhhaAtDb+08oDckvZAGQOvi7OGBgwHi/Ry 0zHunsP4fl51V4x+L3NXdKWR6bghGFZ9fshpNPI0kUFfbTVGTgFGoInjRKLe6bISyPt7 ug9GmWyaPIjeZw8DhVejoYV59OYvbaWp18KlWK5wNKYWrNinGgbv+DFAzBSN6qiU8jPH drq++Ne+9jl29rdSaXvJtvp4o7QjGuXyIc/7zRSlvbW2UyRn9g7EQ89j5hnluIvBpm3G ug== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2kn4spwd8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Aug 2018 12:03:31 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w78C3TRj027193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Aug 2018 12:03:29 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w78C3SaE004400; Wed, 8 Aug 2018 12:03:28 GMT Received: from kili.mountain (/197.232.248.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 08 Aug 2018 05:03:27 -0700 Date: Wed, 8 Aug 2018 15:03:19 +0300 From: Dan Carpenter To: Thomas Gleixner , Ludovic Barre Subject: [PATCH] irqchip/stm32: fix init error handling Message-ID: <20180808120319.akmstg3ads325xcy@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8978 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=796 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808080125 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180808_050400_348541_21AC778C X-CRM114-Status: GOOD ( 16.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Cooper , Marc Zyngier , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Coquelin , linux-arm-kernel@lists.infradead.org, Alexandre Torgue Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If there are any errors in stm32_exti_host_init() then it leads to a NULL dereference in the callers. The function should clean up after itself. Fixes: f9fc1745501e ("irqchip/stm32: Add host and driver data structures") Signed-off-by: Dan Carpenter Reviewed-by: Ludovic Barre diff --git a/drivers/irqchip/irq-stm32-exti.c b/drivers/irqchip/irq-stm32-exti.c index 3df527fcf4e1..0a2088e12d96 100644 --- a/drivers/irqchip/irq-stm32-exti.c +++ b/drivers/irqchip/irq-stm32-exti.c @@ -603,17 +603,24 @@ stm32_exti_host_data *stm32_exti_host_init(const struct stm32_exti_drv_data *dd, sizeof(struct stm32_exti_chip_data), GFP_KERNEL); if (!host_data->chips_data) - return NULL; + goto free_host_data; host_data->base = of_iomap(node, 0); if (!host_data->base) { pr_err("%pOF: Unable to map registers\n", node); - return NULL; + goto free_chips_data; } stm32_host_data = host_data; return host_data; + +free_chips_data: + kfree(host_data->chips_data); +free_host_data: + kfree(host_data); + + return NULL; } static struct @@ -665,10 +672,8 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data, struct irq_domain *domain; host_data = stm32_exti_host_init(drv_data, node); - if (!host_data) { - ret = -ENOMEM; - goto out_free_mem; - } + if (!host_data) + return -ENOMEM; domain = irq_domain_add_linear(node, drv_data->bank_nr * IRQS_PER_BANK, &irq_exti_domain_ops, NULL); @@ -725,7 +730,6 @@ static int __init stm32_exti_init(const struct stm32_exti_drv_data *drv_data, irq_domain_remove(domain); out_unmap: iounmap(host_data->base); -out_free_mem: kfree(host_data->chips_data); kfree(host_data); return ret; @@ -752,10 +756,8 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data, } host_data = stm32_exti_host_init(drv_data, node); - if (!host_data) { - ret = -ENOMEM; - goto out_free_mem; - } + if (!host_data) + return -ENOMEM; for (i = 0; i < drv_data->bank_nr; i++) stm32_exti_chip_init(host_data, i, node); @@ -777,7 +779,6 @@ __init stm32_exti_hierarchy_init(const struct stm32_exti_drv_data *drv_data, out_unmap: iounmap(host_data->base); -out_free_mem: kfree(host_data->chips_data); kfree(host_data); return ret;