From patchwork Fri Jun 16 07:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 108916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1156697vqr; Fri, 16 Jun 2023 00:53:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XZ4ye/GBU/Ue1TPhR+8rlV1KdlaCtGmCvRXTuGA5iFiTJp0VscQMG8UMyR3ra7WRvxtxq X-Received: by 2002:a05:6a20:3d8f:b0:11d:235f:af93 with SMTP id s15-20020a056a203d8f00b0011d235faf93mr1626120pzi.44.1686901990962; Fri, 16 Jun 2023 00:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901990; cv=none; d=google.com; s=arc-20160816; b=AOtLM+17M0/GmFJTQ77P8LrauB3l0pnp0KsexHQ/9pj18VFLWaPJUuLsYJB9k60gX8 xonJTxZtjt+Ql5ayiFBe23aCHvZOL7ndLXhnq83zTVMpSJspHeYqHxf7OpAiZbkB8r+H ZRRQWC6B8nHqzcEo1I7tp11IkD/kuMkX6/PhnwnnCL0yXO/wQce0h9B8+AL83X8c6qk6 hnRjxrTsLTteF6kyx5L5Wft0CpDxkP1uXjcnSMMbbkRyrjmLJKT0e33dpQkegmRbvaHI Ig9wLuJQTXTx/dxJYXPaHTl7bi6LzbmqP7NWDCY/mn/HaeFGtzqfQ+xpBRZnH/tQhp4/ JLyQ== 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=Wiu5zGBFoOmFGLpBMVdYk3kfCjgAA7EuPWdJGNqEVWg=; b=pHaXPnLdGtNwxAYnYWJIEaxn5+EX47X/jz0WUd47kNBPGg1dAbbCS0G4ebDET3fVtC zngKGhvo7svakOi/vMn9yt3dpGM9d3YDoGhAMevCE5+6Iz6mB36+dv5DqRwssnnwEMDU TrMl8Y7y/7q6/YoAv/Wd285n3cKZumKAs9GhYKfU7tD/pURmj6FOqHdQTghR8k08pF6Y iZ0sIHAcoWAygsuw5dfEju4sEa8BlYUFlXN8EMLRInIyoJXSVy0+WbkRmHX/KW2TtBBo iztfCTlIzbs0ap7a4nk7ELaagSyMsPwgW0zPtpoALDoSRLzfjrrWWetcuWOD3CDnoMfc vn5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bg20uc3V; 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 b13-20020a63d80d000000b0053f3d04e66csi11701800pgh.699.2023.06.16.00.52.56; Fri, 16 Jun 2023 00:53:10 -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=bg20uc3V; 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 S244947AbjFPHbN (ORCPT + 99 others); Fri, 16 Jun 2023 03:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245204AbjFPHar (ORCPT ); Fri, 16 Jun 2023 03:30:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C33DC30F5; Fri, 16 Jun 2023 00:30:33 -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 D97A062D2F; Fri, 16 Jun 2023 07:30:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9264C433C0; Fri, 16 Jun 2023 07:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686900632; bh=f+LgoALENSeGbpRznsBkL8AxsTrl0/0l4wQlFDbC4tk=; h=From:Date:Subject:To:Cc:From; b=bg20uc3VVcGfkNHiSyAKcdlbAiPmikUy10j3PxceC9t7yRWsfmydaak5wD2PjpD9f kSP/LnDonrV0txvbiUKjwi/yPQy6ovogAqxh1ulpZk+qpGd74pgff1GYmP9tLYPbGh mxdQz5oSqVOj04b1JN5ujFlEwZSVKSB0a3vJ/kkQSQfUKQPVXwY65LUOfU0K7Af9uY Y4r+XR07rlRyCD2oMdsXGO14YcZMhDvYXreRoukRfHHvQn/v/IYxqwlScRnA+e4uCU wjsc1d3hcKzJpEigOnr6XdWZcRCAahMHYN92qXjfAqO7KWTbGeLfld3MMAQ+xYzdu7 +MOIwTRVHFA3A== From: Michael Walle Date: Fri, 16 Jun 2023 09:30:06 +0200 Subject: [PATCH] gpiolib: Fix irq_domain resource tracking for gpiochip_irqchip_add_domain() MIME-Version: 1.0 Message-Id: <20230616-fixes-gpiolib-irq-domain-v1-1-27fe870db961@kernel.org> X-B4-Tracking: v=1; b=H4sIAH0PjGQC/x2M0QqDMAxFf0XyvEDtoOB+ZewhbaMGtHXJkIH47 6t7PPdyzgHGKmzw6A5Q3sWklgb9rYM0U5kYJTcG7/zdhT7gKF82nDapi0QUfWOuK0lBH8PAidi NOUPTIxljVCppvgIr2Yf1Ojblf6Stz9d5/gCKCoi4gwAAAA== 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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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?1768844942441316447?= X-GMAIL-MSGID: =?utf-8?q?1768844942441316447?= 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 --- 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..b0e3a3de2bf2 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_ext && 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_ext = 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..3dbfed83823b 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_ext: + * + * True it the irq_domain was allocated outside of gpiolib, in which + * case gpiolib won't free the irq_domain itself. + */ + bool domain_is_ext; + /** * @init_hw: optional routine to initialize hardware before * an IRQ chip will be added. This is quite useful when