diff mbox series

[4/6] dma: pxa_dma: no need to check return value of debugfs_create functions

Message ID 20190612122557.24158-4-gregkh@linuxfoundation.org (mailing list archive)
State Accepted
Headers show
Series [1/6] dma: amba-pl08x: no need to cast away call to debugfs_create_file() | expand

Commit Message

Greg KH June 12, 2019, 12:25 p.m. UTC
When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Also, because there is no need to save the file dentry, remove the
variable that was saving it as it was never even being used once set.

Cc: Daniel Mack <daniel@zonque.org>
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: dmaengine@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/dma/pxa_dma.c | 56 +++++++++----------------------------------
 1 file changed, 11 insertions(+), 45 deletions(-)

Comments

Robert Jarzmik Aug. 10, 2019, 7:27 p.m. UTC | #1
Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

Hi Greg,

> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
>
> Also, because there is no need to save the file dentry, remove the
> variable that was saving it as it was never even being used once set.
>
> Cc: Daniel Mack <daniel@zonque.org>
> Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
> Cc: Robert Jarzmik <robert.jarzmik@free.fr>
> Cc: Vinod Koul <vkoul@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: dmaengine@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/dma/pxa_dma.c | 56 +++++++++----------------------------------
>  1 file changed, 11 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/dma/pxa_dma.c b/drivers/dma/pxa_dma.c
> index b429642f3e7a..0f698f49ee26 100644
> --- a/drivers/dma/pxa_dma.c
> +++ b/drivers/dma/pxa_dma.c
> @@ -132,7 +132,6 @@ struct pxad_device {
>  	spinlock_t			phy_lock;	/* Phy association */
>  #ifdef CONFIG_DEBUG_FS
>  	struct dentry			*dbgfs_root;
> -	struct dentry			*dbgfs_state;
>  	struct dentry			**dbgfs_chan;
>  #endif
>  };
> @@ -326,31 +325,18 @@ static struct dentry *pxad_dbg_alloc_chan(struct pxad_device *pdev,
>  					     int ch, struct dentry *chandir)
>  {
>  	char chan_name[11];
> -	struct dentry *chan, *chan_state = NULL, *chan_descr = NULL;
> -	struct dentry *chan_reqs = NULL;
> +	struct dentry *chan;
>  	void *dt;
>  
>  	scnprintf(chan_name, sizeof(chan_name), "%d", ch);
>  	chan = debugfs_create_dir(chan_name, chandir);
>  	dt = (void *)&pdev->phys[ch];
>  
> -	if (chan)
> -		chan_state = debugfs_create_file("state", 0400, chan, dt,
> -						 &chan_state_fops);
> -	if (chan_state)
> -		chan_descr = debugfs_create_file("descriptors", 0400, chan, dt,
> -						 &descriptors_fops);
> -	if (chan_descr)
> -		chan_reqs = debugfs_create_file("requesters", 0400, chan, dt,
> -						&requester_chan_fops);
> -	if (!chan_reqs)
> -		goto err_state;
> +	debugfs_create_file("state", 0400, chan, dt, &chan_state_fops);
> +	debugfs_create_file("descriptors", 0400, chan, dt, &descriptors_fops);
> +	debugfs_create_file("requesters", 0400, chan, dt, &requester_chan_fops);

This is not strictly equivalent.
Imagine that the debugfs_create_dir() fails and returns NULL :
 - in the former case, neither "state", "descriptors" nor "requesters" would be
   created
 - in the new code, "state", "descriptors" nor "requesters" will be created in
   the debugfs root directory

Apart from that it looks fine.

Cheers.
Greg KH Aug. 11, 2019, 7:03 a.m. UTC | #2
On Sat, Aug 10, 2019 at 09:27:26PM +0200, Robert Jarzmik wrote:
> Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
> 
> Hi Greg,
> 
> > When calling debugfs functions, there is no need to ever check the
> > return value.  The function can work or not, but the code logic should
> > never do something different based on this.
> >
> > Also, because there is no need to save the file dentry, remove the
> > variable that was saving it as it was never even being used once set.
> >
> > Cc: Daniel Mack <daniel@zonque.org>
> > Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
> > Cc: Robert Jarzmik <robert.jarzmik@free.fr>
> > Cc: Vinod Koul <vkoul@kernel.org>
> > Cc: Dan Williams <dan.j.williams@intel.com>
> > Cc: linux-arm-kernel@lists.infradead.org
> > Cc: dmaengine@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >  drivers/dma/pxa_dma.c | 56 +++++++++----------------------------------
> >  1 file changed, 11 insertions(+), 45 deletions(-)
> >
> > diff --git a/drivers/dma/pxa_dma.c b/drivers/dma/pxa_dma.c
> > index b429642f3e7a..0f698f49ee26 100644
> > --- a/drivers/dma/pxa_dma.c
> > +++ b/drivers/dma/pxa_dma.c
> > @@ -132,7 +132,6 @@ struct pxad_device {
> >  	spinlock_t			phy_lock;	/* Phy association */
> >  #ifdef CONFIG_DEBUG_FS
> >  	struct dentry			*dbgfs_root;
> > -	struct dentry			*dbgfs_state;
> >  	struct dentry			**dbgfs_chan;
> >  #endif
> >  };
> > @@ -326,31 +325,18 @@ static struct dentry *pxad_dbg_alloc_chan(struct pxad_device *pdev,
> >  					     int ch, struct dentry *chandir)
> >  {
> >  	char chan_name[11];
> > -	struct dentry *chan, *chan_state = NULL, *chan_descr = NULL;
> > -	struct dentry *chan_reqs = NULL;
> > +	struct dentry *chan;
> >  	void *dt;
> >  
> >  	scnprintf(chan_name, sizeof(chan_name), "%d", ch);
> >  	chan = debugfs_create_dir(chan_name, chandir);
> >  	dt = (void *)&pdev->phys[ch];
> >  
> > -	if (chan)
> > -		chan_state = debugfs_create_file("state", 0400, chan, dt,
> > -						 &chan_state_fops);
> > -	if (chan_state)
> > -		chan_descr = debugfs_create_file("descriptors", 0400, chan, dt,
> > -						 &descriptors_fops);
> > -	if (chan_descr)
> > -		chan_reqs = debugfs_create_file("requesters", 0400, chan, dt,
> > -						&requester_chan_fops);
> > -	if (!chan_reqs)
> > -		goto err_state;
> > +	debugfs_create_file("state", 0400, chan, dt, &chan_state_fops);
> > +	debugfs_create_file("descriptors", 0400, chan, dt, &descriptors_fops);
> > +	debugfs_create_file("requesters", 0400, chan, dt, &requester_chan_fops);
> 
> This is not strictly equivalent.
> Imagine that the debugfs_create_dir() fails and returns NULL :

How can that happen?

>  - in the former case, neither "state", "descriptors" nor "requesters" would be
>    created
>  - in the new code, "state", "descriptors" nor "requesters" will be created in
>    the debugfs root directory

I agree, but debugfs_create_dir() does not return a NULL on an error
since many kernel releases.  Neither can debugfs_create_file() so really
this test is not working at all as-is :)

thanks,

greg k-h
Robert Jarzmik Aug. 13, 2019, 9:21 p.m. UTC | #3
Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

> On Sat, Aug 10, 2019 at 09:27:26PM +0200, Robert Jarzmik wrote:
>> Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
>> 
>> This is not strictly equivalent.
>> Imagine that the debugfs_create_dir() fails and returns NULL :
> How can that happen?
Well in v5.0-rc1 that could happen ... unfortunately that's also the code I
checked ...

>>  - in the former case, neither "state", "descriptors" nor "requesters" would be
>>    created
>>  - in the new code, "state", "descriptors" nor "requesters" will be created in
>>    the debugfs root directory
>
> I agree, but debugfs_create_dir() does not return a NULL on an error
> since many kernel releases.  Neither can debugfs_create_file() so really
> this test is not working at all as-is :)
Ah yes, you're right, I wasn't aware of the debugfs changes ...

But checking a bit further, your original mail is 2 monthes old, and this patch
was already merged in v5.2. I probably fell in a time-space anomaly, as I
received this mail only a couple of days ago.

Have a nice day.
diff mbox series

Patch

diff --git a/drivers/dma/pxa_dma.c b/drivers/dma/pxa_dma.c
index b429642f3e7a..0f698f49ee26 100644
--- a/drivers/dma/pxa_dma.c
+++ b/drivers/dma/pxa_dma.c
@@ -132,7 +132,6 @@  struct pxad_device {
 	spinlock_t			phy_lock;	/* Phy association */
 #ifdef CONFIG_DEBUG_FS
 	struct dentry			*dbgfs_root;
-	struct dentry			*dbgfs_state;
 	struct dentry			**dbgfs_chan;
 #endif
 };
@@ -326,31 +325,18 @@  static struct dentry *pxad_dbg_alloc_chan(struct pxad_device *pdev,
 					     int ch, struct dentry *chandir)
 {
 	char chan_name[11];
-	struct dentry *chan, *chan_state = NULL, *chan_descr = NULL;
-	struct dentry *chan_reqs = NULL;
+	struct dentry *chan;
 	void *dt;
 
 	scnprintf(chan_name, sizeof(chan_name), "%d", ch);
 	chan = debugfs_create_dir(chan_name, chandir);
 	dt = (void *)&pdev->phys[ch];
 
-	if (chan)
-		chan_state = debugfs_create_file("state", 0400, chan, dt,
-						 &chan_state_fops);
-	if (chan_state)
-		chan_descr = debugfs_create_file("descriptors", 0400, chan, dt,
-						 &descriptors_fops);
-	if (chan_descr)
-		chan_reqs = debugfs_create_file("requesters", 0400, chan, dt,
-						&requester_chan_fops);
-	if (!chan_reqs)
-		goto err_state;
+	debugfs_create_file("state", 0400, chan, dt, &chan_state_fops);
+	debugfs_create_file("descriptors", 0400, chan, dt, &descriptors_fops);
+	debugfs_create_file("requesters", 0400, chan, dt, &requester_chan_fops);
 
 	return chan;
-
-err_state:
-	debugfs_remove_recursive(chan);
-	return NULL;
 }
 
 static void pxad_init_debugfs(struct pxad_device *pdev)
@@ -358,40 +344,20 @@  static void pxad_init_debugfs(struct pxad_device *pdev)
 	int i;
 	struct dentry *chandir;
 
-	pdev->dbgfs_root = debugfs_create_dir(dev_name(pdev->slave.dev), NULL);
-	if (IS_ERR(pdev->dbgfs_root) || !pdev->dbgfs_root)
-		goto err_root;
-
-	pdev->dbgfs_state = debugfs_create_file("state", 0400, pdev->dbgfs_root,
-						pdev, &state_fops);
-	if (!pdev->dbgfs_state)
-		goto err_state;
-
 	pdev->dbgfs_chan =
-		kmalloc_array(pdev->nr_chans, sizeof(*pdev->dbgfs_state),
+		kmalloc_array(pdev->nr_chans, sizeof(struct dentry *),
 			      GFP_KERNEL);
 	if (!pdev->dbgfs_chan)
-		goto err_alloc;
+		return;
+
+	pdev->dbgfs_root = debugfs_create_dir(dev_name(pdev->slave.dev), NULL);
+
+	debugfs_create_file("state", 0400, pdev->dbgfs_root, pdev, &state_fops);
 
 	chandir = debugfs_create_dir("channels", pdev->dbgfs_root);
-	if (!chandir)
-		goto err_chandir;
 
-	for (i = 0; i < pdev->nr_chans; i++) {
+	for (i = 0; i < pdev->nr_chans; i++)
 		pdev->dbgfs_chan[i] = pxad_dbg_alloc_chan(pdev, i, chandir);
-		if (!pdev->dbgfs_chan[i])
-			goto err_chans;
-	}
-
-	return;
-err_chans:
-err_chandir:
-	kfree(pdev->dbgfs_chan);
-err_alloc:
-err_state:
-	debugfs_remove_recursive(pdev->dbgfs_root);
-err_root:
-	pr_err("pxad: debugfs is not available\n");
 }
 
 static void pxad_cleanup_debugfs(struct pxad_device *pdev)