From patchwork Mon Jun 20 12:29:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 583481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B7F1C43334 for ; Mon, 20 Jun 2022 12:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240227AbiFTM3o (ORCPT ); Mon, 20 Jun 2022 08:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240064AbiFTM3n (ORCPT ); Mon, 20 Jun 2022 08:29:43 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 816111E4 for ; Mon, 20 Jun 2022 05:29:42 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o3GXE-0006zq-FP; Mon, 20 Jun 2022 14:29:40 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1o3GXC-001dd8-4C; Mon, 20 Jun 2022 14:29:39 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1o3GXC-00HaSi-Rz; Mon, 20 Jun 2022 14:29:38 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] gpio: grgpio: Fix device removing Date: Mon, 20 Jun 2022 14:29:33 +0200 Message-Id: <20220620122933.106035-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1694; h=from:subject; bh=YkQmf+LecKEaaLfapNFDMKh7Yb2jAhw7abjjjZFnFnQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBisGgpYK3paFDRxNQc9CApwgWjmUPyxqeu3cfCFpKV 37ttIUKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYrBoKQAKCRDB/BR4rcrsCey2B/ 9J4bOoSEbZCOf6aVfSljOYW3pHT3E6yMdy8k1E2NQ3ETIcajzGoMf4edDjvZDh7uw+lgpJTy3f5HBH gu4A/UTn0klUsPBCywd87u6QPxwqQurDui1IMd3M767kMwWMNUtiVPU7iet9xMLo/ONcMctIKTAED7 TcoSeQ2foSDha+cuOoMLhv4/jzTm0iSndLPlFvYNtHIoEQN0GZ6iyjrn9OqX50NdqlYhBv/CAs2aus LIL8zCL7iiKKMWUdUPFZKXlXGWKX0O0EuucXVZAjzyXPG2Tsg18XyS8hLh/Azi2zIx72q4Jh0n5nHA GPdipgtTYOceR6+sHNriSrv69P1rLP X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-gpio@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org If a platform device's remove callback returns non-zero, the device core emits a warning and still removes the device and calls the devm cleanup callbacks. So it's not save to not unregister the gpiochip because on the next request to a gpio the driver accesses kfree()'d memory. Also if an irq triggers, the freed memory is accessed. Instead rely on the gpio framework to ensure that after gpiochip_remove() all gpios are freed and so the corresponding irqs unmapped. (I'm think the gpio framework doesn't guarantee that, but that's a bug there and out of scope for this gpio driver to fix that.) This is a preparation for making platform remove callbacks return void. Signed-off-by: Uwe Kleine-König --- drivers/gpio/gpio-grgpio.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56 diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c index df563616f943..bea0e32c195d 100644 --- a/drivers/gpio/gpio-grgpio.c +++ b/drivers/gpio/gpio-grgpio.c @@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev) static int grgpio_remove(struct platform_device *ofdev) { struct grgpio_priv *priv = platform_get_drvdata(ofdev); - int i; - int ret = 0; - - if (priv->domain) { - for (i = 0; i < GRGPIO_MAX_NGPIO; i++) { - if (priv->uirqs[i].refcnt != 0) { - ret = -EBUSY; - goto out; - } - } - } gpiochip_remove(&priv->gc); if (priv->domain) irq_domain_remove(priv->domain); -out: - return ret; + return 0; } static const struct of_device_id grgpio_match[] = {