linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno  <angelogioacchino.delregno@collabora.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Mark Brown" <broonie@kernel.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>
Cc: linux-spi@vger.kernel.org, kernel@pengutronix.de,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH 1/3] spi: mt65xx: Properly handle failures in .remove()
Date: Thu, 9 Mar 2023 12:00:35 +0100	[thread overview]
Message-ID: <8d845834-db8f-be0e-93a4-30f27617dd0c@collabora.com> (raw)
In-Reply-To: <20230309094704.2568531-2-u.kleine-koenig@pengutronix.de>

Il 09/03/23 10:47, Uwe Kleine-König ha scritto:
> Returning an error code in a platform driver's remove function is wrong
> most of the time and there is an effort to make the callback return
> void. To prepare this rework the function not to exit early.
> 
> There wasn't a real problem because if pm runtime resume failed the only
> step missing was pm_runtime_disable() which isn't an issue.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>   drivers/spi/spi-mt65xx.c | 21 +++++++++++++--------
>   1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
> index 9eab6c20dbc5..b1cf7bbb2c08 100644
> --- a/drivers/spi/spi-mt65xx.c
> +++ b/drivers/spi/spi-mt65xx.c
> @@ -1275,15 +1275,20 @@ static int mtk_spi_remove(struct platform_device *pdev)
>   	struct mtk_spi *mdata = spi_master_get_devdata(master);
>   	int ret;
>   
> -	ret = pm_runtime_resume_and_get(&pdev->dev);
> -	if (ret < 0)
> -		return ret;
> -
> -	mtk_spi_reset(mdata);
> +	ret = pm_runtime_get_sync(&pdev->dev);

> +	/*
> +	 * If pm runtime resume failed, clks are disabled and unprepared. So
> +	 * don't access the hardware and skip clk unpreparing.
> +	 */

This comment is counter-intuitive: you're saying in words "if this failed" but
in code "if this didn't fail".

Please, either invert the branch so that it looks either like

/* if negative */
if (negative) warn
else /* positive */

or like

if (ret >= 0) {
	do_things()
} else {
	/* if it failed ... */
	warn
}

Functionally, though, looks good to me.

Cheers,
Angelo


  reply	other threads:[~2023-03-09 11:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09  9:47 [PATCH 0/3] spi: mt65xx: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-09  9:47 ` [PATCH 1/3] spi: mt65xx: Properly handle failures in .remove() Uwe Kleine-König
2023-03-09 11:00   ` AngeloGioacchino Del Regno [this message]
2023-03-09  9:47 ` [PATCH 2/3] spi: mt65xx: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-09 11:01   ` AngeloGioacchino Del Regno
2023-03-09  9:47 ` [PATCH 3/3] spi: mt65xx: Don't disguise a "return 0" as "return ret" Uwe Kleine-König
2023-03-09 11:01   ` AngeloGioacchino Del Regno
2023-05-30 17:40 ` [PATCH 0/3] spi: mt65xx: Convert to platform remove callback returning void Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d845834-db8f-be0e-93a4-30f27617dd0c@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).