Skip to content

Commit 0edb555

Browse files
author
Uwe Kleine-König
committed
platform: Make platform_driver::remove() return void
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. To prevent such wrong assumptions, change the return type of the remove callback to void. This was prepared by introducing an alternative remove callback returning void and converting all drivers to that. So .remove() can be changed without further changes in drivers. This corresponds to step b) of the plan outlined in commit 5c5a768 ("platform: Provide a remove callback that returns no value"). Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 45e7d78 commit 0edb555

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

drivers/base/platform.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -1420,14 +1420,8 @@ static void platform_remove(struct device *_dev)
14201420
struct platform_driver *drv = to_platform_driver(_dev->driver);
14211421
struct platform_device *dev = to_platform_device(_dev);
14221422

1423-
if (drv->remove_new) {
1424-
drv->remove_new(dev);
1425-
} else if (drv->remove) {
1426-
int ret = drv->remove(dev);
1427-
1428-
if (ret)
1429-
dev_warn(_dev, "remove callback returned a non-zero value. This will be ignored.\n");
1430-
}
1423+
if (drv->remove)
1424+
drv->remove(dev);
14311425
dev_pm_domain_detach(_dev, true);
14321426
}
14331427

include/linux/platform_device.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,14 @@ struct platform_driver {
237237
int (*probe)(struct platform_device *);
238238

239239
/*
240-
* Traditionally the remove callback returned an int which however is
241-
* ignored by the driver core. This led to wrong expectations by driver
242-
* authors who thought returning an error code was a valid error
243-
* handling strategy. To convert to a callback returning void, new
244-
* drivers should implement .remove_new() until the conversion it done
245-
* that eventually makes .remove() return void.
240+
* .remove_new() is a relic from a prototype conversion of .remove().
241+
* New drivers are supposed to implement .remove(). Once all drivers are
242+
* converted to not use .remove_new any more, it will be dropped.
246243
*/
247-
int (*remove)(struct platform_device *);
248-
void (*remove_new)(struct platform_device *);
244+
union {
245+
void (*remove)(struct platform_device *);
246+
void (*remove_new)(struct platform_device *);
247+
};
249248

250249
void (*shutdown)(struct platform_device *);
251250
int (*suspend)(struct platform_device *, pm_message_t state);

0 commit comments

Comments
 (0)