From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754570AbdHYJKd (ORCPT ); Fri, 25 Aug 2017 05:10:33 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:31165 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754286AbdHYJKb (ORCPT ); Fri, 25 Aug 2017 05:10:31 -0400 Date: Fri, 25 Aug 2017 12:10:00 +0300 From: Dan Carpenter To: Marc Zyngier , David Daney Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] irqdomain: potential Oops in irq_domain_push_irq() Message-ID: <20170825091000.z5taav6xj2yds6ch@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This code generates a Smatch warning: kernel/irq/irqdomain.c:1511 irq_domain_push_irq() warn: variable dereferenced before check 'root_irq_data' (see line 1508) irq_get_irq_data() does sometimes return NULL pointers so it does look like this code could Oops. I've moved the check for NULL earlier to fix this bug. Signed-off-by: Dan Carpenter --- v2: redo the commit message diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index b9c688944429..e84b7056bb08 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1505,10 +1505,10 @@ int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg) if (WARN_ON(!irq_domain_is_hierarchy(domain))) return -EINVAL; - if (domain->parent != root_irq_data->domain) + if (!root_irq_data) return -EINVAL; - if (!root_irq_data) + if (domain->parent != root_irq_data->domain) return -EINVAL; child_irq_data = kzalloc_node(sizeof(*child_irq_data), GFP_KERNEL,