All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Bjorn Andersson <andersson@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-remoteproc@vger.kernel.org, kernel@pengutronix.de
Subject: remove callback of ti_k3_dsp remoteproc driver
Date: Mon, 9 Oct 2023 22:48:25 +0200	[thread overview]
Message-ID: <20231009204825.6n2t366oad7gke2l@pengutronix.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 4336 bytes --]

Hello,

k3_dsp_rproc_remove() in drivers/remoteproc/ti_k3_dsp_remoteproc.c looks
as follows:

static int k3_dsp_rproc_remove(struct platform_device *pdev)
{
        struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev);
        struct rproc *rproc = kproc->rproc;
        struct device *dev = &pdev->dev;
        int ret;

        if (rproc->state == RPROC_ATTACHED) {
                ret = rproc_detach(rproc);
                if (ret) {
                        dev_err(dev, "failed to detach proc, ret = %d\n", ret);
                        return ret;
                }
        }

        rproc_del(kproc->rproc);

        ret = ti_sci_proc_release(kproc->tsp);
        if (ret)
                dev_err(dev, "failed to release proc, ret = %d\n", ret);

        kfree(kproc->tsp);

        ret = ti_sci_put_handle(kproc->ti_sci);
        if (ret)
                dev_err(dev, "failed to put ti_sci handle, ret = %d\n", ret);

        k3_dsp_reserved_mem_exit(kproc);
        rproc_free(kproc->rproc);

        return 0;
}

The error return in the first if block is dangerous: If rproc_detach()
fails, rproc_del() is skipped and so the rproc structure is kept in
rproc_list, with the pointers in rproc->ops leading into nirvana if the
ti_k3_dsp_remoteproc module is unloaded.

I don't know enough about rproc to directly see the right fix for that
issue. Maybe it's just to drop "return ret;", but I guess that's not
safe either?! As I don't have a suggestion to fix this, there is no
patch included here in this bug report :-\

Another minor issue here is: return 0 instead of return ret in the error
path would be an improvement. Returning a non-zero value in a remove
callback is useless. The only effect is that the core will emit

	dev_warn(_dev, "remove callback returned a non-zero value. This will be ignored.\n");

(see platform_remove()) and then it will continue to remove the device.

I want to change the prototype of remove callbacks to

	void (*)(struct platform_device *)

to prevent this type of bug. To progress here I'd like to propose:

--->8---
Convert to platform remove callback returning void

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 (mostly) ignored
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.

The non-zero return value of the first exit point of
k3_dsp_rproc_remove() is ignored by the core, so the only semantical
change here is that an additional warning by the core is suppressed if
rproc_detach() fails. This is even an improvement because
k3_dsp_rproc_remove() already emitted a more useful message.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index ef8415a7cd54..8207439e4927 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -825,7 +825,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int k3_dsp_rproc_remove(struct platform_device *pdev)
+static void k3_dsp_rproc_remove(struct platform_device *pdev)
 {
 	struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev);
 	struct rproc *rproc = kproc->rproc;
@@ -836,7 +836,7 @@ static int k3_dsp_rproc_remove(struct platform_device *pdev)
 		ret = rproc_detach(rproc);
 		if (ret) {
 			dev_err(dev, "failed to detach proc, ret = %d\n", ret);
-			return ret;
+			return;
 		}
 	}
 
@@ -854,8 +854,6 @@ static int k3_dsp_rproc_remove(struct platform_device *pdev)
 
 	k3_dsp_reserved_mem_exit(kproc);
 	rproc_free(kproc->rproc);
-
-	return 0;
 }
 
 static const struct k3_dsp_mem_data c66_mems[] = {
--->8---

But if you want to address the graver bug first, I can wait to prevent
patch conflicts.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

                 reply	other threads:[~2023-10-09 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231009204825.6n2t366oad7gke2l@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=andersson@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.