linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: fsl-mc: allocate resources when there is no scan in progress
@ 2020-05-21 16:12 Ioana Ciornei
  2020-05-25 16:13 ` Ioana Ciornei
  0 siblings, 1 reply; 2+ messages in thread
From: Ioana Ciornei @ 2020-05-21 16:12 UTC (permalink / raw)
  To: gregkh, laurentiu.tudor; +Cc: linux-kernel, Ioana Ciornei

Allocate resources from the fsl-mc bus only when a scan of the bus is
not happening. This is useful when functional devices on the bus, such
as DPNI, DPSW etc, request some kind of allocatable object but the scan
of the bus is still in progress, thus those resources are not yet
available. Catch this early and notify the upper layer driver of the
condition.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index cc7bb900f524..794ddc9589dc 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -184,6 +184,9 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
 	BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) !=
 		     FSL_MC_NUM_POOL_TYPES);
 
+	if (!mutex_trylock(&mc_bus->scan_mutex))
+		return -ENXIO;
+
 	*new_resource = NULL;
 	if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
 		goto out;
@@ -197,7 +200,7 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
 					    struct fsl_mc_resource, node);
 
 	if (!resource) {
-		error = -ENXIO;
+		error = -ENOMEM;
 		dev_err(&mc_bus_dev->dev,
 			"No more resources of type %s left\n",
 			fsl_mc_pool_type_strings[pool_type]);
@@ -220,6 +223,7 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
 	mutex_unlock(&res_pool->mutex);
 	*new_resource = resource;
 out:
+	mutex_unlock(&mc_bus->scan_mutex);
 	return error;
 }
 EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] bus: fsl-mc: allocate resources when there is no scan in progress
  2020-05-21 16:12 [PATCH] bus: fsl-mc: allocate resources when there is no scan in progress Ioana Ciornei
@ 2020-05-25 16:13 ` Ioana Ciornei
  0 siblings, 0 replies; 2+ messages in thread
From: Ioana Ciornei @ 2020-05-25 16:13 UTC (permalink / raw)
  To: gregkh, Laurentiu Tudor; +Cc: linux-kernel

> Subject: [PATCH] bus: fsl-mc: allocate resources when there is no scan in
> progress
> 
> Allocate resources from the fsl-mc bus only when a scan of the bus is not
> happening. This is useful when functional devices on the bus, such as DPNI,
> DPSW etc, request some kind of allocatable object but the scan of the bus is still
> in progress, thus those resources are not yet available. Catch this early and
> notify the upper layer driver of the condition.
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---

Please don't apply this.
I just discovered a corner case in which this approach does not work.

Sorry for the bother,
Ioana

>  drivers/bus/fsl-mc/fsl-mc-allocator.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-
> allocator.c
> index cc7bb900f524..794ddc9589dc 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> @@ -184,6 +184,9 @@ int __must_check fsl_mc_resource_allocate(struct
> fsl_mc_bus *mc_bus,
>  	BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) !=
>  		     FSL_MC_NUM_POOL_TYPES);
> 
> +	if (!mutex_trylock(&mc_bus->scan_mutex))
> +		return -ENXIO;
> +
>  	*new_resource = NULL;
>  	if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES)
>  		goto out;
> @@ -197,7 +200,7 @@ int __must_check fsl_mc_resource_allocate(struct
> fsl_mc_bus *mc_bus,
>  					    struct fsl_mc_resource, node);
> 
>  	if (!resource) {
> -		error = -ENXIO;
> +		error = -ENOMEM;
>  		dev_err(&mc_bus_dev->dev,
>  			"No more resources of type %s left\n",
>  			fsl_mc_pool_type_strings[pool_type]);
> @@ -220,6 +223,7 @@ int __must_check fsl_mc_resource_allocate(struct
> fsl_mc_bus *mc_bus,
>  	mutex_unlock(&res_pool->mutex);
>  	*new_resource = resource;
>  out:
> +	mutex_unlock(&mc_bus->scan_mutex);
>  	return error;
>  }
>  EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate);
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-25 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21 16:12 [PATCH] bus: fsl-mc: allocate resources when there is no scan in progress Ioana Ciornei
2020-05-25 16:13 ` Ioana Ciornei

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).