Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2235081rwd; Fri, 16 Jun 2023 00:45:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64x86ilVDS676XpaBLEACbuJej/7Eo/52wJWDL0q8pyXOaRvkWkZPN8qAj4qtv5R9SpZlZ X-Received: by 2002:a05:6214:2483:b0:62f:fe47:d486 with SMTP id gi3-20020a056214248300b0062ffe47d486mr874125qvb.45.1686901549132; Fri, 16 Jun 2023 00:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901549; cv=none; d=google.com; s=arc-20160816; b=vi44pIHJyDHatmWY7ab81PtGWtC85PzRO2c+OqX1aJOHful0oIKATNOB5Pal0MIbtS 0A7VccBpH7yrrNTOQ8QMgn1fePfpbXGkLM69x6RAfwdZU13ZbCPJVpRfQc6O9VFyGp/1 c+8h5rU+kGyegp+/65VJIqKCIZU4tefnfpv3zRn0gfaTGGYTQ7jJTeIv/iFep26jqV7X 4qi9ArXw4PlWllrw+zRSoXxKe2EXXYVxYcp46t7vcMAtg7IFRX7YXyPBcxPu4Jsq583B Yq3anPD0bPe3xymDrm0VYRyMp0crw6elaj388fIrmZ+SAGy+JhqH87aqo2Ctd3s+zK5g +zsg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a631854000000b0053fc290934dsi14063093pgy.361.2023.06.16.00.45.34; Fri, 16 Jun 2023 00:45:49 -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 S245268AbjFPHbN (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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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 --- drivers/gpio/gpiolib.c | 3 ++- include/linux/gpio/driver.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 --- base-commit: 659140df086c67f5eb77bbffcab34a7e8accd2a8 change-id: 20230616-fixes-gpiolib-irq-domain-2b69ecae0fdd