From patchwork Fri Dec 9 15:09:14 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: 31820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp836626wrr; Fri, 9 Dec 2022 07:20:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4eDPd4Egw69p8R1a5zU0KDpbzQlPPzn7bLLRex7s8utwatrgJ0+otDhGEuLodVdq+H6vNb X-Received: by 2002:a17:907:76d4:b0:7c0:e5c8:d439 with SMTP id kf20-20020a17090776d400b007c0e5c8d439mr5493817ejc.3.1670599232302; Fri, 09 Dec 2022 07:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670599232; cv=none; d=google.com; s=arc-20160816; b=td7K+8dyqWdKK7Epj11EKS3d/bb0l7sGZBCFv+dN1HM4BF0rKM06BOqLRAE/tqsRLV XqFbyow/HpPeQ2zgRWkcDcQKQV/gncEOOyf1yCsPbetXTxUiREbJPCuyGHOCVt7yupnW i/PxLfInLCBx9Pbb+ZBl9AB6Evzp8FKudo+AuwAJXoCoBTUh+e+De+YX2HlHwjNlwDuA 5duJcnU/QWNmr4xyVK3sSa8XkBA5FE7Pl2X9N1POYwtDdlb1w1qiv9EE/Rbi8JE6bZkg s4fhRHRAwLCKqmnA1xTkWGuXXCibhXPkcThXSvcOKtfjxa2E7eFRW/8tvvF/Z3HZorZu EkRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ubFa/W2uwckh61sxo59p5AqQPdfB+68P5A21BfsZ9c0=; b=G+x1R5sGldVVqGWjRuSBg4iyuak3+C+IOdCV7gMhlyBOj1JgIAV08v0jkiOfBI7tFe 75Vnh2FuMNw+7c/t13iwr5lDrOK8EcbfGNwS+JYK1mvZg+0eO8QJSBBss3cPRqRXbjO0 QwxgUQlyTanSHcZLzRKA7LZDrVh0k4ULeYae1mzDKLepGpaiGzcgCbdnQ+n67BqDnBvD BqIfmrVZcqDD532TGoefOUpyMta/QIMUMZSOb8WmCTG3rq6T6+cm0wREOQ84MwpbSwGp 2RWqBu64pOMyxRVjkvZnhFzvReq1KB5QF2JHyHXvLZTye7nJ4u3RXf1hmyDL/uUSq/Kw ln0A== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt11-20020a170907728b00b007c098bddb61si32904ejc.448.2022.12.09.07.20.07; Fri, 09 Dec 2022 07:20:32 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbiLIPLg (ORCPT + 99 others); Fri, 9 Dec 2022 10:11:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbiLIPLQ (ORCPT ); Fri, 9 Dec 2022 10:11:16 -0500 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 56D9284276 for ; Fri, 9 Dec 2022 07:10:54 -0800 (PST) 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 1p3f1X-0006eE-So; Fri, 09 Dec 2022 16:10:51 +0100 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 1p3f1W-003OFO-7C; Fri, 09 Dec 2022 16:10:51 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1p3f1W-003nXP-7L; Fri, 09 Dec 2022 16:10:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] platform: Provide a remove callback that returns no value Date: Fri, 9 Dec 2022 16:09:14 +0100 Message-Id: <20221209150914.3557650-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2873; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=k+rvkADnYOwKQ7El/a33BqcdznBVWIc0DqXYegQmmWQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBjk0+Wuq2PYktrKBTsM3nQ4g88CeTllkY0xtJ4Qh1F cFRkvKKJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCY5NPlgAKCRDB/BR4rcrsCdy/B/ wMUoS3LhfBI5ozyRul0EPX3aOo2vkd4pRgK96PHcGndZPOqusehQRJs5CjwBuGdpKTv/yce600tfyH uJOnCSzyuE3OzkEsy2KML2nxkMDePh1AO5sQIvuHRsyqNcpfjdi68CKSlCQho1ebj5ROufZpOt/lV4 YSkMknTlPmpXqhlXAnLfykezXL4V7zGQZDJxVjZqdZ4VEgZB3FuSsFL4MmTGsxMUAqzsQWOZOZBOuT MG3LOxIwN4P/Khl2Auv1oDCRkQ9oIJmcBpQ2JUXM5fx6YO2z+Xi6YaUy1CU2f2IlaE3kXa2J4hQ/TU /GcElRdg5Ilxq9WcvcXsGOjDtfw/kQ 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-kernel@vger.kernel.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS 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?1751750260355118244?= X-GMAIL-MSGID: =?utf-8?q?1751750260355118244?= struct platform_driver::remove returning an integer made driver authors expect that returning an error code was proper error handling. However the driver core ignores the error and continues to remove the device because there is nothing the core could do anyhow and reentering the remove callback again is only calling for trouble. So this is an source for errors typically yielding resource leaks in the error path. As there are too many platform drivers to neatly convert them all to return void in a single go, do it in several steps after this patch: a) Convert all drivers to implement .remove_new() returning void instead of .remove() returning int; b) Change struct platform_driver::remove() to return void and so make it identical to .remove_new(); c) Change all drivers back to .remove() now with the better prototype; d) drop struct platform_driver::remove_new(). While this touches all drivers eventually twice, steps a) and c) can be done one driver after another and so reduces coordination efforts immensely and simplifies review. Signed-off-by: Uwe Kleine-König --- drivers/base/platform.c | 4 +++- include/linux/platform_device.h | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 968f3d71eeab..a4938d1c8fe1 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1416,7 +1416,9 @@ static void platform_remove(struct device *_dev) struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); - if (drv->remove) { + if (drv->remove_new) { + drv->remove_new(dev); + } else if (drv->remove) { int ret = drv->remove(dev); if (ret) diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index b0d5a253156e..b845fd83f429 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -207,7 +207,18 @@ extern void platform_device_put(struct platform_device *pdev); struct platform_driver { int (*probe)(struct platform_device *); + + /* + * Traditionally the remove callback returned an int which however is + * ignored by the driver core. This led to wrong expectations by driver + * authors who thought returning an error code was a valid error + * handling strategy. To convert to a callback returning void, new + * drivers should implement .remove_new() until the conversion it done + * that eventually makes .remove() return void. + */ int (*remove)(struct platform_device *); + void (*remove_new)(struct platform_device *); + void (*shutdown)(struct platform_device *); int (*suspend)(struct platform_device *, pm_message_t state); int (*resume)(struct platform_device *);