public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] debugfs: fix debugfs_real_fops() build error
@ 2017-11-14 11:40 Arnd Bergmann
  2017-11-14 11:50 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2017-11-14 11:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, Nicolai Stange, linux-kernel

Some drivers use debugfs_real_fops() even when CONFIG_DEBUG_FS is disabled,
which now leads to a build error:

In file included from include/linux/list.h:9:0,
                 from include/linux/wait.h:7,
                 from include/linux/wait_bit.h:8,
                 from include/linux/fs.h:6,
                 from drivers/net/wireless/broadcom/b43legacy/debugfs.c:26:
drivers/net/wireless/broadcom/b43legacy/debugfs.c: In function 'b43legacy_debugfs_read':
drivers/net/wireless/broadcom/b43legacy/debugfs.c:224:23: error: implicit declaration of function 'debugfs_real_fops'; did you mean 'debugfs_create_bool'? [-Werror=implicit-function-declaration]

My first impulse was to add another 'static inline' dummy function
returning NULL for it, which would work fine. However, most callers
feed the pointer into container_of(), so it seems a little dangerous
here. Since all the callers are inside of a read/write file operation
that gets eliminated in this configuration, so having an 'extern'
declaration seems better here. If it ever gets used in a dangerous
way, that will now result in a link error.

Fixes: 7c8d469877b1 ("debugfs: add support for more elaborate ->d_fsdata")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/debugfs.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index f36ecc2a5712..3b0ba54cc4d5 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -216,6 +216,8 @@ static inline void debugfs_remove(struct dentry *dentry)
 static inline void debugfs_remove_recursive(struct dentry *dentry)
 { }
 
+const struct file_operations *debugfs_real_fops(const struct file *filp);
+
 static inline int debugfs_file_get(struct dentry *dentry)
 {
 	return 0;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] debugfs: fix debugfs_real_fops() build error
  2017-11-14 11:40 [PATCH] debugfs: fix debugfs_real_fops() build error Arnd Bergmann
@ 2017-11-14 11:50 ` Greg Kroah-Hartman
  2017-11-14 12:37   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2017-11-14 11:50 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Nicolai Stange, linux-kernel

On Tue, Nov 14, 2017 at 12:40:31PM +0100, Arnd Bergmann wrote:
> Some drivers use debugfs_real_fops() even when CONFIG_DEBUG_FS is disabled,
> which now leads to a build error:
> 
> In file included from include/linux/list.h:9:0,
>                  from include/linux/wait.h:7,
>                  from include/linux/wait_bit.h:8,
>                  from include/linux/fs.h:6,
>                  from drivers/net/wireless/broadcom/b43legacy/debugfs.c:26:
> drivers/net/wireless/broadcom/b43legacy/debugfs.c: In function 'b43legacy_debugfs_read':
> drivers/net/wireless/broadcom/b43legacy/debugfs.c:224:23: error: implicit declaration of function 'debugfs_real_fops'; did you mean 'debugfs_create_bool'? [-Werror=implicit-function-declaration]
> 
> My first impulse was to add another 'static inline' dummy function
> returning NULL for it, which would work fine. However, most callers
> feed the pointer into container_of(), so it seems a little dangerous
> here. Since all the callers are inside of a read/write file operation
> that gets eliminated in this configuration, so having an 'extern'
> declaration seems better here. If it ever gets used in a dangerous
> way, that will now result in a link error.

Ok, but does your patch really "fix" anything?  The linker should now
complain, not the compiler, for these types of configurations?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] debugfs: fix debugfs_real_fops() build error
  2017-11-14 11:50 ` Greg Kroah-Hartman
@ 2017-11-14 12:37   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2017-11-14 12:37 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Nicolai Stange, Linux Kernel Mailing List

On Tue, Nov 14, 2017 at 12:50 PM, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Tue, Nov 14, 2017 at 12:40:31PM +0100, Arnd Bergmann wrote:
>> Some drivers use debugfs_real_fops() even when CONFIG_DEBUG_FS is disabled,
>> which now leads to a build error:
>>
>> In file included from include/linux/list.h:9:0,
>>                  from include/linux/wait.h:7,
>>                  from include/linux/wait_bit.h:8,
>>                  from include/linux/fs.h:6,
>>                  from drivers/net/wireless/broadcom/b43legacy/debugfs.c:26:
>> drivers/net/wireless/broadcom/b43legacy/debugfs.c: In function 'b43legacy_debugfs_read':
>> drivers/net/wireless/broadcom/b43legacy/debugfs.c:224:23: error: implicit declaration of function 'debugfs_real_fops'; did you mean 'debugfs_create_bool'? [-Werror=implicit-function-declaration]
>>
>> My first impulse was to add another 'static inline' dummy function
>> returning NULL for it, which would work fine. However, most callers
>> feed the pointer into container_of(), so it seems a little dangerous
>> here. Since all the callers are inside of a read/write file operation
>> that gets eliminated in this configuration, so having an 'extern'
>> declaration seems better here. If it ever gets used in a dangerous
>> way, that will now result in a link error.
>
> Ok, but does your patch really "fix" anything?  The linker should now
> complain, not the compiler, for these types of configurations?

As I said, all calls to debugfs_real_fops() are from a read/write
file operation, which gets discarded when CONFIG_DEBUG_FS
is disabled, because debugfs_create_file() and similar functions
don't use the file_operations structure pointing to them.

There is no link error, unless someone uses debugfs_real_fops()
in a function that does not get discarded. If we ever get a
function calling debugfs_real_fops() when DEBUG_FS is
turned off and we call that function from somewhere else,
we definitely want to get the link error over dereferencing
container_of(NULL, type, member).

         Arnd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-14 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-14 11:40 [PATCH] debugfs: fix debugfs_real_fops() build error Arnd Bergmann
2017-11-14 11:50 ` Greg Kroah-Hartman
2017-11-14 12:37   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox