From patchwork Sat Oct 2 16:20:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Palmer X-Patchwork-Id: 12532245 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69A0BC433F5 for ; Sat, 2 Oct 2021 16:22:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 20561611AE for ; Sat, 2 Oct 2021 16:22:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 20561611AE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=0x0f.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=mtJ1Poxg6SK1bYRN/thrgIT9pmeopTXQDyzRU49S+mE=; b=R89jPCqr6B8jfr I4gCT5TuqtaBifmrXzISAv85WA2cthV8c9JNW/7HDSpqibmFQ+72HSUz//fm0UH63WdcO8h/O+/AJ /vKtty+cbOfCuSCoQKbb7g0bqU8T6PTvvILdnCynKPcdye9wsbn6lpx7VZiwDc+4V6VRH7pCtHlpJ yNVV6YKT9KU0Zh0oc3yi1VZWnR77U3crZP0o/JhYv2XAvVYR8RzOjRRmWdxpFKTljzmhnPAT/13yK Um81nB2wWewb0Sj2lGxLmNOGdayIH9Q4k4jrCyiqj2SoxOp3WfpNo9PCJE0HFg2Mt9PVIoJNxUjAu NAeZgJKECvUn5kqhD+yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mWhkN-002RBk-G9; Sat, 02 Oct 2021 16:20:23 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mWhkJ-002RBJ-Oi for linux-arm-kernel@lists.infradead.org; Sat, 02 Oct 2021 16:20:21 +0000 Received: by mail-pj1-x1032.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so1425161pjb.2 for ; Sat, 02 Oct 2021 09:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0x0f.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=j4rLuo2ykiHXggmeHqYRj08h89CMbpW00i+4hL2kTmc=; b=Zt5xeF9HzCVGHVXKypIC1N9e6gFdZxQjTDO05pMhNdfZxoVI515qfvoqGJqgKyZn9u pP3Dp5b9dCrR0pPPcfA+cVU3qeG9Z6n4JbpR7CGLbbdq0IWKDui8Y61h1v7TCSkc0Tiv fZUHPUzps+vfU6jN/YV0rwjE1i3IMgZS8zzSI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=j4rLuo2ykiHXggmeHqYRj08h89CMbpW00i+4hL2kTmc=; b=scEPEf5mTDGv2n1mvO4c9xDYUxR5xnxfcdjs2HFj2rAoHyHs6M2dEPLM2NYT6Q1wOY 4D5s80iI4xbq0Svm6pLewQHfWvdaPn2heWXIY4vyH+RvKO4CCBkXJKrueb8/5zsqE1zW WsnCXQgp1xa+Mx3Ta0Hga+01xzHOfzjzcLJqjgVZKraKfWVDYf9WFrEQRHNFYptrqeQR tsymyrdR7+72WFRRzKji+4d20otcM+cvMJNkIS7ZsHpKuNdRmjeN05qcJwmOscCvJeWe x97cpOnyX9mqCqPqs+CMJyzYG2kMbDsFmkuRyQVM5Jf+O5IoUEKJ5vdzH4HPB4V4MySK bycg== X-Gm-Message-State: AOAM531PIJESqH+cx/EX9coTGc0ba4W0cXbDWkNL7YKef9pH+AImYwYh kfnbQxtj7QRWLasK6yz87Di45A== X-Google-Smtp-Source: ABdhPJzRoDmBHnGFqBTldPEU7mvie17JJefDNDPsAGw6oqPncVA8o03SuuO6+KqT5JsacYzh5eyBUw== X-Received: by 2002:a17:90a:19d2:: with SMTP id 18mr20095582pjj.27.1633191618169; Sat, 02 Oct 2021 09:20:18 -0700 (PDT) Received: from shiro.work ([2400:4162:2428:2f01:7285:c2ff:fe8e:66d7]) by smtp.googlemail.com with ESMTPSA id nr14sm5223729pjb.24.2021.10.02.09.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Oct 2021 09:20:17 -0700 (PDT) From: Daniel Palmer To: linus.walleij@linaro.org, brgl@bgdev.pl, linux-gpio@vger.kernel.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [RFC PATCH] gpiolib: Move setting the flow handler and don't set it at all if there is a parent domain Date: Sun, 3 Oct 2021 01:20:00 +0900 Message-Id: <20211002162000.3708238-1-daniel@0x0f.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211002_092019_950016_43B9FC09 X-CRM114-Status: GOOD ( 16.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Calling irq_domain_set_info() before irq_domain_alloc_irqs_parent() can cause a null pointer dereference as the parent domain isn't ready yet. Move irq_domain_set_info() to after irq_domain_alloc_irqs_parent(). A side effect of this is that irq_domain_set_info() will now overwrite the flow handler from the parent domain. So if there is a parent domain do not set the flow handler anymore. This allows gpio-msc313.c to level it's irq domain on top of the new irq controller in later SigmaStar SoCs without crashing. Link: https://lore.kernel.org/linux-arm-kernel/20210914100415.1549208-1-daniel@0x0f.com/ Signed-off-by: Daniel Palmer Suggested-by: Marc Zyngier --- drivers/gpio/gpiolib.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d1b9b721218f..993eeced6b4f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1103,19 +1103,6 @@ static int gpiochip_hierarchy_irq_domain_alloc(struct irq_domain *d, } chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq); - /* - * We set handle_bad_irq because the .set_type() should - * always be invoked and set the right type of handler. - */ - irq_domain_set_info(d, - irq, - hwirq, - gc->irq.chip, - gc, - girq->handler, - NULL, NULL); - irq_set_probe(irq); - /* This parent only handles asserted level IRQs */ parent_arg = girq->populate_parent_alloc_arg(gc, parent_hwirq, parent_type); if (!parent_arg) @@ -1137,6 +1124,27 @@ static int gpiochip_hierarchy_irq_domain_alloc(struct irq_domain *d, parent_hwirq, hwirq); kfree(parent_arg); + + if (!ret) { + /* If there is a parent domain leave the flow handler alone */ + if (d->parent) + irq_domain_set_hwirq_and_chip(d, + irq, + hwirq, + gc->irq.chip, + gc); + /* Otherwise set the flow handler supplied by the gpio driver */ + else + irq_domain_set_info(d, + irq, + hwirq, + gc->irq.chip, + gc, + girq->handler, + NULL, NULL); + irq_set_probe(irq); + } + return ret; }