Hi,
debugfs_create_dir() returns NULL if an error occurs, returns -ENODEV
when debugfs is not enabled in the kernel.
Signed-off-by: Zhao Lei <[email protected]>
---
sound/soc/soc-dapm.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index efbd0b3..7351db9 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -831,7 +831,7 @@ int snd_soc_dapm_sys_add(struct device *dev)
return ret;
asoc_debugfs = debugfs_create_dir("asoc", NULL);
- if (!IS_ERR(asoc_debugfs))
+ if (!IS_ERR(asoc_debugfs) && asoc_debugfs)
debugfs_create_u32("dapm_pop_time", 0744, asoc_debugfs,
&pop_time);
else
--
1.5.5.3
On Fri, Oct 17, 2008 at 09:04:55PM +0800, Zhaolei wrote:
> debugfs_create_dir() returns NULL if an error occurs, returns -ENODEV
> when debugfs is not enabled in the kernel.
...
> asoc_debugfs = debugfs_create_dir("asoc", NULL);
> - if (!IS_ERR(asoc_debugfs))
> + if (!IS_ERR(asoc_debugfs) && asoc_debugfs)
> debugfs_create_u32("dapm_pop_time", 0744, asoc_debugfs,
> &pop_time);
Hrmpf. This looks like something that should be fixed in debugfs -
using both error reporting strategies is rather unhelpful and we're
actually loosing information in the case where debugfs is built. I'll
send a patch and see what people thing.
Still in the meantime,
Acked-by: Mark Brown <[email protected]>
At Fri, 17 Oct 2008 14:23:42 +0100,
Mark Brown wrote:
>
> On Fri, Oct 17, 2008 at 09:04:55PM +0800, Zhaolei wrote:
>
> > debugfs_create_dir() returns NULL if an error occurs, returns -ENODEV
> > when debugfs is not enabled in the kernel.
>
> ...
>
> > asoc_debugfs = debugfs_create_dir("asoc", NULL);
> > - if (!IS_ERR(asoc_debugfs))
> > + if (!IS_ERR(asoc_debugfs) && asoc_debugfs)
> > debugfs_create_u32("dapm_pop_time", 0744, asoc_debugfs,
> > &pop_time);
>
> Hrmpf. This looks like something that should be fixed in debugfs -
> using both error reporting strategies is rather unhelpful and we're
> actually loosing information in the case where debugfs is built. I'll
> send a patch and see what people thing.
This looks like a design. In linux/debugfs.h:
/*
* We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
* so users have a chance to detect if there was a real error or not. We don't
* want to duplicate the design decision mistakes of procfs and devfs again.
*/
Though, I agree that the detailed error information is lost by
returning NULL...
Takashi
At Fri, 17 Oct 2008 17:21:21 +0200,
I wrote:
>
> At Fri, 17 Oct 2008 14:23:42 +0100,
> Mark Brown wrote:
> >
> > On Fri, Oct 17, 2008 at 09:04:55PM +0800, Zhaolei wrote:
> >
> > > debugfs_create_dir() returns NULL if an error occurs, returns -ENODEV
> > > when debugfs is not enabled in the kernel.
> >
> > ...
> >
> > > asoc_debugfs = debugfs_create_dir("asoc", NULL);
> > > - if (!IS_ERR(asoc_debugfs))
> > > + if (!IS_ERR(asoc_debugfs) && asoc_debugfs)
> > > debugfs_create_u32("dapm_pop_time", 0744, asoc_debugfs,
> > > &pop_time);
> >
> > Hrmpf. This looks like something that should be fixed in debugfs -
> > using both error reporting strategies is rather unhelpful and we're
> > actually loosing information in the case where debugfs is built. I'll
> > send a patch and see what people thing.
>
> This looks like a design. In linux/debugfs.h:
Oh, and I applied the patch now to sound git tree, BTW.
Thanks!
Takashi
On Fri, Oct 17, 2008 at 05:21:21PM +0200, Takashi Iwai wrote:
> This looks like a design. In linux/debugfs.h:
Yeah, so my grovelling through the code after I wrote that e-mail
showed.
> /*
> * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
> * so users have a chance to detect if there was a real error or not. We don't
> * want to duplicate the design decision mistakes of procfs and devfs again.
> */
> Though, I agree that the detailed error information is lost by
> returning NULL...
Yes, not to mention the fact that using both error reporting interfaces
makes writing client code more error prone. Looking at the users most
seem to only check one kind of error code is returned.
For ASoC checking only for null would actually be good enough - even if
-ENODEV is returned we only ever pass the pointers into other debugfs
functions so the fact that the pointer is bogus makes no odds, it'll
never actually be dereferenced.