* [PATCH] btrfs: Fix a C compliance issue
@ 2018-06-15 22:36 Bart Van Assche
2018-06-16 10:28 ` Nikolay Borisov
0 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2018-06-15 22:36 UTC (permalink / raw)
To: Chris Mason
Cc: Josef Bacik, David Sterba, linux-btrfs, Bart Van Assche, Jeff Mahoney
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());
}
static int __init init_btrfs_fs(void)
--
2.17.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-15 22:36 [PATCH] btrfs: Fix a C compliance issue Bart Van Assche
@ 2018-06-16 10:28 ` Nikolay Borisov
2018-06-18 9:26 ` David Sterba
0 siblings, 1 reply; 8+ messages in thread
From: Nikolay Borisov @ 2018-06-16 10:28 UTC (permalink / raw)
To: Bart Van Assche, Chris Mason
Cc: Josef Bacik, David Sterba, linux-btrfs, Jeff Mahoney
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)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-16 10:28 ` Nikolay Borisov
@ 2018-06-18 9:26 ` David Sterba
2018-06-18 9:31 ` Nikolay Borisov
0 siblings, 1 reply; 8+ messages in thread
From: David Sterba @ 2018-06-18 9:26 UTC (permalink / raw)
To: Nikolay Borisov
Cc: Bart Van Assche, Chris Mason, Josef Bacik, David Sterba,
linux-btrfs, Jeff Mahoney
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);
?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-18 9:26 ` David Sterba
@ 2018-06-18 9:31 ` Nikolay Borisov
2018-06-20 16:44 ` Bart Van Assche
0 siblings, 1 reply; 8+ messages in thread
From: Nikolay Borisov @ 2018-06-18 9:31 UTC (permalink / raw)
To: dsterba, Bart Van Assche, Chris Mason, Josef Bacik, David Sterba,
linux-btrfs, Jeff Mahoney
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?
>
> ?
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-18 9:31 ` Nikolay Borisov
@ 2018-06-20 16:44 ` Bart Van Assche
2018-06-20 16:55 ` David Sterba
0 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2018-06-20 16:44 UTC (permalink / raw)
To: dsterba, nborisov, dsterba, clm, jeffm, jbacik, linux-btrfs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1026 bytes --]
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.
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±ý»k~ÏâØ^nr¡ö¦zË\x1aëh¨èÚ&£ûàz¿äz¹Þú+Ê+zf£¢·h§~Ûiÿÿïêÿêçz_è®\x0fæj:+v¨þ)ߣøm
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-20 16:44 ` Bart Van Assche
@ 2018-06-20 16:55 ` David Sterba
2018-06-20 17:19 ` Jeff Mahoney
0 siblings, 1 reply; 8+ messages in thread
From: David Sterba @ 2018-06-20 16:55 UTC (permalink / raw)
To: Bart Van Assche
Cc: dsterba, nborisov, dsterba, clm, jeffm, jbacik, linux-btrfs
On Wed, Jun 20, 2018 at 04:44:54PM +0000, Bart Van Assche wrote:
> 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().
Right, the pr_info(fmt,...) does not compile. The closest version I got to is
below. It does not look pretty, but I can't think of a better version right
now.
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2369,7 +2369,8 @@ static __cold void btrfs_interface_exit(void)
static void __init btrfs_print_mod_info(void)
{
- static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
+ static const char fmt1[] = "Btrfs loaded, crc32c=";
+ static const char fmt2[] =
#ifdef CONFIG_BTRFS_DEBUG
", debug=on"
#endif
@@ -2383,7 +2384,7 @@ static void __init btrfs_print_mod_info(void)
", ref-verify=on"
#endif
"\n";
- printk(fmt, crc32c_impl());
+ pr_info("%s%s%s", fmt1, crc32c_impl(), fmt2);
}
static int __init init_btrfs_fs(void)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-20 16:55 ` David Sterba
@ 2018-06-20 17:19 ` Jeff Mahoney
2018-06-20 17:58 ` Bart Van Assche
0 siblings, 1 reply; 8+ messages in thread
From: Jeff Mahoney @ 2018-06-20 17:19 UTC (permalink / raw)
To: dsterba, Bart Van Assche, nborisov, dsterba, clm, jbacik, linux-btrfs
On 6/20/18 12:55 PM, David Sterba wrote:
> On Wed, Jun 20, 2018 at 04:44:54PM +0000, Bart Van Assche wrote:
>> 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().
>
> Right, the pr_info(fmt,...) does not compile. The closest version I got to is
> below. It does not look pretty, but I can't think of a better version right
> now.
>
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2369,7 +2369,8 @@ static __cold void btrfs_interface_exit(void)
>
> static void __init btrfs_print_mod_info(void)
> {
> - static const char fmt[] = KERN_INFO "Btrfs loaded, crc32c=%s"
> + static const char fmt1[] = "Btrfs loaded, crc32c=";
> + static const char fmt2[] =
> #ifdef CONFIG_BTRFS_DEBUG
> ", debug=on"
> #endif
> @@ -2383,7 +2384,7 @@ static void __init btrfs_print_mod_info(void)
> ", ref-verify=on"
> #endif
> "\n";
> - printk(fmt, crc32c_impl());
> + pr_info("%s%s%s", fmt1, crc32c_impl(), fmt2);
> }
>
> static int __init init_btrfs_fs(void)
The shed should be yellow.
-Jeff
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 891cd2ed5dd4..57c9da0b459f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2375,21 +2375,20 @@ static __cold void btrfs_interface_exit(void)
static void __init btrfs_print_mod_info(void)
{
- pr_info("Btrfs loaded, crc32c=%s"
+ pr_info("Btrfs loaded, crc32c=%s", crc32c_impl());
#ifdef CONFIG_BTRFS_DEBUG
- ", debug=on"
+ pr_cont(", debug=on");
#endif
#ifdef CONFIG_BTRFS_ASSERT
- ", assert=on"
+ pr_cont(", assert=on");
#endif
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
- ", integrity-checker=on"
+ pr_cont(", integrity-checker=on");
#endif
#ifdef CONFIG_BTRFS_FS_REF_VERIFY
- ", ref-verify=on"
+ pr_cont(", ref-verify=on")
#endif
- "\n",
- crc32c_impl());
+ pr_cont("\n");
}
static int null_open(struct block_device *bdev, fmode_t mode)
--
Jeff Mahoney
SUSE Labs
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] btrfs: Fix a C compliance issue
2018-06-20 17:19 ` Jeff Mahoney
@ 2018-06-20 17:58 ` Bart Van Assche
0 siblings, 0 replies; 8+ messages in thread
From: Bart Van Assche @ 2018-06-20 17:58 UTC (permalink / raw)
To: dsterba, nborisov, jeffm, dsterba, clm, jbacik, linux-btrfs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1460 bytes --]
On Wed, 2018-06-20 at 13:19 -0400, Jeff Mahoney wrote:
> The shed should be yellow.
>
> -Jeff
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 891cd2ed5dd4..57c9da0b459f 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2375,21 +2375,20 @@ static __cold void btrfs_interface_exit(void)
>
> static void __init btrfs_print_mod_info(void)
> {
> - pr_info("Btrfs loaded, crc32c=%s"
> + pr_info("Btrfs loaded, crc32c=%s", crc32c_impl());
> #ifdef CONFIG_BTRFS_DEBUG
> - ", debug=on"
> + pr_cont(", debug=on");
> #endif
> #ifdef CONFIG_BTRFS_ASSERT
> - ", assert=on"
> + pr_cont(", assert=on");
> #endif
> #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
> - ", integrity-checker=on"
> + pr_cont(", integrity-checker=on");
> #endif
> #ifdef CONFIG_BTRFS_FS_REF_VERIFY
> - ", ref-verify=on"
> + pr_cont(", ref-verify=on")
> #endif
> - "\n",
> - crc32c_impl());
> + pr_cont("\n");
> }
>
> static int null_open(struct block_device *bdev, fmode_t mode)
Since we are doing bikeshedding, let me contribute to it :-)
>From scripts/checkpatch.pl:
if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
WARN("LOGGING_CONTINUATION",
"Avoid logging continuation uses where feasible\n" . $herecurr);
}
Bart.
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±ý»k~ÏâØ^nr¡ö¦zË\x1aëh¨èÚ&£ûàz¿äz¹Þú+Ê+zf£¢·h§~Ûiÿÿïêÿêçz_è®\x0fæj:+v¨þ)ߣøm
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-06-20 17:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15 22:36 [PATCH] btrfs: Fix a C compliance issue Bart Van Assche
2018-06-16 10:28 ` Nikolay Borisov
2018-06-18 9:26 ` David Sterba
2018-06-18 9:31 ` Nikolay Borisov
2018-06-20 16:44 ` Bart Van Assche
2018-06-20 16:55 ` David Sterba
2018-06-20 17:19 ` Jeff Mahoney
2018-06-20 17:58 ` Bart Van Assche
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.