From patchwork Tue Feb 27 11:34:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 207150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2635664dyb; Tue, 27 Feb 2024 03:36:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXETWb9DmqO0tYwf/eMwMnZTnik0NaNQ897APlpMo0yNtSuXbOjW/pgird+fTg2WkhP91f6qcgMKI34zZ0mW7SoQVGBXg== X-Google-Smtp-Source: AGHT+IGn3L7hlDQMJhuUQ7PVYJeaw4KHB80yFh+wQ9wjDZ5t20oV+sCVcVXc/uDoGsz1wMFPHSe/ X-Received: by 2002:a05:6358:88e:b0:17b:64af:cd7b with SMTP id m14-20020a056358088e00b0017b64afcd7bmr8831279rwj.16.1709033805441; Tue, 27 Feb 2024 03:36:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709033805; cv=pass; d=google.com; s=arc-20160816; b=OtOwm8P3DMLTMOu0wbj6Y3E3OlP4JjW4lIiANoj+cmaV85vWoRgSo7GAacVQJVUos7 tzALg4REW2f4wYaba8G+gKEE/9nv8GHOR8N9A2SzkLnxqddxsdI/Q9lMJOZjq4riVS75 tyg4Lpt7MPG5VPA1QhY2TJ2sHyOesCY7E0uaYWCjVTZFKcgRpzEQ3N1MmAEw4L+IrIDA yBRr4y3MV9bu2jqnSqGVub8y84IhkN4f1vHMvD37ETSUx0n5x9pF4p2+8V/si4iRR9eB 1u0hevPZh3jPcVuRu/CvXwp0CSOIl64PnKZpaZxOgtnEMmb5vX2r9Sy0K7uygzEXjrQq FsyQ== 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=JEy1WKZu79JY8RBIlDzPDmv8Cqag9mXrU8thTH54FTE=; fh=ONUZ3m01L0DVQm+Cjotv2dXDuBgIcWiaHC6/g+ZSH6Y=; b=KMKq8cm/Nf9dGD5wurIOOg6hEzkEJFhd9v0612KIsuPnm/g6KFJacAYcxmWwK7DhNL SHYhHvNkt/fo4tdmpKU09sF9FZH+ZzdHMaJwJqoXSL4Ts4zVdgmk4o4RxPpb/rinA7cW P82b9ofGMy9icuEGmlDNfs2fQk1SQ7+yTt6RdAerlx7l66UYYS9bU+nbYEmO8aq0bEWP pEtDqAy0GtLvtv5HjhLAIcly1PgKHZYQPCih9oXOL7dlTRjZbe+ort5VHrYs0FgWvdBt cyWEnMA4v2FIihNSuR2UyuRfr/h05FLLp6AUnkq1/KZ5QJm/tJipruJOBJAk2XIy+BS9 pelA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RNSH9eQ+; 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-83132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83132-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kc24-20020a056214411800b0068f8cad5187si7165394qvb.460.2024.02.27.03.36.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:36:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RNSH9eQ+; 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-83132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83132-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B0FDC1C22DB5 for ; Tue, 27 Feb 2024 11:35:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECF3713AA22; Tue, 27 Feb 2024 11:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="RNSH9eQ+" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 DFC0F139568; Tue, 27 Feb 2024 11:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709033684; cv=none; b=Wjf5uWpF9YxolDCHsFmu68wv79hcZnBwuPal5gs7u5Y2Zb8g8B8yIYGH42X1YfsMDXyyGg//vYyzS2pcP0O/4jrYKzETvRlWEYl1pgrtqPCrDLOuJO1yIZiT5rAdzHyY7A/pvxU5NWSe8rvYZ3dexZeFvyCXxgJP2CQk/OlPYNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709033684; c=relaxed/simple; bh=kvF+KDgzeivY+RAQ8/BHt2sd41hOYzWE/MAHOlgwnpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hF5EUpSK9UtWUFX4qy6wX3NFLdw8yfl/1K+FapfgJlSP28SFzc1fb0/2rqQBRF+nzkLr5ltKc2Xn62357sbGGJLbykhd32ua5/t5AkN2sjBuWGkeiW23kKYctTukReYyyUhtv0n7eYyYMijE7JoOkJb7joilqtigX2t7en3YTSc= 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=RNSH9eQ+; arc=none smtp.client-ip=217.70.183.197 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 04A831C000B; Tue, 27 Feb 2024 11:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709033674; 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=JEy1WKZu79JY8RBIlDzPDmv8Cqag9mXrU8thTH54FTE=; b=RNSH9eQ+4yWnHnVtlpUJNgnp4s9B6XVqsh6exUAL1s6CqvR6ygkEsOH/dQOX/tE6eC/qFr LNMoKg7wTEhXQgA4XChpkYqs+LILCghDtZdR83mOjk0GJAyKs6FgHEotEEFASaW3bLUAmD aJgjIGeDSNCg8VI1xSF/d829mDK+ju2dP4dWYyNTVZZDI2NvMTxooFd4HzclQmz5NruFX6 /i1j+sL46YdFwwEp1uC8/ubaWfZIYGtNc4rsIE+Gp4L8tiBO0+N9dsE7OpgQOEybfKxPFS xn7hxpTDY5ob9FqApPkD8EIyUvSAbYM0pn9bDipErxQNZeUBLz5mybDXpbksiw== From: Herve Codina To: Bartosz Golaszewski , Kent Gibson , Linus Walleij Cc: Saravana Kannan , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v2 1/2] gpiolib: call gcdev_unregister() sooner in the removal operations Date: Tue, 27 Feb 2024 12:34:24 +0100 Message-ID: <20240227113426.253232-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227113426.253232-1-herve.codina@bootlin.com> References: <20240227113426.253232-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: 1792051831760963805 X-GMAIL-MSGID: 1792051831760963805 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 63e793a410e3..4ad3e260dec2 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1118,6 +1118,11 @@ void gpiochip_remove(struct gpio_chip *gc) /* Numb the device, cancelling all outstanding operations */ rcu_assign_pointer(gdev->chip, NULL); synchronize_srcu(&gdev->srcu); + /* + * 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_irqchip_remove(gc); acpi_gpiochip_remove(gc); of_gpiochip_remove(gc); @@ -1135,7 +1140,6 @@ void gpiochip_remove(struct gpio_chip *gc) * be removed, else it will be dangling until the last user is * gone. */ - gcdev_unregister(gdev); gpio_device_put(gdev); } EXPORT_SYMBOL_GPL(gpiochip_remove); From patchwork Tue Feb 27 11:34:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 207149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2635635dyb; Tue, 27 Feb 2024 03:36:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWyR/K0GmcaArYg5MonmK5MfKJm7o4FGd1klC/IfT43B/2rjci7arczXTqUwtedt4GXjai7ffoCoHLsepj1OGdPOml8/A== X-Google-Smtp-Source: AGHT+IG9RsE1zerE2gyOI0AO4j4AUzERPv5IdecR6YS8y0YiLDgk4DglmjOw4qES7VphWpXr2jVJ X-Received: by 2002:a1f:4e44:0:b0:4c0:1cc8:8821 with SMTP id c65-20020a1f4e44000000b004c01cc88821mr5985427vkb.9.1709033801724; Tue, 27 Feb 2024 03:36:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709033801; cv=pass; d=google.com; s=arc-20160816; b=DOK1RQGiOP17kC4PktzQXNtvUFR9nMFXBRz973L0ckfGTzJlOhtZLyVJ5NK143551C 2do2vGOQE/1D11vnW87K7GaqPafKdcpp3C9b4Ife4ZPRq6QeG2H+LpWo0dz2c/0TtR9E 1o0mo1m2AMrMCAM1rctJ4D6XXo+CRA7pFljNZQTP19x1949otEDwzdntXLPTzVOhgKug 0pfBGkFtFfWngEN28g47bR0bGMTIP2FKLA+fz+eEKJlcS2oaE46huyHklUyu7Nnm1z+d Mf3xyTUeasmDhEI6etR6sfpSjTJSJtVW6LbKAOUuQ3XyoUAMKXUSTwKN/RrGHDF6eIbK OxUA== 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=Q7WNC75978u3FnRvqua2g0x3X53QY3+13gx9/jOUJyE=; fh=ONUZ3m01L0DVQm+Cjotv2dXDuBgIcWiaHC6/g+ZSH6Y=; b=IRaPmNg+hXF/dNVnLfT7UcTT8+4aKdmhQhM343WAHuxqe9XWWajnSNyJ+akQng2+Wn uM+TBa4b3Z206K7Q4LQfLRTrYVN4c/YTcXibgSLlvWnGdD5jx85sZm7FS6OAy+zxSLyj DHrHkS1F1SvGgGdyuyQw/B6DRSxHwKQb61sr88haFixYwI84qJNdkV5tVLr8dDCvPpO9 /YQu5FcRpcJ2SwFUwR5TeEWjUU0SF5Yl96JP/ya98Zwhl0LV/DMI6K/y6+k7MgLrByMX H40L4YuWCER5O4dTAV2tt8mDiCQ+P7vhnRcV3/2KjFq+IPISFS28lSzOp0YUnvML1jNn KTOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MzHA2jzs; 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-83131-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83131-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m18-20020ac84452000000b0042c72478d20si7050877qtn.70.2024.02.27.03.36.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83131-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MzHA2jzs; 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-83131-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83131-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 04DF21C2338A for ; Tue, 27 Feb 2024 11:35:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A99313A893; Tue, 27 Feb 2024 11:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MzHA2jzs" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 744E0130ADF; Tue, 27 Feb 2024 11:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709033683; cv=none; b=NFeIgETMa2T3esTzYSq6yrgttcBiO0bINfbplsWly0G2IHVd/LsZch7Gr23/vgHv21x73cYmYHOn6nuMu88i9N4p8dQePS8YnsJJGmtdszgUWZGfNPVD5MrVTtTs4x1oAUfuOO0rahfcEvn2AfX2+jQvwt1aMMjqszNG6a+hDSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709033683; c=relaxed/simple; bh=Bg7CrCHk8qTVzw8D5kTnaxr6RqBt1zINI31UQ7JKYi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HyUViIAaolpYHxK7FlW9l6OLO/dtDt3q28HZ2bl0mqBakhQrhMrBkxw6u58yH9mJv9WswRW7aLXXj9cKUnCt6OVdH9gfeFoHZjW/88Nd9CT7WJzjSUpxhfLRHprtuwcTJL2WNyIihPRR/WHMWf4mI9tk5CXUSmV2fPtQV9Icj+s= 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=MzHA2jzs; arc=none smtp.client-ip=217.70.183.197 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 4176E1C0010; Tue, 27 Feb 2024 11:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709033678; 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=Q7WNC75978u3FnRvqua2g0x3X53QY3+13gx9/jOUJyE=; b=MzHA2jzsWuaKvAoMqzuVbPeM/fg/szQ9gQSyJdwcwimmuGWmR9iiA6pg8/A3bd7GP6HlqA FT7ofzCj8Dy9vRPQ2o2fKZjt4iYuuyEFn68ulBj9uvc/upMmhJwF7u7RT3phD9sYdFXHqI A0XuAvfXCVefPUH48olX2YcNxAHeo0FKbqE1iBh5fh9H5DUFwwvvlV317/p2+/zm32yb0i L/gg+5t2y9vvmGAMXW32BGDOAtuJdrSnBkcyvbchPbbOEfDObKItUXThnX8GAJGHUNOGtv R3HuO7IxIZ2U3cHrxGeoo0Y2euPdNvZJSrgf1sKnKkk6a6bsb804KhiIY/eJEg== From: Herve Codina To: Bartosz Golaszewski , Kent Gibson , Linus Walleij Cc: Saravana Kannan , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v2 2/2] gpiolib: cdev: release IRQs when the gpio chip device is removed Date: Tue, 27 Feb 2024 12:34:25 +0100 Message-ID: <20240227113426.253232-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227113426.253232-1-herve.codina@bootlin.com> References: <20240227113426.253232-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: 1792051827341703872 X-GMAIL-MSGID: 1792051827341703872 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 f384fa278764..96c05bd326d0 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -682,17 +682,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) { @@ -1183,6 +1172,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) { @@ -1892,6 +1898,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;