From patchwork Mon Jun 19 08:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 109840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2867075vqr; Mon, 19 Jun 2023 02:16:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VXlv+KY1MXNFnp4fNNdUBe/odv16K6yDIdzEjvXIywD4LOYK79LWkiTVQDEyaQ6K1asiP X-Received: by 2002:a05:6808:15a4:b0:39e:d344:b4c0 with SMTP id t36-20020a05680815a400b0039ed344b4c0mr3695802oiw.34.1687166185992; Mon, 19 Jun 2023 02:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687166185; cv=none; d=google.com; s=arc-20160816; b=TccJZ/bqQpSmDsaQSrxo8nbxS+eLPzwLhF+vN5NMDW2SCqOfyRCPJHIqKmtSCujEa2 rUgzJXwh9AbQUcZcTI5WPr00N6wg4+xpefi0v+zJopM1IWHeiDuCn4lm7JXlUYnptPgG SvQGb5ZP3u3tzxdSKyz+b6EHOamcfpWMqQfRNQXpWNd7P8XOgvzpX0uB1EI6mBGJa7ou 2+IELz8mYJb54yZS5f+t61s8xemxnc8jw/0SdTfIoem7ZQkfZdGl6x0ekxgRSQ77pMFX 79iWkv8w5WALH5l2tVRemfbRKDriRLtbkTadK+CbbuPcbos5jjwdVuQzB0UNPMGMZQ0t 6Y5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=rUGoESrEUM29CKhSbBFKs8XDLpvYdDyOUT99KYCuQak=; b=Ph8ixBkaITrdNheFC0V11tq9x0IiyjI8olun/Pq+qmjrRCb8lbVndHG6KjraYxE6gV 43A0R8EwpfI0oLDLF1x+MlpmGVij/zf4Hg8Tp20mUvdWuYVcxXpN9kHTBq4/G+h8DtyT IvZrKeFQmrsLcngcX8igK3CbPoeN9HEB8kEhRJbRoZ/QZCZeqFEAhFxCuE6jwiByPynA c6RdFdiUytl0lmqNgTzHcR2kgEMS+mX4/OLiNWGHKD7D7sCUs/xhNR44UFwHQcTANw1R +elNPJr8QkErxNl+yKvqEVa2lnWchFMw7DrdyfKTrkWL/FOZweOTxXIPcehWdmZSGcMX 7AdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="aN/OC1mU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk13-20020a056a02028d00b0055384407e41si5988425pgb.855.2023.06.19.02.16.13; Mon, 19 Jun 2023 02:16:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="aN/OC1mU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjFSI6I (ORCPT + 99 others); Mon, 19 Jun 2023 04:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjFSI5o (ORCPT ); Mon, 19 Jun 2023 04:57:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D8CB1997; Mon, 19 Jun 2023 01:56:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A50386009F; Mon, 19 Jun 2023 08:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD4B7C433BA; Mon, 19 Jun 2023 08:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687164987; bh=SXbRj7a8K92shQSYS+f3sTL1ucqnqo6+0RjDa+QJfv0=; h=From:Date:Subject:To:Cc:From; b=aN/OC1mU3PD4B3Jk2EKdPZBCeT4FdZXy6Yrs/p7jMGYap6hhGssOzrt+EPVELd4nm S9WJgOHt/QjWiSOXr7yXlcinJU3t0g+IUIhgCEcfofuxRW+/vI8R2lxTcj5d2/QBt9 Qi2Bv54drtMYcNwhuE/uPb0z6CeUnVAlvmVHJkVcEYxNYCGHVrUS4UaTH2VR7jMWU9 YUkQLbF9Uuzz4eZ3p0jR5elQtZJR1hLJ1EWt1/fLLvBdAEMYElvaP+zNor3f01/0wA mEP+YMwJxUcJ8aUAUMxHUNdsMGdJRFME88RKg6K4DiWTyM2kIHaRzghBIOLb3dZ+5p O2Zyf4FQKEIDw== From: Michael Walle Date: Mon, 19 Jun 2023 10:56:07 +0200 Subject: [PATCH v2] gpiolib: Fix irq_domain resource tracking for gpiochip_irqchip_add_domain() MIME-Version: 1.0 Message-Id: <20230616-fixes-gpiolib-irq-domain-v2-1-e28b47fc3e45@kernel.org> X-B4-Tracking: v=1; b=H4sIACYYkGQC/42OTQ6CMBCFr0K6dkxbkyKuvIdh0dIBJkILU0I0h LtbOIHL7728n00kZMIkHsUmGFdKFEMGfSlE09vQIZDPLLTUN2mUgZY+mKCbKA7kgHgGH0dLAbQ zFTYWZeu9yHFnE4JjG5r+KBhtWpAPY2I8S7L6qjP3lJbI3/PCqg71j7VVgQJdtngvpXeVUc83c sDhGrkT9b7vP+F6AhTaAAAA To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Jiawen Wu , Michael Walle X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769121970524935981?= X-GMAIL-MSGID: =?utf-8?q?1769121970524935981?= Up until commit 6a45b0e2589f ("gpiolib: Introduce gpiochip_irqchip_add_domain()") all irq_domains were allocated by gpiolib itself and thus gpiolib also takes care of freeing it. With gpiochip_irqchip_add_domain() a user of gpiolib can associate an irq_domain with the gpio_chip. This irq_domain is not managed by gpiolib and therefore must not be freed by gpiolib. Fixes: 6a45b0e2589f ("gpiolib: Introduce gpiochip_irqchip_add_domain()") Reported-by: Jiawen Wu Signed-off-by: Michael Walle Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- Changes in v2: - change flag name to domain_is_externally_allocated - Link to v1: https://lore.kernel.org/r/20230616-fixes-gpiolib-irq-domain-v1-1-27fe870db961@kernel.org --- drivers/gpio/gpiolib.c | 3 ++- include/linux/gpio/driver.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) --- base-commit: 659140df086c67f5eb77bbffcab34a7e8accd2a8 change-id: 20230616-fixes-gpiolib-irq-domain-2b69ecae0fdd diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7c6fefcbebd1..2664275c25f3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1740,7 +1740,7 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gc) } /* Remove all IRQ mappings and delete the domain */ - if (gc->irq.domain) { + if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) { unsigned int irq; for (offset = 0; offset < gc->ngpio; offset++) { @@ -1786,6 +1786,7 @@ int gpiochip_irqchip_add_domain(struct gpio_chip *gc, gc->to_irq = gpiochip_to_irq; gc->irq.domain = domain; + gc->irq.domain_is_allocated_externally = true; /* * Using barrier() here to prevent compiler from reordering diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 5c6db5533be6..67b8774eed8f 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -251,6 +251,14 @@ struct gpio_irq_chip { */ bool initialized; + /** + * @domain_is_allocated_externally: + * + * True it the irq_domain was allocated outside of gpiolib, in which + * case gpiolib won't free the irq_domain itself. + */ + bool domain_is_allocated_externally; + /** * @init_hw: optional routine to initialize hardware before * an IRQ chip will be added. This is quite useful when