[PATCH V2 2/3] soc: ti: knav_dma: Make knav_dma_open_channel return NULL on error

Nishanth Menon posted 3 patches 2 months, 2 weeks ago
[PATCH V2 2/3] soc: ti: knav_dma: Make knav_dma_open_channel return NULL on error
Posted by Nishanth Menon 2 months, 2 weeks ago
Make knav_dma_open_channel consistently return NULL on error instead of
ERR_PTR. Currently the header include/linux/soc/ti/knav_dma.h returns NUL
when the driver is disabled, but the driver implementation returns
ERR_PTR(-EINVAL), creating API inconsistency for users.

Standardize the error handling by making the function return NULL on all
error conditions.

Suggested-by: Simon Horman <horms@kernel.org>
Signed-off-by: Nishanth Menon <nm@ti.com>
---
Changes in V2:
* renewed version

 drivers/soc/ti/knav_dma.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
index a25ebe6cd503..e69f0946de29 100644
--- a/drivers/soc/ti/knav_dma.c
+++ b/drivers/soc/ti/knav_dma.c
@@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
  * @name:	slave channel name
  * @config:	dma configuration parameters
  *
- * Returns pointer to appropriate DMA channel on success or error.
+ * Returns pointer to appropriate DMA channel on success or NULL on error.
  */
 void *knav_dma_open_channel(struct device *dev, const char *name,
 					struct knav_dma_cfg *config)
@@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
 
 	if (!kdev) {
 		pr_err("keystone-navigator-dma driver not registered\n");
-		return (void *)-EINVAL;
+		return NULL;
 	}
 
 	chan_num = of_channel_match_helper(dev->of_node, name, &instance);
 	if (chan_num < 0) {
 		dev_err(kdev->dev, "No DMA instance with name %s\n", name);
-		return (void *)-EINVAL;
+		return NULL;
 	}
 
 	dev_dbg(kdev->dev, "initializing %s channel %d from DMA %s\n",
@@ -431,7 +431,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
 	if (config->direction != DMA_MEM_TO_DEV &&
 	    config->direction != DMA_DEV_TO_MEM) {
 		dev_err(kdev->dev, "bad direction\n");
-		return (void *)-EINVAL;
+		return NULL;
 	}
 
 	/* Look for correct dma instance */
@@ -443,7 +443,7 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
 	}
 	if (!dma) {
 		dev_err(kdev->dev, "No DMA instance with name %s\n", instance);
-		return (void *)-EINVAL;
+		return NULL;
 	}
 
 	/* Look for correct dma channel from dma instance */
@@ -463,14 +463,14 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
 	if (!chan) {
 		dev_err(kdev->dev, "channel %d is not in DMA %s\n",
 				chan_num, instance);
-		return (void *)-EINVAL;
+		return NULL;
 	}
 
 	if (atomic_read(&chan->ref_count) >= 1) {
 		if (!check_config(chan, config)) {
 			dev_err(kdev->dev, "channel %d config miss-match\n",
 				chan_num);
-			return (void *)-EINVAL;
+			return NULL;
 		}
 	}
 
-- 
2.47.0
Re: [PATCH V2 2/3] soc: ti: knav_dma: Make knav_dma_open_channel return NULL on error
Posted by Jacob Keller 2 months, 2 weeks ago

On 9/30/2025 5:16 AM, Nishanth Menon wrote:
> Make knav_dma_open_channel consistently return NULL on error instead of
> ERR_PTR. Currently the header include/linux/soc/ti/knav_dma.h returns NUL
> when the driver is disabled, but the driver implementation returns
> ERR_PTR(-EINVAL), creating API inconsistency for users.
> 

I would word this as indicating that we don't even use ERR_PTR here at all!

> Standardize the error handling by making the function return NULL on all
> error conditions.
> 
> Suggested-by: Simon Horman <horms@kernel.org>
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
> Changes in V2:
> * renewed version
> 
>  drivers/soc/ti/knav_dma.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> index a25ebe6cd503..e69f0946de29 100644
> --- a/drivers/soc/ti/knav_dma.c
> +++ b/drivers/soc/ti/knav_dma.c
> @@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
>   * @name:	slave channel name
>   * @config:	dma configuration parameters
>   *
> - * Returns pointer to appropriate DMA channel on success or error.
> + * Returns pointer to appropriate DMA channel on success or NULL on error.
>   */
>  void *knav_dma_open_channel(struct device *dev, const char *name,
>  					struct knav_dma_cfg *config)
> @@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
>  
>  	if (!kdev) {
>  		pr_err("keystone-navigator-dma driver not registered\n");
> -		return (void *)-EINVAL;
> +		return NULL;

Wow. The driver doesn't even return ERR_PTR, but just directly casts
-EINVAL to a void *... thats quite ugly. Good to remove this.

Re: [PATCH V2 2/3] soc: ti: knav_dma: Make knav_dma_open_channel return NULL on error
Posted by Nishanth Menon 2 months, 2 weeks ago
On 16:59-20250930, Jacob Keller wrote:
> 
> 
> On 9/30/2025 5:16 AM, Nishanth Menon wrote:
> > Make knav_dma_open_channel consistently return NULL on error instead of
> > ERR_PTR. Currently the header include/linux/soc/ti/knav_dma.h returns NUL
> > when the driver is disabled, but the driver implementation returns
> > ERR_PTR(-EINVAL), creating API inconsistency for users.
> > 
> 
> I would word this as indicating that we don't even use ERR_PTR here at all!

Thanks. Yep, will do for the next respin.

> 
> > Standardize the error handling by making the function return NULL on all
> > error conditions.
> > 
> > Suggested-by: Simon Horman <horms@kernel.org>
> > Signed-off-by: Nishanth Menon <nm@ti.com>
> > ---
> > Changes in V2:
> > * renewed version
> > 
> >  drivers/soc/ti/knav_dma.c | 14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
> > index a25ebe6cd503..e69f0946de29 100644
> > --- a/drivers/soc/ti/knav_dma.c
> > +++ b/drivers/soc/ti/knav_dma.c
> > @@ -402,7 +402,7 @@ static int of_channel_match_helper(struct device_node *np, const char *name,
> >   * @name:	slave channel name
> >   * @config:	dma configuration parameters
> >   *
> > - * Returns pointer to appropriate DMA channel on success or error.
> > + * Returns pointer to appropriate DMA channel on success or NULL on error.
> >   */
> >  void *knav_dma_open_channel(struct device *dev, const char *name,
> >  					struct knav_dma_cfg *config)
> > @@ -414,13 +414,13 @@ void *knav_dma_open_channel(struct device *dev, const char *name,
> >  
> >  	if (!kdev) {
> >  		pr_err("keystone-navigator-dma driver not registered\n");
> > -		return (void *)-EINVAL;
> > +		return NULL;
> 
> Wow. The driver doesn't even return ERR_PTR, but just directly casts
> -EINVAL to a void *... thats quite ugly. Good to remove this.
> 




-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource