[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAC_iWj+5MskeWaqa242zFsGRrgAxMGuVPHL6kYm1DUtH_jkDTg@mail.gmail.com>
Date: Sat, 18 Nov 2023 09:21:23 +0200
From: Ilias Apalodimas <ilias.apalodimas@...aro.org>
To: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
Cc: Siddharth Vadapalli <s-vadapalli@...com>, Ravi Gunasekaran <r-gunasekaran@...com>,
Roger Quadros <rogerq@...nel.org>, Alexei Starovoitov <ast@...nel.org>, Marek Majtyka <alardam@...il.com>,
Gerhard Engleder <gerhard@...leder-embedded.com>, Rob Herring <robh@...nel.org>,
Yunsheng Lin <linyunsheng@...wei.com>, linux-omap@...r.kernel.org, netdev@...r.kernel.org,
kernel@...gutronix.de
Subject: Re: [PATCH 3/7] net: ethernet: ti: cpsw-new: Don't error out in .remove()
On Fri, 17 Nov 2023 at 11:17, Uwe Kleine-König
<u.kleine-koenig@...gutronix.de> wrote:
>
> Returning early from .remove() with an error code still results in the
> driver unbinding the device. So the driver core ignores the returned error
> code and the resources that were not freed are never catched up. In
> combination with devm this also often results in use-after-free bugs.
>
> If runtime resume fails, it's still important to free all resources, so
> don't return with an error code, but emit an error message and continue
> freeing acquired stuff.
>
> This prepares changing cpsw_remove() to return void.
>
> Fixes: ed3525eda4c4 ("net: ethernet: ti: introduce cpsw switchdev based driver part 1 - dual-emac")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
> ---
> drivers/net/ethernet/ti/cpsw_new.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c
> index 0e4f526b1753..a6ce409f563c 100644
> --- a/drivers/net/ethernet/ti/cpsw_new.c
> +++ b/drivers/net/ethernet/ti/cpsw_new.c
> @@ -2042,16 +2042,24 @@ static int cpsw_remove(struct platform_device *pdev)
> struct cpsw_common *cpsw = platform_get_drvdata(pdev);
> int ret;
>
> - ret = pm_runtime_resume_and_get(&pdev->dev);
> + ret = pm_runtime_get_sync(&pdev->dev);
> if (ret < 0)
> - return ret;
> + /* There is no need to do something about that. The important
> + * thing is to not exit early, but do all cleanup that doesn't
> + * requrie register access.
> + */
> + dev_err(&pdev->dev, "runtime resume failed (%pe)\n",
> + ERR_PTR(ret));
>
> cpsw_unregister_notifiers(cpsw);
> cpsw_unregister_devlink(cpsw);
> cpsw_unregister_ports(cpsw);
>
> - cpts_release(cpsw->cpts);
> - cpdma_ctlr_destroy(cpsw->dma);
> + if (ret >= 0) {
> + cpts_release(cpsw->cpts);
> + cpdma_ctlr_destroy(cpsw->dma);
> + }
> +
> cpsw_remove_dt(cpsw);
> pm_runtime_put_sync(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
> --
> 2.42.0
>
Acked-by: Ilias Apalodimas <ilias.apalodimas@...aro.org>
Powered by blists - more mailing lists