From patchwork Fri Nov 17 13:38:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 838988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="u5AZ5QxF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydfNy1SMrz9s0Z for ; Sat, 18 Nov 2017 00:39:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758232AbdKQNjm (ORCPT ); Fri, 17 Nov 2017 08:39:42 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:44088 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758156AbdKQNjL (ORCPT ); Fri, 17 Nov 2017 08:39:11 -0500 Received: by mail-lf0-f66.google.com with SMTP id w23so2711314lfd.11; Fri, 17 Nov 2017 05:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=5a1WBjC1BvIQA7EUQqCUM5qG4tmUDS6xvYo5IQr8e4k=; b=u5AZ5QxFUeG6s+MJXdrnt5KWPXaLNXM9ulX4dlueNHn2DNARKtNBFoNHze4+rxADc5 D/qNUfMl/Otga7JQr9/5Y30ii/8Uz5jn+jgGrl15NuyfyO3q4QvhIgx3HRawiwGdLhLL cMlgt4e+jYnEaJ/Kyg6bT3jBehPaZINdYjBSuIBpj6zQyp4vAYYTFnZTcY11bosEk+QU PiviLmUAOEEikJQp6tXmcDyczalbuvQTfyvUcbxrG7IzuBtvULWuRROdH3Ze6pgc2nsx L4OPlkRRrJZqHFp30IN2Yg+GSmjUdOGuvwYOWqy0bUz2y5NOyakJI5yrilFiE0Pbe0Rp ccYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=5a1WBjC1BvIQA7EUQqCUM5qG4tmUDS6xvYo5IQr8e4k=; b=jbRI+ue881iqMvlzqpKHe2GLOks21dwOpq3S+Nj3AJO26feFpf1FjlwA08uOtU5oFr 2U8A5lOqhZAbK0NgnZNgT60SGYJOqCgf0rG88StN9i2CaIcxrHPdhofK4D9ahoy0ThMm 3bZT/qaw2SimvMmv4zzFvuJyyfFQGKc78+q4zLmTGZvq3oNnomyMaRSqNUqi43Jyk6ZP UVAw0/rS9eMytV2h/xCBV1UYmR2EGx/FWvw23af1a9yVAQBN5CLmfn/zF7YppE9JMhMr zoYDw7F1G63CwK3uSE0eqItRqbfYzPQnjVSAI+IDkh+6fjZ3pnwvQv/0eVOgRno6mIUT 45HQ== X-Gm-Message-State: AJaThX66u19Mc8xQXMF4LCP9s58fuD0Ao3NCZOR9Fy1VBt3bnpCuerQr koOl5W2quONmhjgJFYt2128= X-Google-Smtp-Source: AGs4zMZxqO0vY8S+MHzfDqqIedI42V+LRQBi6npRDhbJuYWycTA3QJXPJDvRxZynh2lxMh+YD8zDSw== X-Received: by 10.25.199.139 with SMTP id x133mr894015lff.87.1510925948612; Fri, 17 Nov 2017 05:39:08 -0800 (PST) Received: from xi.terra (c-c0bae655.07-184-6d6c6d4.cust.bredbandsbolaget.se. [85.230.186.192]) by smtp.gmail.com with ESMTPSA id f13sm889009lja.25.2017.11.17.05.39.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 05:39:07 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1eFgrK-0000Lj-Ne; Fri, 17 Nov 2017 14:39:06 +0100 From: Johan Hovold To: Murali Karicheri Cc: Lorenzo Pieralisi , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH v2] PCI: keystone: fix interrupt-controller-node lookup Date: Fri, 17 Nov 2017 14:38:31 +0100 Message-Id: <20171117133831.1300-1-johan@kernel.org> X-Mailer: git-send-email 2.15.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Fix child-node lookup during initialisation which was using the wrong OF-helper and ended up searching the whole device tree depth-first starting at the parent rather than just matching on its children. To make things worse, the parent pci node could end up being prematurely freed as of_find_node_by_name() drops a reference to its first argument. Any matching child interrupt-controller node was also leaked. Fixes: 0c4ffcfe1fbc ("PCI: keystone: Add TI Keystone PCIe driver") Cc: stable # 3.18 Acked-by: Murali Karicheri Acked-by: Lorenzo Pieralisi Signed-off-by: Johan Hovold --- v2 - amend commit message and mention explicitly that of_find_node_by_name() drops a reference to the start node - add Murali's and Lorenzo's acks drivers/pci/dwc/pci-keystone.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/pci/dwc/pci-keystone.c b/drivers/pci/dwc/pci-keystone.c index 5bee3af47588..39405598b22d 100644 --- a/drivers/pci/dwc/pci-keystone.c +++ b/drivers/pci/dwc/pci-keystone.c @@ -178,7 +178,7 @@ static int ks_pcie_get_irq_controller_info(struct keystone_pcie *ks_pcie, } /* interrupt controller is in a child node */ - *np_temp = of_find_node_by_name(np_pcie, controller); + *np_temp = of_get_child_by_name(np_pcie, controller); if (!(*np_temp)) { dev_err(dev, "Node for %s is absent\n", controller); return -EINVAL; @@ -187,6 +187,7 @@ static int ks_pcie_get_irq_controller_info(struct keystone_pcie *ks_pcie, temp = of_irq_count(*np_temp); if (!temp) { dev_err(dev, "No IRQ entries in %s\n", controller); + of_node_put(*np_temp); return -EINVAL; } @@ -204,6 +205,8 @@ static int ks_pcie_get_irq_controller_info(struct keystone_pcie *ks_pcie, break; } + of_node_put(*np_temp); + if (temp) { *num_irqs = temp; return 0;