Message ID | 20221209150914.3557650-1-u.kleine-koenig@pengutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;sophiezhao968@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <ukl@pengutronix.de>) 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 <ukl@pengutronix.de>) 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 <ukl@pengutronix.de>) id 1p3f1W-003nXP-7L; Fri, 09 Dec 2022 16:10:50 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org>, 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 Content-Type: text/plain; charset=UTF-8 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 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
platform: Provide a remove callback that returns no value
|
|
Commit Message
Uwe Kleine-König
Dec. 9, 2022, 3:09 p.m. UTC
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 <u.kleine-koenig@pengutronix.de>
---
drivers/base/platform.c | 4 +++-
include/linux/platform_device.h | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
Comments
On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > 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; Change c) seems like it will be just as much work as a), right? > 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 <u.kleine-koenig@pengutronix.de> > --- > 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 *); > + Who is going to do the work of the conversion to this new prototype? I'll be glad to take this, but I don't want to see a half-finished conversion happen and us stuck with a "new" and "old" call, as that would just be a mess. thanks, greg k-h
Hello Greg, On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > 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; > > Change c) seems like it will be just as much work as a), right? Yeah, but c) should be trivially doable per subsystem using coccinelle. So my plan is to do a) per subsystem with one patch per driver and c) with one patch per subsystem. > Who is going to do the work of the conversion to this new prototype? > I'll be glad to take this, but I don't want to see a half-finished > conversion happen and us stuck with a "new" and "old" call, as that > would just be a mess. The idea is that this becomes my new pet project once https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org is complete. :-) I intend to work on that once the patch under discussion is included in an -rc1. Best regards Uwe
On Fri, Dec 09, 2022 at 04:52:07PM +0100, Uwe Kleine-König wrote: > Hello Greg, > > On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > > 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; > > > > Change c) seems like it will be just as much work as a), right? > > Yeah, but c) should be trivially doable per subsystem using coccinelle. > So my plan is to do a) per subsystem with one patch per driver and c) > with one patch per subsystem. > > > Who is going to do the work of the conversion to this new prototype? > > I'll be glad to take this, but I don't want to see a half-finished > > conversion happen and us stuck with a "new" and "old" call, as that > > would just be a mess. > > The idea is that this becomes my new pet project once > https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org > is complete. :-) > > I intend to work on that once the patch under discussion is included in > an -rc1. Ok, I'll wait to queue this up to my tree until after 6.2-rc1 is out, thanks. greg k-h
Hello Greg, On Fri, Dec 09, 2022 at 05:15:42PM +0100, Greg Kroah-Hartman wrote: > On Fri, Dec 09, 2022 at 04:52:07PM +0100, Uwe Kleine-König wrote: > > On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > > > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > > > 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; > > > > > > Change c) seems like it will be just as much work as a), right? > > > > Yeah, but c) should be trivially doable per subsystem using coccinelle. > > So my plan is to do a) per subsystem with one patch per driver and c) > > with one patch per subsystem. > > > > > Who is going to do the work of the conversion to this new prototype? > > > I'll be glad to take this, but I don't want to see a half-finished > > > conversion happen and us stuck with a "new" and "old" call, as that > > > would just be a mess. > > > > The idea is that this becomes my new pet project once > > https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org > > is complete. :-) > > > > I intend to work on that once the patch under discussion is included in > > an -rc1. > > Ok, I'll wait to queue this up to my tree until after 6.2-rc1 is out, > thanks. We're at v6.2-rc3 now. Is this patch still in your queue and you didn't come around yet to apply it, or did it fell through the cracks? Best regards Uwe
On Thu, Jan 12, 2023 at 09:20:29AM +0100, Uwe Kleine-König wrote: > Hello Greg, > > On Fri, Dec 09, 2022 at 05:15:42PM +0100, Greg Kroah-Hartman wrote: > > On Fri, Dec 09, 2022 at 04:52:07PM +0100, Uwe Kleine-König wrote: > > > On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > > > > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > > > > 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; > > > > > > > > Change c) seems like it will be just as much work as a), right? > > > > > > Yeah, but c) should be trivially doable per subsystem using coccinelle. > > > So my plan is to do a) per subsystem with one patch per driver and c) > > > with one patch per subsystem. > > > > > > > Who is going to do the work of the conversion to this new prototype? > > > > I'll be glad to take this, but I don't want to see a half-finished > > > > conversion happen and us stuck with a "new" and "old" call, as that > > > > would just be a mess. > > > > > > The idea is that this becomes my new pet project once > > > https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org > > > is complete. :-) > > > > > > I intend to work on that once the patch under discussion is included in > > > an -rc1. > > > > Ok, I'll wait to queue this up to my tree until after 6.2-rc1 is out, > > thanks. > > We're at v6.2-rc3 now. Is this patch still in your queue and you didn't > come around yet to apply it, or did it fell through the cracks? My queue is huge right now. I'll work on this "soon". Do you want this on a tag that others can pull into their trees, or just in my normal driver-core-next branch? Either is fine for me. thanks, greg k-h
On Fri, Jan 13, 2023 at 12:43:39PM +0100, Greg Kroah-Hartman wrote: > On Thu, Jan 12, 2023 at 09:20:29AM +0100, Uwe Kleine-König wrote: > > Hello Greg, > > > > On Fri, Dec 09, 2022 at 05:15:42PM +0100, Greg Kroah-Hartman wrote: > > > On Fri, Dec 09, 2022 at 04:52:07PM +0100, Uwe Kleine-König wrote: > > > > On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > > > > > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > > > > > 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; > > > > > > > > > > Change c) seems like it will be just as much work as a), right? > > > > > > > > Yeah, but c) should be trivially doable per subsystem using coccinelle. > > > > So my plan is to do a) per subsystem with one patch per driver and c) > > > > with one patch per subsystem. > > > > > > > > > Who is going to do the work of the conversion to this new prototype? > > > > > I'll be glad to take this, but I don't want to see a half-finished > > > > > conversion happen and us stuck with a "new" and "old" call, as that > > > > > would just be a mess. > > > > > > > > The idea is that this becomes my new pet project once > > > > https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org > > > > is complete. :-) > > > > > > > > I intend to work on that once the patch under discussion is included in > > > > an -rc1. > > > > > > Ok, I'll wait to queue this up to my tree until after 6.2-rc1 is out, > > > thanks. > > > > We're at v6.2-rc3 now. Is this patch still in your queue and you didn't > > come around yet to apply it, or did it fell through the cracks? > > My queue is huge right now. > > I'll work on this "soon". Do you want this on a tag that others can > pull into their trees, or just in my normal driver-core-next branch? > Either is fine for me. In my experience maintainers stumble when patches depend on patches that are not in -rc1. So I will be patient until this hits an -rc1. Thanks for the offer. Best regards Uwe
On Fri, Jan 13, 2023 at 06:40:04PM +0100, Uwe Kleine-König wrote: > On Fri, Jan 13, 2023 at 12:43:39PM +0100, Greg Kroah-Hartman wrote: > > On Thu, Jan 12, 2023 at 09:20:29AM +0100, Uwe Kleine-König wrote: > > > Hello Greg, > > > > > > On Fri, Dec 09, 2022 at 05:15:42PM +0100, Greg Kroah-Hartman wrote: > > > > On Fri, Dec 09, 2022 at 04:52:07PM +0100, Uwe Kleine-König wrote: > > > > > On Fri, Dec 09, 2022 at 04:21:30PM +0100, Greg Kroah-Hartman wrote: > > > > > > On Fri, Dec 09, 2022 at 04:09:14PM +0100, Uwe Kleine-König wrote: > > > > > > > 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; > > > > > > > > > > > > Change c) seems like it will be just as much work as a), right? > > > > > > > > > > Yeah, but c) should be trivially doable per subsystem using coccinelle. > > > > > So my plan is to do a) per subsystem with one patch per driver and c) > > > > > with one patch per subsystem. > > > > > > > > > > > Who is going to do the work of the conversion to this new prototype? > > > > > > I'll be glad to take this, but I don't want to see a half-finished > > > > > > conversion happen and us stuck with a "new" and "old" call, as that > > > > > > would just be a mess. > > > > > > > > > > The idea is that this becomes my new pet project once > > > > > https://lore.kernel.org/lkml/20221118224540.619276-1-uwe@kleine-koenig.org > > > > > is complete. :-) > > > > > > > > > > I intend to work on that once the patch under discussion is included in > > > > > an -rc1. > > > > > > > > Ok, I'll wait to queue this up to my tree until after 6.2-rc1 is out, > > > > thanks. > > > > > > We're at v6.2-rc3 now. Is this patch still in your queue and you didn't > > > come around yet to apply it, or did it fell through the cracks? > > > > My queue is huge right now. > > > > I'll work on this "soon". Do you want this on a tag that others can > > pull into their trees, or just in my normal driver-core-next branch? > > Either is fine for me. > > In my experience maintainers stumble when patches depend on patches that > are not in -rc1. So I will be patient until this hits an -rc1. Thanks > for the offer. Fair enough, now added to my tree, sorry for the delay. Feel free to start flooding me with these types of changes, I'll be glad to take them through my tree if at all possible. greg k-h
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 *);