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

From: Robert Jarzmik
Date: Sat Aug 10 2019 - 15:27:55 EST


Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxx>
> Cc: Haojian Zhuang <haojian.zhuang@xxxxxxxxx>
> Cc: Robert Jarzmik <robert.jarzmik@xxxxxxx>
> Cc: Vinod Koul <vkoul@xxxxxxxxxx>
> Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: dmaengine@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> 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.

--
Robert