Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756221AbbLQKvU (ORCPT ); Thu, 17 Dec 2015 05:51:20 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:8857 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756185AbbLQKtd (ORCPT ); Thu, 17 Dec 2015 05:49:33 -0500 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Thu, 17 Dec 2015 02:34:54 -0800 From: Jon Hunter To: Thomas Gleixner , Jason Cooper , Marc Zyngier , Jiang Liu , Stephen Warren , Thierry Reding CC: Kevin Hilman , Geert Uytterhoeven , Grygorii Strashko , Lars-Peter Clausen , Linus Walleij , Soren Brinkmann , linux-kernel@vger.kernel.org, , Jon Hunter Subject: [RFC PATCH V2 1/8] irqdomain: Ensure type settings match for an existing mapping Date: Thu, 17 Dec 2015 10:48:22 +0000 Message-ID: <1450349309-8107-2-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450349309-8107-1-git-send-email-jonathanh@nvidia.com> References: <1450349309-8107-1-git-send-email-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3111 Lines: 100 When mapping an IRQ, if a mapping already exists, then we simply return the virual IRQ number. However, we do not check that the type settings for the existing mapping match those for the mapping that is about to be created. It may be unlikely that the type settings would not match, but check for this and don't return a valid IRQ mapping if the type settings do not match. Signed-off-by: Jon Hunter --- kernel/irq/irqdomain.c | 58 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 22aa9612ef7c..eae31e978ab2 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -568,8 +568,10 @@ static void of_phandle_args_to_fwspec(struct of_phandle_args *irq_data, unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) { + struct device_node *of_node; struct irq_domain *domain; irq_hw_number_t hwirq; + unsigned int cur_type = IRQ_TYPE_NONE; unsigned int type = IRQ_TYPE_NONE; int virq; @@ -587,23 +589,49 @@ unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) if (irq_domain_translate(domain, fwspec, &hwirq, &type)) return 0; - if (irq_domain_is_hierarchy(domain)) { - /* - * If we've already configured this interrupt, - * don't do it again, or hell will break loose. - */ - virq = irq_find_mapping(domain, hwirq); - if (virq) - return virq; + of_node = irq_domain_get_of_node(domain); - virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec); - if (virq <= 0) - return 0; + /* + * If we've already configured this interrupt, + * don't do it again, or hell will break loose. + */ + virq = irq_find_mapping(domain, hwirq); + if (!virq) { + if (irq_domain_is_hierarchy(domain)) { + virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, + fwspec); + if (virq <= 0) + return 0; + } else { + virq = irq_domain_alloc_descs(-1, 1, hwirq, + of_node_to_nid(of_node)); + if (virq <= 0) + return 0; + + if (irq_domain_associate(domain, virq, hwirq)) { + irq_free_desc(virq); + return 0; + } + } } else { - /* Create mapping */ - virq = irq_create_mapping(domain, hwirq); - if (!virq) - return virq; + cur_type = irq_get_trigger_type(virq); + } + + /* + * If the trigger type is not specified or matches the current + * trigger type then we are done so return the interrupt number. + */ + if (type == IRQ_TYPE_NONE || type == cur_type) + return virq; + + /* + * If the trigger type is already set and does + * not match this interrupt, then return 0. + */ + if (cur_type != IRQ_TYPE_NONE) { + pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n", + hwirq, of_node_full_name(of_node)); + return 0; } /* Set type if specified and different than the current one */ -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/