Message ID | 20240821112131.6004-1-11162571@vivo.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v1] drivers:bus:Fix the NULL vs IS_ERR() bug for debugfs_create_dir() | expand |
On Wed, Aug 21, 2024 at 07:21:30AM -0400, Yang Ruibin wrote: > The debugfs_create_dir() function returns error pointers. > It never returns NULL. So use IS_ERR() to check it. > > Signed-off-by: Yang Ruibin <11162571@vivo.com> > --- > drivers/bus/mvebu-mbus.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c > index 3c99d72087eb..42621838ba75 100644 > --- a/drivers/bus/mvebu-mbus.c > +++ b/drivers/bus/mvebu-mbus.c > @@ -995,13 +995,13 @@ static __init int mvebu_mbus_debugfs_init(void) > s->debugfs_root = debugfs_create_dir("mvebu-mbus", NULL); > if(IS_ERR(s->debugfs_root)) > return PTR_ERR(s->debugfs_root); > + You are not supposed to check error codes from debugfs, since it is optional. The code should just keep going, independent of failure or success. > s->debugfs_sdram = debugfs_create_file("sdram", S_IRUGO, > s->debugfs_root, NULL, > &mvebu_sdram_debug_fops); > s->debugfs_devs = debugfs_create_file("devices", S_IRUGO, > s->debugfs_root, NULL, > &mvebu_devs_debug_fops); > - } I'm surprised this code compiles without this close braces! Andrew
diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c index 3c99d72087eb..42621838ba75 100644 --- a/drivers/bus/mvebu-mbus.c +++ b/drivers/bus/mvebu-mbus.c @@ -995,13 +995,13 @@ static __init int mvebu_mbus_debugfs_init(void) s->debugfs_root = debugfs_create_dir("mvebu-mbus", NULL); if(IS_ERR(s->debugfs_root)) return PTR_ERR(s->debugfs_root); + s->debugfs_sdram = debugfs_create_file("sdram", S_IRUGO, s->debugfs_root, NULL, &mvebu_sdram_debug_fops); s->debugfs_devs = debugfs_create_file("devices", S_IRUGO, s->debugfs_root, NULL, &mvebu_devs_debug_fops); - } return 0; }
The debugfs_create_dir() function returns error pointers. It never returns NULL. So use IS_ERR() to check it. Signed-off-by: Yang Ruibin <11162571@vivo.com> --- drivers/bus/mvebu-mbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)