diff mbox

btrfs: Fix a C compliance issue

Message ID 20180615223659.32420-1-bart.vanassche@wdc.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bart Van Assche June 15, 2018, 10:36 p.m. UTC
The C programming language does not allow to use preprocessor statements
inside macro arguments (pr_info() is defined as a macro). Hence rework
the pr_info() statement in btrfs_print_mod_info() such that it becomes
compliant. This patch allows tools like sparse to analyze the BTRFS
source code.

Fixes: 62e855771dac ("btrfs: convert printk(KERN_* to use pr_* calls")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Jeff Mahoney <jeffm@suse.com>
Cc: David Sterba <dsterba@suse.com>
---
 fs/btrfs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Nikolay Borisov June 16, 2018, 10:28 a.m. UTC | #1
On 16.06.2018 01:36, Bart Van Assche wrote:
> The C programming language does not allow to use preprocessor statements
> inside macro arguments (pr_info() is defined as a macro). Hence rework
> the pr_info() statement in btrfs_print_mod_info() such that it becomes
> compliant. This patch allows tools like sparse to analyze the BTRFS
> source code.
> 
> Fixes: 62e855771dac ("btrfs: convert printk(KERN_* to use pr_* calls")
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Jeff Mahoney <jeffm@suse.com>
> Cc: David Sterba <dsterba@suse.com>
> ---
>  fs/btrfs/super.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 81107ad49f3a..dd4980df5b8e 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2369,7 +2369,7 @@ static __cold void btrfs_interface_exit(void)
>  
>  static void __init btrfs_print_mod_info(void)
>  {
> -	pr_info("Btrfs loaded, crc32c=%s"
> +	static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
>  #ifdef CONFIG_BTRFS_DEBUG
>  			", debug=on"
>  #endif
> @@ -2382,8 +2382,8 @@ static void __init btrfs_print_mod_info(void)
>  #ifdef CONFIG_BTRFS_FS_REF_VERIFY
>  			", ref-verify=on"
>  #endif
> -			"\n",
> -			crc32c_impl());
> +			"\n";
> +	printk(fmt, crc32c_impl());

I'd rather not see more printk being added. Nothing prevents from having
the fmt string being passed to pr_info.
>  }
>  
>  static int __init init_btrfs_fs(void)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba June 18, 2018, 9:26 a.m. UTC | #2
On Sat, Jun 16, 2018 at 01:28:13PM +0300, Nikolay Borisov wrote:
> 
> 
> On 16.06.2018 01:36, Bart Van Assche wrote:
> > The C programming language does not allow to use preprocessor statements
> > inside macro arguments (pr_info() is defined as a macro). Hence rework
> > the pr_info() statement in btrfs_print_mod_info() such that it becomes
> > compliant. This patch allows tools like sparse to analyze the BTRFS
> > source code.
> > 
> > Fixes: 62e855771dac ("btrfs: convert printk(KERN_* to use pr_* calls")
> > Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> > Cc: Jeff Mahoney <jeffm@suse.com>
> > Cc: David Sterba <dsterba@suse.com>
> > ---
> >  fs/btrfs/super.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> > index 81107ad49f3a..dd4980df5b8e 100644
> > --- a/fs/btrfs/super.c
> > +++ b/fs/btrfs/super.c
> > @@ -2369,7 +2369,7 @@ static __cold void btrfs_interface_exit(void)
> >  
> >  static void __init btrfs_print_mod_info(void)
> >  {
> > -	pr_info("Btrfs loaded, crc32c=%s"
> > +	static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
> >  #ifdef CONFIG_BTRFS_DEBUG
> >  			", debug=on"
> >  #endif
> > @@ -2382,8 +2382,8 @@ static void __init btrfs_print_mod_info(void)
> >  #ifdef CONFIG_BTRFS_FS_REF_VERIFY
> >  			", ref-verify=on"
> >  #endif
> > -			"\n",
> > -			crc32c_impl());
> > +			"\n";
> > +	printk(fmt, crc32c_impl());
> 
> I'd rather not see more printk being added. Nothing prevents from having
> the fmt string being passed to pr_info.

So you mean to do

+	static const char fmt[] = "Btrfs loaded, crc32c=%s"
+	pr_info(fmt);

?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nikolay Borisov June 18, 2018, 9:31 a.m. UTC | #3
On 18.06.2018 12:26, David Sterba wrote:
> On Sat, Jun 16, 2018 at 01:28:13PM +0300, Nikolay Borisov wrote:
>>
>>
>> On 16.06.2018 01:36, Bart Van Assche wrote:
>>> The C programming language does not allow to use preprocessor statements
>>> inside macro arguments (pr_info() is defined as a macro). Hence rework
>>> the pr_info() statement in btrfs_print_mod_info() such that it becomes
>>> compliant. This patch allows tools like sparse to analyze the BTRFS
>>> source code.
>>>
>>> Fixes: 62e855771dac ("btrfs: convert printk(KERN_* to use pr_* calls")
>>> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
>>> Cc: Jeff Mahoney <jeffm@suse.com>
>>> Cc: David Sterba <dsterba@suse.com>
>>> ---
>>>  fs/btrfs/super.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
>>> index 81107ad49f3a..dd4980df5b8e 100644
>>> --- a/fs/btrfs/super.c
>>> +++ b/fs/btrfs/super.c
>>> @@ -2369,7 +2369,7 @@ static __cold void btrfs_interface_exit(void)
>>>  
>>>  static void __init btrfs_print_mod_info(void)
>>>  {
>>> -	pr_info("Btrfs loaded, crc32c=%s"
>>> +	static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
>>>  #ifdef CONFIG_BTRFS_DEBUG
>>>  			", debug=on"
>>>  #endif
>>> @@ -2382,8 +2382,8 @@ static void __init btrfs_print_mod_info(void)
>>>  #ifdef CONFIG_BTRFS_FS_REF_VERIFY
>>>  			", ref-verify=on"
>>>  #endif
>>> -			"\n",
>>> -			crc32c_impl());
>>> +			"\n";
>>> +	printk(fmt, crc32c_impl());
>>
>> I'd rather not see more printk being added. Nothing prevents from having
>> the fmt string being passed to pr_info.
> 
> So you mean to do
> 
> +	static const char fmt[] = "Btrfs loaded, crc32c=%s"
> +	pr_info(fmt);

Pretty much, something along the lines of

pr_info(fmt, crc32c_impl).

printk requires having the KERN_INFO in the format string, which I see
no point in doing, correct me if I'm wrong?
> 
> ?
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche June 20, 2018, 4:44 p.m. UTC | #4
On Mon, 2018-06-18 at 12:31 +0300, Nikolay Borisov wrote:
> On 18.06.2018 12:26, David Sterba wrote:

> > On Sat, Jun 16, 2018 at 01:28:13PM +0300, Nikolay Borisov wrote:

> > > I'd rather not see more printk being added. Nothing prevents from having

> > > the fmt string being passed to pr_info.

> > 

> > So you mean to do

> > 

> > +	static const char fmt[] = "Btrfs loaded, crc32c=%s"

> > +	pr_info(fmt);

> 

> Pretty much, something along the lines of

> 

> pr_info(fmt, crc32c_impl).

> 

> printk requires having the KERN_INFO in the format string, which I see

> no point in doing, correct me if I'm wrong?


You should know that what you proposed doesn't compile because pr_info()
relies on string concatenation and hence requires that its first argument is
a string constant instead of a const char pointer. Anyway, I will rework this
patch such that it uses pr_info() instead of printk().

Bart.
diff mbox

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 81107ad49f3a..dd4980df5b8e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2369,7 +2369,7 @@  static __cold void btrfs_interface_exit(void)
 
 static void __init btrfs_print_mod_info(void)
 {
-	pr_info("Btrfs loaded, crc32c=%s"
+	static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
 #ifdef CONFIG_BTRFS_DEBUG
 			", debug=on"
 #endif
@@ -2382,8 +2382,8 @@  static void __init btrfs_print_mod_info(void)
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
 			", ref-verify=on"
 #endif
-			"\n",
-			crc32c_impl());
+			"\n";
+	printk(fmt, crc32c_impl());
 }
 
 static int __init init_btrfs_fs(void)