Skip to content

Commit

Permalink
ACPI: APEI: GHES: Convert to platform remove callback returning void
Browse files Browse the repository at this point in the history
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Instead of returning an error code, emit a better error message than the
core. Apart from the improved error message this patch has no effects
for the driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Uwe Kleine-König authored and Rafael J. Wysocki committed Feb 27, 2024
1 parent d206a76 commit f2f212f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/acpi/apei/ghes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ static int ghes_probe(struct platform_device *ghes_dev)
return rc;
}

static int ghes_remove(struct platform_device *ghes_dev)
static void ghes_remove(struct platform_device *ghes_dev)
{
int rc;
struct ghes *ghes;
Expand Down Expand Up @@ -1492,8 +1492,15 @@ static int ghes_remove(struct platform_device *ghes_dev)
break;
case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
rc = apei_sdei_unregister_ghes(ghes);
if (rc)
return rc;
if (rc) {
/*
* Returning early results in a resource leak, but we're
* only here if stopping the hardware failed.
*/
dev_err(&ghes_dev->dev, "Failed to unregister ghes (%pe)\n",
ERR_PTR(rc));
return;
}
break;
default:
BUG();
Expand All @@ -1507,16 +1514,14 @@ static int ghes_remove(struct platform_device *ghes_dev)
mutex_unlock(&ghes_devs_mutex);

kfree(ghes);

return 0;
}

static struct platform_driver ghes_platform_driver = {
.driver = {
.name = "GHES",
},
.probe = ghes_probe,
.remove = ghes_remove,
.remove_new = ghes_remove,
};

void __init acpi_ghes_init(void)
Expand Down

0 comments on commit f2f212f

Please sign in to comment.