Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp740689imm; Wed, 8 Aug 2018 05:05:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyWk6iNP5Zaarr1TpsEwIKQfkC3RE6+Fp0lq/ohDHj7IuWNHvgmAt6VoNEzz+Sj6qFHwsOJ X-Received: by 2002:a62:d24a:: with SMTP id c71-v6mr2670065pfg.242.1533729926113; Wed, 08 Aug 2018 05:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533729926; cv=none; d=google.com; s=arc-20160816; b=d2qmA6MN7aXxLdo2Uqm/chvTnCKGP2FqQvYOnWeh++d4y5Sn61WkNDlz0bLQYXt4sH upWu02hcYtS4ikZZDoAdAZOOz6OZ5nAk2D6UkXSp5Sox6IL8YH8/ul3O1/+YfrmzhHEF RWxkzXJaJawXuHi6VQNc5IGgXk94G2MPqABiVzqiYIxfzC8dFs+dWM564x1HyByXoj54 kv3h0XcZQSRDcEICe6OHIcvvb6n91pAOd0pCmfnMURt8GvuvpwOJi3uYa5e3xucT69ea eJtNxfwEzmsD0cY4kp7ZteIubmBrLes1+RypPgxSceH8swR/9N3X9m2xNN6L+OzZYGXd bWiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=KYec9+n3qUBOCziNFGWXpnJMQbb6SVsNV4pdryci0fM=; b=ALFtFiNd+tsBpsmMQMKQhfnVnACg6xOfrN/ETnRySN15gnl0+DlIxvBgK1+MNegcGF 3WcTduH21h7E1pDDaOOR4UydvLKmS7CHzvqFHlxkh9NThs4dJ6SKsI3nGDz7M2ng7Ljh lclJN+/tZ2kbfEp4iD3xVq39N90ETNrxwj8NMS03IJ1yCZ5ClbEYoeWw8JZ7ifKpV8km fLjQgxi6+0BkOjDMzTTTL5VoxBwe/A/IPlkUpgQyxawdJIGhgCwZC20zyDGD3iKtUzMd ++LLSZJ8uiw31nT8W658LDa+oEebhdS+nnYr1oezmCvHMt8XCoADnOOG0zuIuzQG+UnV bHzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=0xfqSPD2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62-v6si4683901pfu.79.2018.08.08.05.05.11; Wed, 08 Aug 2018 05:05:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=0xfqSPD2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbeHHOX2 (ORCPT + 99 others); Wed, 8 Aug 2018 10:23:28 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:42060 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726756AbeHHOX2 (ORCPT ); Wed, 8 Aug 2018 10:23:28 -0400 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 Cc: Jason Cooper , Marc Zyngier , Maxime Coquelin , Alexandre Torgue , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-janitors@vger.kernel.org Subject: [PATCH] irqchip/stm32: fix init error handling Message-ID: <20180808120319.akmstg3ads325xcy@kili.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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;