All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dinh Nguyen <dinguyen@kernel.org>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linus.walleij@linaro.org,
	p.zabel@pengutronix.de, thor.thayer@linux.intel.com
Subject: Re: [PATCHv3] ARM: drivers/amba: release and cleanup the resource to allow for deferred probe
Date: Wed, 2 Oct 2019 15:45:42 -0500	[thread overview]
Message-ID: <2083d164-c998-6990-9e51-86d331a36a07@kernel.org> (raw)
In-Reply-To: <20191002173209.GT25745@shell.armlinux.org.uk>



On 10/2/19 12:32 PM, Russell King - ARM Linux admin wrote:
> On Wed, Oct 02, 2019 at 09:35:51AM -0500, Dinh Nguyen wrote:
>> With commit "79bdcb202a35 ARM: 8906/1: drivers/amba: add reset control to
>> amba bus probe", the amba bus driver needs to be deferred probe because the
>> reset driver is probed later. However with a deferred probe, the call to
>> request_resource() in the driver returns -EBUSY. The reason is the driver
>> has not released the resource from the previous probe attempt.
>>
>> This patch fixes how we handle the condition of EPROBE_DEFER that is returned
>> from getting the reset controls. For this condition, the patch will jump
>> to defer_probe, which will iounmap, dev_pm_domain_detach, and release the
>> resource.
>>
>> Fixes: 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control to
>> amba bus probe")
>> Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
>> ---
>> v3: jump to defer_probe where the driver will unmap and pm_detach the
>>     driver resource for the next probe attempt
>> v2: release the resource when of_reset_control_array_get_optional_shared()
>>     returns EPROBE_DEFER
>> ---
>>  drivers/amba/bus.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index f39f075abff9..4a021b1dab3d 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -409,9 +409,12 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>>  		 */
>>  		rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node);
>>  		if (IS_ERR(rstc)) {
>> -			if (PTR_ERR(rstc) != -EPROBE_DEFER)
>> +			ret = PTR_ERR(rstc);
>> +			if (ret == -EPROBE_DEFER)
>> +				goto defer_probe;
>> +			else
>>  				dev_err(&dev->dev, "Can't get amba reset!\n");
>> -			return PTR_ERR(rstc);
>> +			return ret;
> 
> So, if of_reset_control_array_get_optional_shared() returns an error,
> we end up leaking the ioremap(), the resource claim, the pclk enable
> and pm domain?  If it returns -EPROBE_DEFER, we end up leaking the
> pclk enable?
> 
> I think this is going to be quicker if I write the patch - I haven't
> build-tested this yet though.  Please check whether this works for
> you.
> 
> Thanks.
> 
> 8<=====
> From: Russell King <rmk+kernel@armlinux.org.uk>
> Subject: [PATCH] drivers/amba: fix reset control error handling
> 
> With commit 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control
> to amba bus probe") it is possible for the the amba bus driver to defer
> probing the device for its IDs because the reset driver may be probed
> later.
> 
> However when a subsequent probe occurs, the call to request_resource()
> in the driver returns -EBUSY as the driver has not released the resource
> from the initial probe attempt - or cleaned up any of the preceding
> actions.
> 
> Fix this both for the deferred probe case as well as a failure to get
> the reset.
> 
> Fixes: 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control to amba bus probe")
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> ---
>  drivers/amba/bus.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index f39f075abff9..fe1523664816 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -409,9 +409,11 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>  		 */
>  		rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node);
>  		if (IS_ERR(rstc)) {
> -			if (PTR_ERR(rstc) != -EPROBE_DEFER)
> -				dev_err(&dev->dev, "Can't get amba reset!\n");
> -			return PTR_ERR(rstc);
> +			ret = PTR_ERR(rstc);
> +			if (ret != -EPROBE_DEFER)
> +				dev_err(&dev->dev, "can't get reset: %d\n",
> +					ret);
> +			goto err_reset;
>  		}
>  		reset_control_deassert(rstc);
>  		reset_control_put(rstc);
> @@ -472,6 +474,12 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>  	release_resource(&dev->res);
>   err_out:
>  	return ret;
> +
> + err_reset:
> +	amba_put_disable_pclk(dev);
> +	iounmap(tmp);
> +	dev_pm_domain_detach(&dev->dev, true);
> +	goto err_release;
>  }
>  
>  /*
> 

Tested-by: Dinh Nguyen <dinguyen@kernel.org>

Thanks,
Dinh

WARNING: multiple messages have this Message-ID (diff)
From: Dinh Nguyen <dinguyen@kernel.org>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: p.zabel@pengutronix.de, linus.walleij@linaro.org,
	thor.thayer@linux.intel.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCHv3] ARM: drivers/amba: release and cleanup the resource to allow for deferred probe
Date: Wed, 2 Oct 2019 15:45:42 -0500	[thread overview]
Message-ID: <2083d164-c998-6990-9e51-86d331a36a07@kernel.org> (raw)
In-Reply-To: <20191002173209.GT25745@shell.armlinux.org.uk>



On 10/2/19 12:32 PM, Russell King - ARM Linux admin wrote:
> On Wed, Oct 02, 2019 at 09:35:51AM -0500, Dinh Nguyen wrote:
>> With commit "79bdcb202a35 ARM: 8906/1: drivers/amba: add reset control to
>> amba bus probe", the amba bus driver needs to be deferred probe because the
>> reset driver is probed later. However with a deferred probe, the call to
>> request_resource() in the driver returns -EBUSY. The reason is the driver
>> has not released the resource from the previous probe attempt.
>>
>> This patch fixes how we handle the condition of EPROBE_DEFER that is returned
>> from getting the reset controls. For this condition, the patch will jump
>> to defer_probe, which will iounmap, dev_pm_domain_detach, and release the
>> resource.
>>
>> Fixes: 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control to
>> amba bus probe")
>> Signed-off-by: Dinh Nguyen <dinguyen@kernel.org>
>> ---
>> v3: jump to defer_probe where the driver will unmap and pm_detach the
>>     driver resource for the next probe attempt
>> v2: release the resource when of_reset_control_array_get_optional_shared()
>>     returns EPROBE_DEFER
>> ---
>>  drivers/amba/bus.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index f39f075abff9..4a021b1dab3d 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -409,9 +409,12 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>>  		 */
>>  		rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node);
>>  		if (IS_ERR(rstc)) {
>> -			if (PTR_ERR(rstc) != -EPROBE_DEFER)
>> +			ret = PTR_ERR(rstc);
>> +			if (ret == -EPROBE_DEFER)
>> +				goto defer_probe;
>> +			else
>>  				dev_err(&dev->dev, "Can't get amba reset!\n");
>> -			return PTR_ERR(rstc);
>> +			return ret;
> 
> So, if of_reset_control_array_get_optional_shared() returns an error,
> we end up leaking the ioremap(), the resource claim, the pclk enable
> and pm domain?  If it returns -EPROBE_DEFER, we end up leaking the
> pclk enable?
> 
> I think this is going to be quicker if I write the patch - I haven't
> build-tested this yet though.  Please check whether this works for
> you.
> 
> Thanks.
> 
> 8<=====
> From: Russell King <rmk+kernel@armlinux.org.uk>
> Subject: [PATCH] drivers/amba: fix reset control error handling
> 
> With commit 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control
> to amba bus probe") it is possible for the the amba bus driver to defer
> probing the device for its IDs because the reset driver may be probed
> later.
> 
> However when a subsequent probe occurs, the call to request_resource()
> in the driver returns -EBUSY as the driver has not released the resource
> from the initial probe attempt - or cleaned up any of the preceding
> actions.
> 
> Fix this both for the deferred probe case as well as a failure to get
> the reset.
> 
> Fixes: 79bdcb202a35 ("ARM: 8906/1: drivers/amba: add reset control to amba bus probe")
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> ---
>  drivers/amba/bus.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index f39f075abff9..fe1523664816 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -409,9 +409,11 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>  		 */
>  		rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node);
>  		if (IS_ERR(rstc)) {
> -			if (PTR_ERR(rstc) != -EPROBE_DEFER)
> -				dev_err(&dev->dev, "Can't get amba reset!\n");
> -			return PTR_ERR(rstc);
> +			ret = PTR_ERR(rstc);
> +			if (ret != -EPROBE_DEFER)
> +				dev_err(&dev->dev, "can't get reset: %d\n",
> +					ret);
> +			goto err_reset;
>  		}
>  		reset_control_deassert(rstc);
>  		reset_control_put(rstc);
> @@ -472,6 +474,12 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>  	release_resource(&dev->res);
>   err_out:
>  	return ret;
> +
> + err_reset:
> +	amba_put_disable_pclk(dev);
> +	iounmap(tmp);
> +	dev_pm_domain_detach(&dev->dev, true);
> +	goto err_release;
>  }
>  
>  /*
> 

Tested-by: Dinh Nguyen <dinguyen@kernel.org>

Thanks,
Dinh

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-10-02 20:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02 14:35 [PATCHv3] ARM: drivers/amba: release and cleanup the resource to allow for deferred probe Dinh Nguyen
2019-10-02 14:35 ` Dinh Nguyen
2019-10-02 17:32 ` Russell King - ARM Linux admin
2019-10-02 17:32   ` Russell King - ARM Linux admin
2019-10-02 20:45   ` Dinh Nguyen [this message]
2019-10-02 20:45     ` Dinh Nguyen
2019-10-02 20:45   ` Dinh Nguyen
2019-10-02 20:45     ` Dinh Nguyen

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=2083d164-c998-6990-9e51-86d331a36a07@kernel.org \
    --to=dinguyen@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=p.zabel@pengutronix.de \
    --cc=thor.thayer@linux.intel.com \
    /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.