Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp769826iob; Wed, 18 May 2022 12:33:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2OGUTDPDlg97BzXKLOVumAuafIdObv/FvbF27agTWIBbrhPQf6i+rwE9X2pX65n0u5z07 X-Received: by 2002:a17:90a:2e83:b0:1da:3273:53ab with SMTP id r3-20020a17090a2e8300b001da327353abmr1644934pjd.14.1652902401274; Wed, 18 May 2022 12:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652902401; cv=none; d=google.com; s=arc-20160816; b=hM817P+ID8+F/VrKBqrb7Z1idWO9TY8pmfvRXIu6MFSSzxW9vIwn449Oc4wNIvxGPI 8xtZAWp+W2P0nZbOGBq9kNS2s0c62Il/gBEXpLj3aFv+jLn6Tr/DjJO8bgdnjo6fN6Kv Yk1MCHR3pHbEm93g4AJZ6t13mIno6I3fyEKPbY4BwRLGacY8lXaOm/Adjng5qWP2An2m mlqH6sNNXEKShc7vpEjcfD6cO/PhUmZ4Ec7NkwOkGR0Iia6PatlvZ0tHse39/zGz5Ojh myf0aV+Kvb7J1A9cjLdHzRugeB4QOBgQvR2bvHEXsJmwxqQ0NvDJjn0mWZzEy/38jChL FWjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=W+v2c+Pe4uLRFX26cIHGD3kUQufsPk/TlByF6TZg/xY=; b=m3oWNNctmCFBodE8Dmi+rcYRvzQp/xnXIO3yWXN0P06iQjRCgQdiE2Kk/ReVG+ze89 4JiOYq+X5F1lwi9I13SeCHiQ9OXpsvLmG/IhbhGhX0Ua8YikU6sV2ahB3ungOubZNSy8 Wzuq8KBwVF/fYns3krgo3aTmC1lSLVd/FwoP46e0d9QgR+qOR57KcQoeCvLmG1SrjnCP LdtDREyss4tmNLnFogDbMucRw4OvfbWFrEeWvmfJg+wNgqyYTamBC4o/S7xUBCePE8LD JRLMEPbJvZYnFgRW7QR7eXOsSg27SNoKk/2sKI/kJLfVz9nT9Gtu5DsinmSXkFqPWZed 2UEA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p13-20020a056a000b4d00b0050a49c21b85si4566549pfo.50.2022.05.18.12.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 12:33:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B5041C1942; Wed, 18 May 2022 12:30:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242011AbiERTa1 (ORCPT + 99 others); Wed, 18 May 2022 15:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241989AbiERTa0 (ORCPT ); Wed, 18 May 2022 15:30:26 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 832F222DA04; Wed, 18 May 2022 12:30:24 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.91,235,1647270000"; d="scan'208";a="121409068" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 19 May 2022 04:30:23 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id B4A394004CF5; Thu, 19 May 2022 04:30:16 +0900 (JST) From: Lad Prabhakar To: Marc Zyngier , Geert Uytterhoeven , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Linus Walleij , Bartosz Golaszewski , Thierry Reding , Jonathan Hunter , Bjorn Andersson , Andy Gross , Philipp Zabel , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , linux-renesas-soc@vger.kernel.org, Phil Edworthy , Biju Das , Lad Prabhakar Subject: [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq Date: Wed, 18 May 2022 20:29:22 +0100 Message-Id: <20220518192924.20948-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220518192924.20948-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220518192924.20948-1-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a check to validate GPIO hwirq is always within the range of hwirq_max set in the GPIO irq domain. Signed-off-by: Lad Prabhakar --- drivers/gpio/gpiolib.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 65e344a23c6a..c1de7bb54c13 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1028,6 +1028,7 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc, * it is necessary to keep this around. */ if (is_fwnode_irqchip(gc->irq.fwnode)) { + struct irq_domain *domain = gc->irq.domain; int i; int ret; @@ -1061,6 +1062,11 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc, i, ret); continue; } + if (WARN(hwirq >= domain->hwirq_max, + "error: hwirq 0x%x is too large for %s\n", + (int)hwirq, domain->name)) + continue; + fwspec.fwnode = gc->irq.fwnode; /* This is the hwirq for the GPIO line side of things */ fwspec.param[0] = hwirq; @@ -1436,6 +1442,9 @@ static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset) ret = gc->irq.child_offset_to_irq(gc, offset, &hwirq); if (ret) return ret; + if (WARN(hwirq >= domain->hwirq_max, + "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name)) + return -EINVAL; spec.fwnode = domain->fwnode; spec.param_count = 2; spec.param[0] = hwirq; -- 2.25.1