2023-03-28 12:31:18

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] fs: quota: avoid unused function warning for !CONFIG_SYSCTL

From: Arnd Bergmann <[email protected]>

Having fs_dqstats_table[] inside of an #ifdef causes a build time
warning:

fs/quota/dquot.c:2864:12: error: 'do_proc_dqstats' defined but not used [-Werror=unused-function]
2864 | static int do_proc_dqstats(struct ctl_table *table, int write,

Avoid this by using an IS_ENABLED() check in place of the #ifdef,
giving the compiler a better idea of how it is used.

Fixes: 63d00e08515b ("quota: check for register_sysctl() failure")
Signed-off-by: Arnd Bergmann <[email protected]>
---
Note: it may be better to just revert the 63d00e08515b patch, as the
additional pr_notice() does not seem to add much value after
the pr_err() printed by register_sysctl() that tells us exactly what
went wrong.
---
fs/quota/dquot.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 05bed02b257f..6e9109c6218e 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2877,7 +2877,6 @@ static int do_proc_dqstats(struct ctl_table *table, int write,
return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
}

-#ifdef CONFIG_SYSCTL
static struct ctl_table fs_dqstats_table[] = {
{
.procname = "lookups",
@@ -2946,7 +2945,6 @@ static struct ctl_table fs_dqstats_table[] = {
#endif
{ },
};
-#endif

static int __init dquot_init(void)
{
@@ -2955,10 +2953,10 @@ static int __init dquot_init(void)

printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__);

-#ifdef CONFIG_SYSCTL
- if (!register_sysctl("fs/quota", fs_dqstats_table))
- pr_notice("quota sysctl registration failed!\n");
-#endif
+ if (IS_ENABLED(CONFIG_SYSCTL)) {
+ if (!register_sysctl("fs/quota", fs_dqstats_table))
+ pr_notice("quota sysctl registration failed!\n");
+ }

dquot_cachep = kmem_cache_create("dquot",
sizeof(struct dquot), sizeof(unsigned long) * 4,
--
2.39.2


2023-03-28 17:54:04

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH] fs: quota: avoid unused function warning for !CONFIG_SYSCTL

On Tue, Mar 28, 2023 at 02:22:31PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
> Note: it may be better to just revert the 63d00e08515b patch, as the
> -#ifdef CONFIG_SYSCTL
> - if (!register_sysctl("fs/quota", fs_dqstats_table))
> - pr_notice("quota sysctl registration failed!\n");
> -#endif
> + if (IS_ENABLED(CONFIG_SYSCTL)) {
> + if (!register_sysctl("fs/quota", fs_dqstats_table))
> + pr_notice("quota sysctl registration failed!\n");
> + }

I'd agree to drop that patch and instead just use register_sysctl_init()
iwht Arnd's strategy.

Luis

2023-03-29 09:47:07

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH] fs: quota: avoid unused function warning for !CONFIG_SYSCTL

On Tue 28-03-23 10:48:20, Luis Chamberlain wrote:
> On Tue, Mar 28, 2023 at 02:22:31PM +0200, Arnd Bergmann wrote:
> > From: Arnd Bergmann <[email protected]>
> > Note: it may be better to just revert the 63d00e08515b patch, as the
> > -#ifdef CONFIG_SYSCTL
> > - if (!register_sysctl("fs/quota", fs_dqstats_table))
> > - pr_notice("quota sysctl registration failed!\n");
> > -#endif
> > + if (IS_ENABLED(CONFIG_SYSCTL)) {
> > + if (!register_sysctl("fs/quota", fs_dqstats_table))
> > + pr_notice("quota sysctl registration failed!\n");
> > + }
>
> I'd agree to drop that patch and instead just use register_sysctl_init()
> iwht Arnd's strategy.

Ah, indeed, register_sysctl_init() is exactly what we need here. I didn't
know about that helper. Thanks for letting me know.

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR