diff mbox series

[for-4.15,2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()

Message ID 20210305124003.13582-3-julien@xen.org (mailing list archive)
State New, archived
Headers show
Series xenstore: Check format printf | expand

Commit Message

Julien Grall March 5, 2021, 12:40 p.m. UTC
From: Julien Grall <jgrall@amazon.com>

Allow GCC to analyze the format printf for xprintf() and
barf{,_perror}().

Take the opportunity to define __noreturn to make the prototype for
barf{,_perror})() easier to read.

Signed-off-by: Julien Grall <jgrall@amazon.com>
---
 tools/xenstore/utils.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jürgen Groß March 5, 2021, 1:01 p.m. UTC | #1
On 05.03.21 13:40, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
> 
> Allow GCC to analyze the format printf for xprintf() and
> barf{,_perror}().
> 
> Take the opportunity to define __noreturn to make the prototype for
> barf{,_perror})() easier to read.
> 
> Signed-off-by: Julien Grall <jgrall@amazon.com>

Reviewed-by: Juergen Gross <jgross@suse.com>

But I would prefer, if ...

> ---
>   tools/xenstore/utils.h | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h
> index 3dfb96b556dd..ccfb9b8fb699 100644
> --- a/tools/xenstore/utils.h
> +++ b/tools/xenstore/utils.h
> @@ -29,10 +29,12 @@ const char *dump_state_align(FILE *fp);
>   
>   #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2)))
>   
> -void barf(const char *fmt, ...) __attribute__((noreturn));
> -void barf_perror(const char *fmt, ...) __attribute__((noreturn));
> +#define __noreturn __attribute__((noreturn))
>   
> -extern void (*xprintf)(const char *fmt, ...);
> +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
> +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
> +
> +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);

... the extern here would be dropped.


Juergen
Ian Jackson March 5, 2021, 1:24 p.m. UTC | #2
Julien Grall writes ("[PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
> From: Julien Grall <jgrall@amazon.com>
> 
> Allow GCC to analyze the format printf for xprintf() and
> barf{,_perror}().
> 
> Take the opportunity to define __noreturn to make the prototype for
> barf{,_perror})() easier to read.

Release-Acked-by: Ian Jackson <iwj@xenproject.org>
Ian Jackson March 5, 2021, 1:27 p.m. UTC | #3
Jürgen Groß writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
> On 05.03.21 13:40, Julien Grall wrote:
> > -extern void (*xprintf)(const char *fmt, ...);
> > +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
> > +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
> > +
> > +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
> 
> ... the extern here would be dropped.

With my RM hat on I don't have an opinion on that and my R-A can
stand.

With my maintainer hat on I agree with Jürgen's style opinion - it's
nicer without the "extern", but I'm also happy with the patch as is.

Ian.
Julien Grall March 5, 2021, 1:32 p.m. UTC | #4
Hi Ian,

On 05/03/2021 13:27, Ian Jackson wrote:
> Jürgen Groß writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
>> On 05.03.21 13:40, Julien Grall wrote:
>>> -extern void (*xprintf)(const char *fmt, ...);
>>> +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +
>>> +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
>>
>> ... the extern here would be dropped.
> 
> With my RM hat on I don't have an opinion on that and my R-A can
> stand.
> 
> With my maintainer hat on I agree with Jürgen's style opinion - it's
> nicer without the "extern", but I'm also happy with the patch as is.
I agree with Juergen's style opinion. I will do the modification on 
commit. I will also update the last sentence of the commit to:

"
Take the opportunity to:
    * remove extern from the function prototype for consistency
    * define __noreturn to make the prototype for
barf{,_perror})() easier to read.
"

Cheers,

> Ian.
>
Jan Beulich March 5, 2021, 1:45 p.m. UTC | #5
On 05.03.2021 14:01, Jürgen Groß wrote:
> On 05.03.21 13:40, Julien Grall wrote:
>> From: Julien Grall <jgrall@amazon.com>
>> --- a/tools/xenstore/utils.h
>> +++ b/tools/xenstore/utils.h
>> @@ -29,10 +29,12 @@ const char *dump_state_align(FILE *fp);
>>   
>>   #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2)))
>>   
>> -void barf(const char *fmt, ...) __attribute__((noreturn));
>> -void barf_perror(const char *fmt, ...) __attribute__((noreturn));
>> +#define __noreturn __attribute__((noreturn))
>>   
>> -extern void (*xprintf)(const char *fmt, ...);
>> +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>> +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>> +
>> +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
> 
> ... the extern here would be dropped.

But this isn't a function declaration, but that of a data object.
With the extern dropped, a common symbol will appear in every CU.

Jan
Andrew Cooper March 5, 2021, 1:48 p.m. UTC | #6
On 05/03/2021 13:45, Jan Beulich wrote:
> On 05.03.2021 14:01, Jürgen Groß wrote:
>> On 05.03.21 13:40, Julien Grall wrote:
>>> From: Julien Grall <jgrall@amazon.com>
>>> --- a/tools/xenstore/utils.h
>>> +++ b/tools/xenstore/utils.h
>>> @@ -29,10 +29,12 @@ const char *dump_state_align(FILE *fp);
>>>   
>>>   #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2)))
>>>   
>>> -void barf(const char *fmt, ...) __attribute__((noreturn));
>>> -void barf_perror(const char *fmt, ...) __attribute__((noreturn));
>>> +#define __noreturn __attribute__((noreturn))
>>>   
>>> -extern void (*xprintf)(const char *fmt, ...);
>>> +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +
>>> +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
>> ... the extern here would be dropped.
> But this isn't a function declaration, but that of a data object.
> With the extern dropped, a common symbol will appear in every CU.

Correct, and some of the containers in Gitlab CI really ought to notice
because GCC 9(? IIRC) defaulted to -fno-common.

~Andrew
Julien Grall March 5, 2021, 1:48 p.m. UTC | #7
Hi Jan,

On 05/03/2021 13:45, Jan Beulich wrote:
> On 05.03.2021 14:01, Jürgen Groß wrote:
>> On 05.03.21 13:40, Julien Grall wrote:
>>> From: Julien Grall <jgrall@amazon.com>
>>> --- a/tools/xenstore/utils.h
>>> +++ b/tools/xenstore/utils.h
>>> @@ -29,10 +29,12 @@ const char *dump_state_align(FILE *fp);
>>>    
>>>    #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2)))
>>>    
>>> -void barf(const char *fmt, ...) __attribute__((noreturn));
>>> -void barf_perror(const char *fmt, ...) __attribute__((noreturn));
>>> +#define __noreturn __attribute__((noreturn))
>>>    
>>> -extern void (*xprintf)(const char *fmt, ...);
>>> +void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
>>> +
>>> +extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
>>
>> ... the extern here would be dropped.
> 
> But this isn't a function declaration, but that of a data object.
> With the extern dropped, a common symbol will appear in every CU.

Urgh, you are right. Actually, the extern was added recently by Anthony:

dacdbf7088d6a3705a9831e73991c2b14c519a65 ("tools/xenstore: mark variable 
in header as extern")

I completely forgot it despite I needed to backport the patch to our 
downstream Xen.

Cheers,
Ian Jackson March 5, 2021, 1:58 p.m. UTC | #8
Julien Grall writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
> Urgh, you are right. Actually, the extern was added recently by Anthony:
> 
> dacdbf7088d6a3705a9831e73991c2b14c519a65 ("tools/xenstore: mark variable 
> in header as extern")
> 
> I completely forgot it despite I needed to backport the patch to our 
> downstream Xen.

How horrible.

Maybe we could add a comment to the code, next to the declaration,
about this crazy situation.

Ian.
Julien Grall March 6, 2021, 7:37 p.m. UTC | #9
Hi Ian,

On 05/03/2021 13:58, Ian Jackson wrote:
> Julien Grall writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
>> Urgh, you are right. Actually, the extern was added recently by Anthony:
>>
>> dacdbf7088d6a3705a9831e73991c2b14c519a65 ("tools/xenstore: mark variable
>> in header as extern")
>>
>> I completely forgot it despite I needed to backport the patch to our
>> downstream Xen.
> 
> How horrible.
> 
> Maybe we could add a comment to the code, next to the declaration,
> about this crazy situation.

Would the following comment work for you?

/* Function pointer as xprintf() can be configured at runtime. */

I can fold it in my patch while committing.

Cheers,

> 
> Ian.
>
Ian Jackson March 8, 2021, 9:44 a.m. UTC | #10
Julien Grall writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
> Would the following comment work for you?
> 
> /* Function pointer as xprintf() can be configured at runtime. */
> 
> I can fold it in my patch while committing.

Sure, thanks.  FTAOD

Reviewed-by: Ian Jackson <iwj@xenproject.org>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>

to that comment addition.

Ian.
Julien Grall March 11, 2021, 9:48 a.m. UTC | #11
Hi Ian,

On 08/03/2021 09:44, Ian Jackson wrote:
> Julien Grall writes ("Re: [PATCH for-4.15 2/2] tools/xenstore: Check the format printf for xprintf() and barf{,_perror}()"):
>> Would the following comment work for you?
>>
>> /* Function pointer as xprintf() can be configured at runtime. */
>>
>> I can fold it in my patch while committing.
> 
> Sure, thanks.  FTAOD
> 
> Reviewed-by: Ian Jackson <iwj@xenproject.org>
> Release-Acked-by: Ian Jackson <iwj@xenproject.org>
> 
> to that comment addition.

Thanks! I have committed the two patches.

Cheers,
diff mbox series

Patch

diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h
index 3dfb96b556dd..ccfb9b8fb699 100644
--- a/tools/xenstore/utils.h
+++ b/tools/xenstore/utils.h
@@ -29,10 +29,12 @@  const char *dump_state_align(FILE *fp);
 
 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__((format (printf, a1, a2)))
 
-void barf(const char *fmt, ...) __attribute__((noreturn));
-void barf_perror(const char *fmt, ...) __attribute__((noreturn));
+#define __noreturn __attribute__((noreturn))
 
-extern void (*xprintf)(const char *fmt, ...);
+void barf(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
+void barf_perror(const char *fmt, ...) __noreturn PRINTF_ATTRIBUTE(1, 2);
+
+extern void (*xprintf)(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
 
 #define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args)