From patchwork Tue Feb 20 11:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 203554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp324946dyc; Tue, 20 Feb 2024 03:11:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWE+FEjHswTovf+whXPiORF1YC2On1hi0Z2R/VbXWimL4HhvOQneDYB5ys5+GfIsTheYIG+TV8wAEq81+Mlf9fulfMIwg== X-Google-Smtp-Source: AGHT+IGQFv7wvWoszKcho3ls3bF1E8HVDdW6MQg+HQUbOwnTmc/a6JRbMPHpGnDW8QGV1/F8e8Kl X-Received: by 2002:a05:6a20:20c1:b0:19e:b534:1bcb with SMTP id t1-20020a056a2020c100b0019eb5341bcbmr10899637pza.23.1708427495285; Tue, 20 Feb 2024 03:11:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708427495; cv=pass; d=google.com; s=arc-20160816; b=je4AKtFF4Y9rFJx11TLMi4/TQq2negUF4BZnVNMjfGBRTy/C4lhZDaTpgAbznrSuHk /qgijctL5SFc5gFi6y6yuJZuWHHxscaYTIb4ULVZynAuU2Z4J7n9e1ozhjeeALXO1DsN L/7KRVraGzQIUArR9e8n5v3ZD9kcFdSiG52i8btA6UrQZGgKnwnWLRHl8uCI/fvuX1Xg IoJYEMDi2676sp90maR5zg69+PWaT1mGSpINU5yNHx5Ca8GpZKekjsG8MjZiCCxhLkXG O2H9CEbyaE0MCX/XYgPOeOP8lpW9qjA2PHrZdvABxtuL6/NQTL1b6JoXQuNb24zxxndK mziw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sUjOtVqB/hznZUhY9fXEYX8O3hPd38F8oY1TUvnjCBc=; fh=bQDfEZGNvUJOgi5NqmHXoHCcxSTUxiah6hyMMNL5D+k=; b=RLydk75Ysw/glVg5z1WS07q8oOSBDj2pWnTmCu9JWd834U9StfMqPGMoJlz+LOjQwr zBUFdrZl+SHTxjK6Mv27dPPQVh6/lSWJgYN3l1PMqXVK1pWLJN1u/RQltF1GPzjNrEvb rz/BQdrBWT7TyeQxbHS3Z2R3SwifE8W/0YnpKbD8m/OmQXyco/5UtFoZGibxGiM6WW7C CZTqw0/X8NbNwDhrbyqH2w1ZhUn9xr9Z7819F6CORKSUQ2Ul/jL5/u7CqImiGFYyMt33 MRSLgmU4ATFayBrJ/yidwMpKU+qvd481bGEOB/QVptKp9QCEIZvnlBZcTMthQneigye8 7U3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="Klp/Pvd0"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-72876-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72876-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i15-20020a170902c94f00b001dbb4048c6asi6114325pla.21.2024.02.20.03.11.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:11:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72876-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="Klp/Pvd0"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-72876-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72876-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 03290287A13 for ; Tue, 20 Feb 2024 11:11:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA15066B53; Tue, 20 Feb 2024 11:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Klp/Pvd0" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70C1165BCD; Tue, 20 Feb 2024 11:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708427438; cv=none; b=EU4wyPQx1UjfAwAvSX3VAEXvf343vpCc8gVE9jlXz+yON8Iacbb63Ren/Pl77p2xxFKyPLLzfE+k9bZqDkKNmYhNcfrzT3/mE8hZFJnGbjIv6jH3sPGD1oXIZ5Wbs8m/+czbw9rRWv9GHeWAAfVdh3VGgOw0ezhhrXJWA3pVmQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708427438; c=relaxed/simple; bh=ZDvB1WMZuKAfHW9xiHMtijGQ7/PSUaNUsnp1UoCHZp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G7cCatztCM9vhMK7V7E/jfeA1TyvTJeJN/d+ku2GzXfLciPtz42NKeR+YD63pRQRI2SqXZw+45xrYYkjuaaRq4xwjP6/imOw4s91+nNYUKZ/zQ9xFrZb35pBcHtt4AjC0tbJxf+oZ+RQ9FoLqMto6L5RxexWOZnQ0blD60IFm8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Klp/Pvd0; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 70DBF1BF214; Tue, 20 Feb 2024 11:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708427427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sUjOtVqB/hznZUhY9fXEYX8O3hPd38F8oY1TUvnjCBc=; b=Klp/Pvd0U6mkLtV4zBX11LCFFxxzp8QPqJ99ea+44bI94VlQ8Ti+5sUpwFrLaveiCiSv8b LyWbsoum7pFGT9R57LJxFyKGWmh2NydZ0IWtGhUApl/ti902KmCeHDYXMOAk2/ZUUHJOh3 DaQdYZw0ms5XykAhIPuv3r20GI18ens0Y7hYIl8Z311pjlwKjBnA+ZsKi/lnNqS0aifXAh LepoIeXeegXqv2gkxJ+gSd2BKwrvKXOleHG+aln9OCz1QTyrwpkryvTdh8T28ptPUX2oi4 /baYn8J9MV4Lfd1/e5yLqtFOIgBaJj/6uFIyashDbVIPJd6r+Yr9H80NP8PvIw== From: Herve Codina To: Bartosz Golaszewski , Kent Gibson , Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH 1/2] gpiolib: call gcdev_unregister() sooner in the removal operations Date: Tue, 20 Feb 2024 12:10:17 +0100 Message-ID: <20240220111019.133697-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220111019.133697-1-herve.codina@bootlin.com> References: <20240220111019.133697-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791416069159661176 X-GMAIL-MSGID: 1791416069159661176 When gpio chip device is removed while some related gpio are used by the user-space, the following warning can appear: remove_proc_entry: removing non-empty directory 'irq/233', leaking at least 'gpiomon' WARNING: CPU: 2 PID: 72 at fs/proc/generic.c:717 remove_proc_entry+0x190/0x19c ... Call trace: remove_proc_entry+0x190/0x19c unregister_irq_proc+0xd0/0x104 free_desc+0x4c/0xc4 irq_free_descs+0x6c/0x90 irq_dispose_mapping+0x104/0x14c gpiochip_irqchip_remove+0xcc/0x1a4 gpiochip_remove+0x48/0x100 ... Indeed, the gpio cdev uses an IRQ but this IRQ is not released (irq_free() call) before the call to gpiochip_irqchip_remove(). In order to give a chance to the gpio dev driver to release this irq before removing the IRQ mapping, notify the cdev driver about the gpio device removal before the gpiochip_irqchip_remove() call. Signed-off-by: Herve Codina --- drivers/gpio/gpiolib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 8b3a0f45b574..079181b9daa8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1051,6 +1051,13 @@ void gpiochip_remove(struct gpio_chip *gc) /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ gpiochip_sysfs_unregister(gdev); + + /* + * Tell gcdev that the device is removing. If any gpio resources are in + * use (irqs for instance), it's time for gcdev to release them. + */ + gcdev_unregister(gdev); + gpiochip_free_hogs(gc); /* Numb the device, cancelling all outstanding operations */ gdev->chip = NULL; @@ -1085,7 +1092,6 @@ void gpiochip_remove(struct gpio_chip *gc) * be removed, else it will be dangling until the last user is * gone. */ - gcdev_unregister(gdev); up_write(&gdev->sem); gpio_device_put(gdev); } From patchwork Tue Feb 20 11:10:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 203553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp324808dyc; Tue, 20 Feb 2024 03:11:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzLGqkpLhDxzkuMuVzlgUFewgQyUN/Ib+Gd9O9W3AK6nkUFUiR66rcJa7LFLN0OpF8il2GROPQkYg4nCXteF/EAgLJmQ== X-Google-Smtp-Source: AGHT+IGFSMjVdvacBxZWP05MLpijnjTccdKX8OZfrshUwJVzKlJ6NwpO91gsWcfGdYnMXpKQZjrk X-Received: by 2002:a17:906:3915:b0:a3e:c680:ee3a with SMTP id f21-20020a170906391500b00a3ec680ee3amr2724404eje.30.1708427474217; Tue, 20 Feb 2024 03:11:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708427474; cv=pass; d=google.com; s=arc-20160816; b=E6ywwaWVEFEDNEdsZoDWJo78CICwD6AO/DUwFBSfSLCpNCh05oRBtqlzECdfJwvQf+ HTaQxuSuUj9Om0HhNwSN7+5PqpUJderbF5yu8VfPtxbYQ95CFGhUBr2gCWPUE7dDHCpT RvUL1M9VYnvHkjgC3iXuCBh6QUZRsJjhU2fnEdbC0BYS+/7L5wwBL4E1pgamny270O3q UH6LqKKI6xf82X1066Gx1SLavmjuAugbHU6vBCNiEZfTjIlHZtQ7HDmtNoufD3hLgoxj CD3ZlPpvXnlIRDOFafsNUY/nkI3TmFI5meRHC+A8n6l6Uy+dya/CI+8rFIpGs5IbP4AJ V9qA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=c+dSIBMW24B1QEdw+4NnCXt+Ftn4RqDE56kLBoNW620=; fh=bQDfEZGNvUJOgi5NqmHXoHCcxSTUxiah6hyMMNL5D+k=; b=0Hg6usYmj+B5sEGzsSQSQ1YZ1w4dOWX0EHSW0eXFwxYsXRMJK++beNtu1wsJtON9nb GE/M+Mgo48levNHXXtChYd+8s/brYkGtT6+AnEybKEoshTVJ/SGFRQBYbwtRajtSGvJy IlAUTg57VEFcsm8bJQAA1hWPtiCQhUS4vy4tphkh/awRufC1PS7jkskoh67YgiOZ5m0D Hh6zFhzkrHU38qIxzGVZ1/C/er2Db49RtkQ79frK1WtMsH9z3PQHd9053/LNiqFLUu7N RQOy3kghW48RP7te/rKXVql4S/+hDMEKc3LyPnZ8jv/A9PYQHzZSvxvjt+TNp6SF4Ac+ dcqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BVyvJKXa; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-72877-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72877-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hd13-20020a170907968d00b00a3eb2a3c3e9si1576539ejc.1006.2024.02.20.03.11.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:11:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72877-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BVyvJKXa; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-72877-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72877-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CE8961F242B9 for ; Tue, 20 Feb 2024 11:11:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3526367754; Tue, 20 Feb 2024 11:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="BVyvJKXa" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70C4465BD7; Tue, 20 Feb 2024 11:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708427439; cv=none; b=JRUqY9cJ/Sa1Cue5fjF6KnRaZKpUmH9JOYvh2Xq4VFSnmKo1mn3bDnt/0RUZmFma4wd0Zq8iMPh62XhSmKU6x7P5IXI2rH+4ST6vAMJmp9DVqIdM6dK19idPNfT8fQUYtba8k5u/j1yRmizWkX8wyXeENRWl2mC2UACMlP385uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708427439; c=relaxed/simple; bh=+gtPF82Psk+0scOoKi//Kqv72HSichWCQkcD4dfiT54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nkmalsi8tThYEDQFzZqvPp4IjvTlFLFJ1S3e5b0hFKBCb4kQCZoEJYRF2L2VXIe8AwWtqsYcfftXzvbTg4j0NEqfIcgw5BMO3UcI0LVVZr3mWvehjA1Q1jsveXjyI21jtz/xEUVguUIjAMZbrHC9/9UtxbemkHpX9po7CDmSHas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=BVyvJKXa; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id DF7C51BF216; Tue, 20 Feb 2024 11:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708427428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c+dSIBMW24B1QEdw+4NnCXt+Ftn4RqDE56kLBoNW620=; b=BVyvJKXaQGyrX5QqXRvRovkMd9I52tgnpBvFb8sGJW2ToyYfkTjQSpmRPbC7MWlr87qARC UuykfAJ2Gzw/xw5HTJEEqnS9JgcllN4ozixRVIdJYUmaJ03EwrSA/HPHMJ0LyBIfwuFF1T Vn1eXzZi+zEtjlgWodDARgePGpWww+XhLl3uCVA3aeN0DFXy7cgyb1C+jG8yyVHnXCLaiV irE83aWO1lAbdCOCsco0uZvMOIkdgUuXesKYs7D8/MbzY6shCK+YPobQUfruQ4uRjyYmG/ JGkV8ouvIR9DZ5KZSudRIcYRPo7yRuxpmIc3uM6rb3FMCWiLekvld3vCTbWM1g== From: Herve Codina To: Bartosz Golaszewski , Kent Gibson , Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH 2/2] gpiolib: cdev: release IRQs when the gpio chip device is removed Date: Tue, 20 Feb 2024 12:10:18 +0100 Message-ID: <20240220111019.133697-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220111019.133697-1-herve.codina@bootlin.com> References: <20240220111019.133697-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791416047157736740 X-GMAIL-MSGID: 1791416047157736740 When gpio chip device is removed while some related gpio are used by the user-space, the following warning can appear: remove_proc_entry: removing non-empty directory 'irq/233', leaking at least 'gpiomon' WARNING: CPU: 2 PID: 72 at fs/proc/generic.c:717 remove_proc_entry+0x190/0x19c ... Call trace: remove_proc_entry+0x190/0x19c unregister_irq_proc+0xd0/0x104 free_desc+0x4c/0xc4 irq_free_descs+0x6c/0x90 irq_dispose_mapping+0x104/0x14c gpiochip_irqchip_remove+0xcc/0x1a4 gpiochip_remove+0x48/0x100 ... Indeed, the gpio cdev uses an IRQ but this IRQ is not released when the gpio chip device is removed. Release IRQs used in the device removal notifier functions. Also move one of these function definition in order to avoid a forward declaration (move after the edge_detector_stop() definition). Signed-off-by: Herve Codina --- drivers/gpio/gpiolib-cdev.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 2a88736629ef..aec4a4c8490a 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -688,17 +688,6 @@ static void line_set_debounce_period(struct line *line, GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE | \ GPIO_V2_LINE_EDGE_FLAGS) -static int linereq_unregistered_notify(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct linereq *lr = container_of(nb, struct linereq, - device_unregistered_nb); - - wake_up_poll(&lr->wait, EPOLLIN | EPOLLERR); - - return NOTIFY_OK; -} - static void linereq_put_event(struct linereq *lr, struct gpio_v2_line_event *le) { @@ -1189,6 +1178,23 @@ static int edge_detector_update(struct line *line, return edge_detector_setup(line, lc, line_idx, edflags); } +static int linereq_unregistered_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct linereq *lr = container_of(nb, struct linereq, + device_unregistered_nb); + int i; + + for (i = 0; i < lr->num_lines; i++) { + if (lr->lines[i].desc) + edge_detector_stop(&lr->lines[i]); + } + + wake_up_poll(&lr->wait, EPOLLIN | EPOLLERR); + + return NOTIFY_OK; +} + static u64 gpio_v2_line_config_flags(struct gpio_v2_line_config *lc, unsigned int line_idx) { @@ -1898,6 +1904,11 @@ static int lineevent_unregistered_notify(struct notifier_block *nb, struct lineevent_state *le = container_of(nb, struct lineevent_state, device_unregistered_nb); + if (le->irq) { + free_irq(le->irq, le); + le->irq = 0; + } + wake_up_poll(&le->wait, EPOLLIN | EPOLLERR); return NOTIFY_OK;