The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Andrew Davis <afd@ti.com>
Cc: Bjorn Andersson <andersson@kernel.org>,
	Hari Nagalla <hnagalla@ti.com>, Beleswar Padhi <b-padhi@ti.com>,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] remoteproc: da8xx: Use devm action to release reserved memory
Date: Tue, 26 Aug 2025 12:48:26 -0600	[thread overview]
Message-ID: <aK4BepPvXW6u7Eui@p14s> (raw)
In-Reply-To: <d54e1cb6-388d-4e0e-a3a0-387ed87082ce@ti.com>

On Mon, Aug 25, 2025 at 01:29:26PM -0500, Andrew Davis wrote:
> On 8/25/25 12:04 PM, Mathieu Poirier wrote:
> > On Thu, Aug 14, 2025 at 08:55:31AM -0500, Andrew Davis wrote:
> > > This helps prevent mistakes like freeing out of order in cleanup functions
> > > and forgetting to free on error paths.
> > > 
> > > Signed-off-by: Andrew Davis <afd@ti.com>
> > > ---
> > >   drivers/remoteproc/da8xx_remoteproc.c | 30 +++++++++++++--------------
> > >   1 file changed, 14 insertions(+), 16 deletions(-)
> > > 
> > > diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
> > > index 47df21bea5254..58b4f05283d92 100644
> > > --- a/drivers/remoteproc/da8xx_remoteproc.c
> > > +++ b/drivers/remoteproc/da8xx_remoteproc.c
> > > @@ -233,6 +233,13 @@ static int da8xx_rproc_get_internal_memories(struct platform_device *pdev,
> > >   	return 0;
> > >   }
> > > +static void da8xx_rproc_mem_release(void *data)
> > > +{
> > > +	struct device *dev = data;
> > > +
> > 
> > The check for dev->of_node from "free_mem" is missing.  I can add it if you
> > agree.
> > 
> 
> It should not be needed, this devm_action callback is added inside a if(dev->of_node)
> block below, so this will only be called iff dev->of_node is not null.

I agree with your assessment.  This set has been applied, along with the other
two with similar aim.  

> 
> Andrew
> 
> > > +	of_reserved_mem_device_release(dev);
> > > +}
> > > +
> > >   static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   {
> > >   	struct device *dev = &pdev->dev;
> > > @@ -274,14 +281,13 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   		ret = of_reserved_mem_device_init(dev);
> > >   		if (ret)
> > >   			return dev_err_probe(dev, ret, "device does not have specific CMA pool\n");
> > > +		devm_add_action_or_reset(&pdev->dev, da8xx_rproc_mem_release, &pdev->dev);
> > >   	}
> > >   	rproc = devm_rproc_alloc(dev, "dsp", &da8xx_rproc_ops, da8xx_fw_name,
> > >   				 sizeof(*drproc));
> > > -	if (!rproc) {
> > > -		ret = -ENOMEM;
> > > -		goto free_mem;
> > > -	}
> > > +	if (!rproc)
> > > +		return -ENOMEM;
> > >   	/* error recovery is not supported at present */
> > >   	rproc->recovery_disabled = true;
> > > @@ -294,7 +300,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   	ret = da8xx_rproc_get_internal_memories(pdev, drproc);
> > >   	if (ret)
> > > -		goto free_mem;
> > > +		return ret;
> > >   	platform_set_drvdata(pdev, rproc);
> > > @@ -304,7 +310,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   					rproc);
> > >   	if (ret) {
> > >   		dev_err(dev, "devm_request_threaded_irq error: %d\n", ret);
> > > -		goto free_mem;
> > > +		return ret;
> > >   	}
> > >   	/*
> > > @@ -314,7 +320,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   	 */
> > >   	ret = reset_control_assert(dsp_reset);
> > >   	if (ret)
> > > -		goto free_mem;
> > > +		return ret;
> > >   	drproc->chipsig = chipsig;
> > >   	drproc->bootreg = bootreg;
> > > @@ -325,22 +331,16 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
> > >   	ret = rproc_add(rproc);
> > >   	if (ret) {
> > >   		dev_err(dev, "rproc_add failed: %d\n", ret);
> > > -		goto free_mem;
> > > +		return ret;
> > >   	}
> > >   	return 0;
> > > -
> > > -free_mem:
> > > -	if (dev->of_node)
> > > -		of_reserved_mem_device_release(dev);
> > > -	return ret;
> > >   }
> > >   static void da8xx_rproc_remove(struct platform_device *pdev)
> > >   {
> > >   	struct rproc *rproc = platform_get_drvdata(pdev);
> > >   	struct da8xx_rproc *drproc = rproc->priv;
> > > -	struct device *dev = &pdev->dev;
> > >   	/*
> > >   	 * The devm subsystem might end up releasing things before
> > > @@ -350,8 +350,6 @@ static void da8xx_rproc_remove(struct platform_device *pdev)
> > >   	disable_irq(drproc->irq);
> > >   	rproc_del(rproc);
> > > -	if (dev->of_node)
> > > -		of_reserved_mem_device_release(dev);
> > >   }
> > >   static const struct of_device_id davinci_rproc_of_match[] __maybe_unused = {
> > > -- 
> > > 2.39.2
> > > 
> 

  reply	other threads:[~2025-08-26 18:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14 13:55 [PATCH 1/3] remoteproc: da8xx: Use devm_rproc_alloc() helper Andrew Davis
2025-08-14 13:55 ` [PATCH 2/3] remoteproc: da8xx: Use devm action to release reserved memory Andrew Davis
2025-08-25 17:04   ` Mathieu Poirier
2025-08-25 18:29     ` Andrew Davis
2025-08-26 18:48       ` Mathieu Poirier [this message]
2025-08-14 13:55 ` [PATCH 3/3] remoteproc: da8xx: Use devm_rproc_add() helper Andrew Davis
2025-08-25 17:01 ` [PATCH 1/3] remoteproc: da8xx: Use devm_rproc_alloc() helper Mathieu Poirier

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=aK4BepPvXW6u7Eui@p14s \
    --to=mathieu.poirier@linaro.org \
    --cc=afd@ti.com \
    --cc=andersson@kernel.org \
    --cc=b-padhi@ti.com \
    --cc=hnagalla@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox