From patchwork Wed Jul 19 16:34:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 704739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE2DC00528 for ; Wed, 19 Jul 2023 16:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjGSQfB (ORCPT ); Wed, 19 Jul 2023 12:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjGSQez (ORCPT ); Wed, 19 Jul 2023 12:34:55 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B3B519B4 for ; Wed, 19 Jul 2023 09:34:53 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bb2468257fso26165885ad.0 for ; Wed, 19 Jul 2023 09:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1689784493; x=1690389293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qKYrsbwFkQq7mxSa9jMwKApOtesu39YvxU4CShJxAhI=; b=ZvLnrY1568MZhaU/qXPqlRY4i0xnbvv+JpUWdEukxuSZl/js2HLyiHv64/36av5u3L kUf3LGIWVHKuEZeht318sYiL3rd50EHbqXS0SXHIx8tUVeo1gBBrSfKjl0evGs6RA3Ph g15fyNoVbYvClluNk5HufnB5tU27SwjMx5sRXAV13WPnOgbqZokaYWmyXm001+hU3wzZ pjyGKQGGSPgDbmCq74EU+FgzpiZ9qp8PbTz5jkNX35QqD0fTRTcLxPkTgUTIUr7UjxPB WIr+kn52YPa2S/ZaOznqmSXXYvLlDmov1AW9dqDgYj+1cv1QQdhKmZolsnN5t/wTas0R BFCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689784493; x=1690389293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qKYrsbwFkQq7mxSa9jMwKApOtesu39YvxU4CShJxAhI=; b=Zst9/bSAqipUWOyjvs5biQesDnzXAtgTTQZ0xm1KvGlH0Zueb/XoWtafvkcwBqrdrl NKr3nJP/JRGJAqTG3BKWdIrMyzkOiKf8xo3R2cvy9EfcNDMfcf4m/3Y31B90U+gbvvnw InkonNuEWcGg6C9PBytHpKN0jxAfNLqtMbZLKGIZchNAW474/0eOjA3DgzCC+2sblSCt FnOpOxG7bvxoZ9qTylHKxriDtAQeeABjPcAMEqq9EBccFFl/iLM9LzztXuJYls0Z4T3x b70+oIm348cWULlAaPRyBlEz0OqfHF1AplypKvCyx5RhQrp7JugbYCoSaRCMv58etRhQ imKQ== X-Gm-Message-State: ABy/qLbUIxAOuSB1Kd6yvjve8/qMVtQFzyjtkMhHSx26v8ujzFsUsNnS x6noJnZLDs/3fxH0p6SlcfSYcw== X-Google-Smtp-Source: APBJJlFipcbSu/NojN35HkrEsviKbFWtcYcx3WLvCCXo8NC5ZDt1xR4dBGQY2EMiUvSm/R5cz/pIvg== X-Received: by 2002:a17:903:48c:b0:1b8:7483:d47a with SMTP id jj12-20020a170903048c00b001b87483d47amr15035853plb.37.1689784492938; Wed, 19 Jul 2023 09:34:52 -0700 (PDT) Received: from sw06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id x6-20020a1709027c0600b001b0358848b0sm4199276pll.161.2023.07.19.09.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 09:34:52 -0700 (PDT) From: Samuel Holland To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: Emil Renner Berthing , Rob Herring , Frank Rowand , Samuel Holland , Palmer Dabbelt , Paul Walmsley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v2 3/4] gpio: sifive: Get the parent IRQ's domain from its irq_data Date: Wed, 19 Jul 2023 09:34:44 -0700 Message-Id: <20230719163446.1398961-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230719163446.1398961-1-samuel.holland@sifive.com> References: <20230719163446.1398961-1-samuel.holland@sifive.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Do not parse the devicetree again when the data is already available from the IRQ subsystem. This follows the example of the ThunderX and X-Gene GPIO drivers. The ngpio check is needed to avoid a possible out-of-bounds read. Signed-off-by: Samuel Holland --- Changes in v2: - New patch for v2 drivers/gpio/gpio-sifive.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index 6606c919d957..46a42109d6f5 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -180,9 +179,6 @@ static const struct regmap_config sifive_gpio_regmap_config = { static int sifive_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *node = pdev->dev.of_node; - struct device_node *irq_parent; - struct irq_domain *parent; struct gpio_irq_chip *girq; struct sifive_gpio *chip; int ret, ngpio; @@ -202,24 +198,16 @@ static int sifive_gpio_probe(struct platform_device *pdev) if (IS_ERR(chip->regs)) return PTR_ERR(chip->regs); - irq_parent = of_irq_find_parent(node); - if (!irq_parent) { - dev_err(dev, "no IRQ parent node\n"); - return -ENODEV; - } - parent = irq_find_host(irq_parent); - of_node_put(irq_parent); - if (!parent) { - dev_err(dev, "no IRQ parent domain\n"); - return -ENODEV; - } - for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { ret = platform_get_irq_optional(pdev, ngpio); if (ret < 0) break; chip->irq_number[ngpio] = ret; } + if (!ngpio) { + dev_err(dev, "no IRQ found\n"); + return -ENODEV; + } ret = bgpio_init(&chip->gc, dev, 4, chip->base + SIFIVE_GPIO_INPUT_VAL, @@ -248,7 +236,7 @@ static int sifive_gpio_probe(struct platform_device *pdev) girq = &chip->gc.irq; gpio_irq_chip_set_chip(girq, &sifive_gpio_irqchip); girq->fwnode = dev->fwnode; - girq->parent_domain = parent; + girq->parent_domain = irq_get_irq_data(chip->irq_number[0])->domain; girq->child_to_parent_hwirq = sifive_gpio_child_to_parent_hwirq; girq->handler = handle_bad_irq; girq->default_type = IRQ_TYPE_NONE;