Skip to contentSkip to conversation

Enable Wformat for clang

PATCH Superseded Roger Pau Monne 3 participants 9 messages Feb 13, 2017

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Enable Wformat for clang

Hello,

These patches fix the remaining issues so that Wformat can be enabled for clang. Note that this has only been tested on FreeBSD with clang 3.8, and the components enabled might be different from the ones present in other OSes.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

PATCH v2 1/2 xen/grants: print grant number and handle in hex format

Due to the large number of grants in use it seems more useful to print the grant references and handlers in hex format rather than decimal.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/common/grant_table.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
xen/common/grant_table.c +13 -13
index d3ea805..eca07b9 100644
@@ -814,7 +814,7 @@ __gnttab_map_grant_ref(
 
     /* Bounds check on the grant ref */
     if ( unlikely(op->ref >= nr_grant_entries(rgt)))
-        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%d).\n", op->ref);
+        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%#x).\n", op->ref);
 
     act = active_entry_acquire(rgt, op->ref);
     shah = shared_entry_header(rgt, op->ref);
@@ -1087,7 +1087,7 @@ __gnttab_unmap_common(
 
     if ( unlikely(op->handle >= lgt->maptrack_limit) )
     {
-        gdprintk(XENLOG_INFO, "Bad handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Bad handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1099,7 +1099,7 @@ __gnttab_unmap_common(
     if ( unlikely(!read_atomic(&op->map->flags)) )
     {
         grant_read_unlock(lgt);
-        gdprintk(XENLOG_INFO, "Zero flags for handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Zero flags for handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1132,7 +1132,7 @@ __gnttab_unmap_common(
     op->flags = read_atomic(&op->map->flags);
     if ( unlikely(!op->flags) || unlikely(op->map->domid != dom) )
     {
-        gdprintk(XENLOG_WARNING, "Unstable handle %u\n", op->handle);
+        gdprintk(XENLOG_WARNING, "Unstable handle %#x\n", op->handle);
         rc = GNTST_bad_handle;
         goto unmap_out;
     }
@@ -1706,7 +1706,7 @@ gnttab_prepare_for_transfer(
     if ( unlikely(ref >= nr_grant_entries(rgt)) )
     {
         gdprintk(XENLOG_INFO,
-                "Bad grant reference (%d) for transfer to domain(%d).\n",
+                "Bad grant reference (%#x) for transfer to domain(%d).\n",
                 ref, rd->domain_id);
         goto fail;
     }
@@ -2672,7 +2672,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
                 break;
             default:
                 gdprintk(XENLOG_INFO,
-                         "bad flags %#x in grant %u when switching version\n",
+                         "bad flags %#x in grant %#x when switching version\n",
                          flags, i);
                 /* fall through */
             case GTF_invalid:
@@ -2836,9 +2836,9 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     /* Bounds check on the grant refs */
     if ( unlikely(ref_a >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%d).\n", ref_a);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%#x).\n", ref_a);
     if ( unlikely(ref_b >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%d).\n", ref_b);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%#x).\n", ref_b);
 
     /* Swapping the same ref is a no-op. */
     if ( ref_a == ref_b )
@@ -2846,11 +2846,11 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     act_a = active_entry_acquire(gt, ref_a);
     if ( act_a->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref a %ld busy\n", (long)ref_a);
+        PIN_FAIL(out, GNTST_eagain, "ref a %#x busy\n", ref_a);
 
     act_b = active_entry_acquire(gt, ref_b);
     if ( act_b->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref b %ld busy\n", (long)ref_b);
+        PIN_FAIL(out, GNTST_eagain, "ref b %#x busy\n", ref_b);
 
     if ( gt->gt_version == 1 )
     {
@@ -3284,7 +3284,7 @@ gnttab_release_mappings(
 
         ref = map->ref;
 
-        gdprintk(XENLOG_INFO, "Grant release (%hu) ref:(%hu) "
+        gdprintk(XENLOG_INFO, "Grant release (%#x) ref:(%#x) "
                 "flags:(%x) dom:(%hu)\n",
                 handle, ref, map->flags, map->domid);
 
@@ -3530,8 +3530,8 @@ static void gnttab_usage_print(struct domain *rd)
             first = 0;
         }
 
-        /*      [ddd]    ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
-        printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
+        /*      [0xXXX]  ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
+        printk("[%#03x]  %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
                ref, act->domid, act->frame, act->pin,
                sha->domid, frame, status);
         active_entry_release(act);
Signature · 7 lines
2.10.1 (Apple Git-78)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v2 1/2] xen/grants: print grant number and handle in hex format

Quoted 22 lines · Roger Pau Monne

Due to the large number of grants in use it seems more useful to print the grant references and handlers in hex format rather than decimal.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/common/grant_table.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
xen/common/grant_table.c +0 -0
index d3ea805..eca07b9 100644

xen/common/grant_table.c __gnttab_map_grant_ref( · line 817

Quoted 5 lines
xen/common/grant_table.c +1 -1
@@ -814,7 +814,7 @@ __gnttab_map_grant_ref(
 
     /* Bounds check on the grant ref */
     if ( unlikely(op->ref >= nr_grant_entries(rgt)))
-        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%d).\n", op->ref);
+        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%#x).\n", op->ref);

I'd drop the brackets and full stop, as you are making changes here. Similarly below.

Quoted 31 lines
xen/common/grant_table.c +3 -3
     act = active_entry_acquire(rgt, op->ref);
     shah = shared_entry_header(rgt, op->ref);
@@ -1087,7 +1087,7 @@ __gnttab_unmap_common(
 
     if ( unlikely(op->handle >= lgt->maptrack_limit) )
     {
-        gdprintk(XENLOG_INFO, "Bad handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Bad handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1099,7 +1099,7 @@ __gnttab_unmap_common(
     if ( unlikely(!read_atomic(&op->map->flags)) )
     {
         grant_read_unlock(lgt);
-        gdprintk(XENLOG_INFO, "Zero flags for handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Zero flags for handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1132,7 +1132,7 @@ __gnttab_unmap_common(
     op->flags = read_atomic(&op->map->flags);
     if ( unlikely(!op->flags) || unlikely(op->map->domid != dom) )
     {
-        gdprintk(XENLOG_WARNING, "Unstable handle %u\n", op->handle);
+        gdprintk(XENLOG_WARNING, "Unstable handle %#x\n", op->handle);
         rc = GNTST_bad_handle;
         goto unmap_out;
     }

xen/common/grant_table.c gnttab_prepare_for_transfer( · line 1710

Quoted 6 lines
xen/common/grant_table.c +1 -1
@@ -1706,7 +1706,7 @@ gnttab_prepare_for_transfer(
     if ( unlikely(ref >= nr_grant_entries(rgt)) )
     {
         gdprintk(XENLOG_INFO,
-                "Bad grant reference (%d) for transfer to domain(%d).\n",
+                "Bad grant reference (%#x) for transfer to domain(%d).\n",
                 ref, rd->domain_id);

We can shorten this to just d%d, matching our prevailing domain notation.

Quoted 47 lines
xen/common/grant_table.c +6 -6
         goto fail;
     }
@@ -2672,7 +2672,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
                 break;
             default:
                 gdprintk(XENLOG_INFO,
-                         "bad flags %#x in grant %u when switching version\n",
+                         "bad flags %#x in grant %#x when switching version\n",
                          flags, i);
                 /* fall through */
             case GTF_invalid:
@@ -2836,9 +2836,9 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     /* Bounds check on the grant refs */
     if ( unlikely(ref_a >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%d).\n", ref_a);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%#x).\n", ref_a);
     if ( unlikely(ref_b >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%d).\n", ref_b);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%#x).\n", ref_b);
 
     /* Swapping the same ref is a no-op. */
     if ( ref_a == ref_b )
@@ -2846,11 +2846,11 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     act_a = active_entry_acquire(gt, ref_a);
     if ( act_a->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref a %ld busy\n", (long)ref_a);
+        PIN_FAIL(out, GNTST_eagain, "ref a %#x busy\n", ref_a);
 
     act_b = active_entry_acquire(gt, ref_b);
     if ( act_b->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref b %ld busy\n", (long)ref_b);
+        PIN_FAIL(out, GNTST_eagain, "ref b %#x busy\n", ref_b);
 
     if ( gt->gt_version == 1 )
     {
@@ -3284,7 +3284,7 @@ gnttab_release_mappings(
 
         ref = map->ref;
 
-        gdprintk(XENLOG_INFO, "Grant release (%hu) ref:(%hu) "
+        gdprintk(XENLOG_INFO, "Grant release (%#x) ref:(%#x) "
                 "flags:(%x) dom:(%hu)\n",
                 handle, ref, map->flags, map->domid);
 

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 3534

Quoted 7 lines
xen/common/grant_table.c +2 -2
@@ -3530,8 +3530,8 @@ static void gnttab_usage_print(struct domain *rd)
             first = 0;
         }
 
-        /*      [ddd]    ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
-        printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
+        /*      [0xXXX]  ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
+        printk("[%#03x]  %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",

This needs to be 0x%03x to work properly. With #, the 0x comes out of the limit of 3 characters.

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 3537

Quoted 3 lines
xen/common/grant_table.c +0 -0
                ref, act->domid, act->frame, act->pin,
                sha->domid, frame, status);
         active_entry_release(act);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v2 1/2] xen/grants: print grant number and handle in hex format

Quoted 24 lines · Andrew Cooper
Quoted 23 lines · Roger Pau Monne

Due to the large number of grants in use it seems more useful to print the grant references and handlers in hex format rather than decimal.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/common/grant_table.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
xen/common/grant_table.c +0 -0
index d3ea805..eca07b9 100644
@@ -814,7 +814,7 @@ __gnttab_map_grant_ref(
 
Quoted 7 lines

xen/common/grant_table.c __gnttab_map_grant_ref( · line 817

Quoted 4 lines
xen/common/grant_table.c +1 -1
     /* Bounds check on the grant ref */
     if ( unlikely(op->ref >= nr_grant_entries(rgt)))
-        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%d).\n", op->ref);
+        PIN_FAIL(unlock_out, GNTST_bad_gntref, "Bad ref (%#x).\n", op->ref);

I'd drop the brackets and full stop, as you are making changes here. Similarly below.

OK, I think I've fixed the occurrences of this kind of pattern in the messages I'm touching.

Quoted 31 lines
Quoted 31 lines
xen/common/grant_table.c +3 -3
     act = active_entry_acquire(rgt, op->ref);
     shah = shared_entry_header(rgt, op->ref);
@@ -1087,7 +1087,7 @@ __gnttab_unmap_common(
 
     if ( unlikely(op->handle >= lgt->maptrack_limit) )
     {
-        gdprintk(XENLOG_INFO, "Bad handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Bad handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1099,7 +1099,7 @@ __gnttab_unmap_common(
     if ( unlikely(!read_atomic(&op->map->flags)) )
     {
         grant_read_unlock(lgt);
-        gdprintk(XENLOG_INFO, "Zero flags for handle (%d).\n", op->handle);
+        gdprintk(XENLOG_INFO, "Zero flags for handle (%#x).\n", op->handle);
         op->status = GNTST_bad_handle;
         return;
     }
@@ -1132,7 +1132,7 @@ __gnttab_unmap_common(
     op->flags = read_atomic(&op->map->flags);
     if ( unlikely(!op->flags) || unlikely(op->map->domid != dom) )
     {
-        gdprintk(XENLOG_WARNING, "Unstable handle %u\n", op->handle);
+        gdprintk(XENLOG_WARNING, "Unstable handle %#x\n", op->handle);
         rc = GNTST_bad_handle;
         goto unmap_out;
     }
@@ -1706,7 +1706,7 @@ gnttab_prepare_for_transfer(
Quoted 8 lines

xen/common/grant_table.c gnttab_prepare_for_transfer( · line 1710

Quoted 6 lines
xen/common/grant_table.c +1 -1
     if ( unlikely(ref >= nr_grant_entries(rgt)) )
     {
         gdprintk(XENLOG_INFO,
-                "Bad grant reference (%d) for transfer to domain(%d).\n",
+                "Bad grant reference (%#x) for transfer to domain(%d).\n",
                 ref, rd->domain_id);

We can shorten this to just d%d, matching our prevailing domain notation.

OK, so now it's: "Bad grant reference (%#x) for transfer to d%d\n"

Quoted 50 lines
Quoted 50 lines
xen/common/grant_table.c +6 -6
         goto fail;
     }
@@ -2672,7 +2672,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
                 break;
             default:
                 gdprintk(XENLOG_INFO,
-                         "bad flags %#x in grant %u when switching version\n",
+                         "bad flags %#x in grant %#x when switching version\n",
                          flags, i);
                 /* fall through */
             case GTF_invalid:
@@ -2836,9 +2836,9 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     /* Bounds check on the grant refs */
     if ( unlikely(ref_a >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%d).\n", ref_a);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-a (%#x).\n", ref_a);
     if ( unlikely(ref_b >= nr_grant_entries(d->grant_table)))
-        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%d).\n", ref_b);
+        PIN_FAIL(out, GNTST_bad_gntref, "Bad ref-b (%#x).\n", ref_b);
 
     /* Swapping the same ref is a no-op. */
     if ( ref_a == ref_b )
@@ -2846,11 +2846,11 @@ __gnttab_swap_grant_ref(grant_ref_t ref_a, grant_ref_t ref_b)
 
     act_a = active_entry_acquire(gt, ref_a);
     if ( act_a->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref a %ld busy\n", (long)ref_a);
+        PIN_FAIL(out, GNTST_eagain, "ref a %#x busy\n", ref_a);
 
     act_b = active_entry_acquire(gt, ref_b);
     if ( act_b->pin )
-        PIN_FAIL(out, GNTST_eagain, "ref b %ld busy\n", (long)ref_b);
+        PIN_FAIL(out, GNTST_eagain, "ref b %#x busy\n", ref_b);
 
     if ( gt->gt_version == 1 )
     {
@@ -3284,7 +3284,7 @@ gnttab_release_mappings(
 
         ref = map->ref;
 
-        gdprintk(XENLOG_INFO, "Grant release (%hu) ref:(%hu) "
+        gdprintk(XENLOG_INFO, "Grant release (%#x) ref:(%#x) "
                 "flags:(%x) dom:(%hu)\n",
                 handle, ref, map->flags, map->domid);
 
@@ -3530,8 +3530,8 @@ static void gnttab_usage_print(struct domain *rd)
             first = 0;
         }
 
Quoted 7 lines

xen/common/grant_table.c static void gnttab_usage_print(struct domain *rd) · line 3534

Quoted 4 lines
xen/common/grant_table.c +2 -2
-        /*      [ddd]    ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
-        printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
+        /*      [0xXXX]  ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
+        printk("[%#03x]  %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",

This needs to be 0x%03x to work properly. With #, the 0x comes out of the limit of 3 characters.

Thanks, fixed.

Quoted 6 lines

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 3 lines
xen/common/grant_table.c +0 -0
                ref, act->domid, act->frame, act->pin,
                sha->domid, frame, status);
         active_entry_release(act);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v2 1/2] xen/grants: print grant number and handle in hex format

Quoted 11 lines · Roger Pau Monne
Quoted 9 lines · Andrew Cooper

xen/common/grant_table.c gnttab_prepare_for_transfer( · line 1710

Quoted 7 lines · Roger Pau Monne
xen/common/grant_table.c +1 -1
@@ -1706,7 +1706,7 @@ gnttab_prepare_for_transfer(
     if ( unlikely(ref >= nr_grant_entries(rgt)) )
     {
         gdprintk(XENLOG_INFO,
-                "Bad grant reference (%d) for transfer to domain(%d).\n",
+                "Bad grant reference (%#x) for transfer to domain(%d).\n",
                 ref, rd->domain_id);

We can shorten this to just d%d, matching our prevailing domain notation.

OK, so now it's: "Bad grant reference (%#x) for transfer to d%d\n"

TBH, I'd also drop the brackets here. They don't add anything but length to the message.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v2 2/2 build/printf: fix incorrect format specifiers

In reply to Roger Pau Monne

The following incorrect format specifiers and incorrect number of parameters passed to printf like functions are reported by clang:

mce.c:601:18: error: data argument not used by format string [-Werror,-Wformat-extra-args]

                 smp_processor_id());
                 ^

xenpm.c:102:23: error: data argument not used by format string [-Werror,-Wformat-extra-args]

                what, argv[argc > 1]);
                      ^

libxl_internal.c:25:69: error: data argument not used by format string

      [-Werror,-Wformat-extra-args]
    libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0,0, func, INVALID_DOMID, L);
                                                                    ^

libxl_internal.c:24:17: note: expanded from macro 'L'
func, (unsigned long)nmemb, (unsigned long)size
^
libxl_internal.c:26:21: error: data argument not used by format string

      [-Werror,-Wformat-extra-args]
    fprintf(stderr, L);
                    ^

libxl_internal.c:24:17: note: expanded from macro 'L'
func, (unsigned long)nmemb, (unsigned long)size
^

This patch contains the fixes for them and enabled -Wformat for clang.

---
NB: FWIW, there's a way to disable extra arguments checks (-Wno-format-extra-args), that would prevent us from having to apply some of the changes here. However, given that there are not that many occurrences, I would rather leave the full checks of Wformat enabled.

NB2: this has only been tested with a FreeBSD clang build (3.8.0), and only against the components that build on FreeBSD (ie: no qemu-trad, and certainly no blktap).
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Christoph Egger <[email protected]>
Cc: Liu Jinsong <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Change the format string for MCE to avoid duplicating CPU%i.
- Remove the grant-ref format specifier change, it's already taken care in patch #1.

---
 Config.mk                     |  2 +-
 tools/libxl/libxl_internal.c  | 21 ++++++++++++++++-----
 tools/misc/xenpm.c            | 13 ++++++++-----
 xen/arch/x86/cpu/mcheck/mce.c |  5 ++---
 4 files changed, 27 insertions(+), 14 deletions(-)
Config.mk +1 -1
index 3a1d960..4739f36 100644
@@ -215,7 +215,7 @@ CFLAGS += -Wall -Wstrict-prototypes
 # Clang complains about macros that expand to 'if ( ( foo == bar ) ) ...'
 # and is over-zealous with the printf format lint
 # and is a bit too fierce about unused return values
-CFLAGS-$(clang) += -Wno-parentheses -Wno-format -Wno-unused-value
+CFLAGS-$(clang) += -Wno-parentheses -Wno-unused-value
 
 $(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
 $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
tools/libxl/libxl_internal.c +16 -5
index d288215..f492dae 100644
@@ -20,14 +20,25 @@
 void libxl__alloc_failed(libxl_ctx *ctx, const char *func,
                          size_t nmemb, size_t size) {
 #define M "libxl: FATAL ERROR: memory allocation failure"
-#define L (size ? M " (%s, %lu x %lu)\n" : M " (%s)\n"), \
-          func, (unsigned long)nmemb, (unsigned long)size
-    libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0,0, func, INVALID_DOMID, L);
-    fprintf(stderr, L);
+#define M_SIZE M " (%s, %lu x %lu)\n"
+#define M_NSIZE M " (%s)\n"
+    if (size) {
+       libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0, 0, func, INVALID_DOMID,
+                  M_SIZE, func, (unsigned long)nmemb, (unsigned long)size);
+       fprintf(stderr, M_SIZE, func, (unsigned long)nmemb,
+               (unsigned long)size);
+    } else {
+       libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0, 0, func, INVALID_DOMID,
+                  M_NSIZE, func);
+       fprintf(stderr, M_NSIZE, func);
+
+    }
+
     fflush(stderr);
     _exit(-1);
+#undef M_NSIZE
+#undef M_SIZE
 #undef M
-#undef L
 }
 
 void libxl__ptr_add(libxl__gc *gc, void *ptr)
tools/misc/xenpm.c +8 -5
index a2edee5..ded40b9 100644
@@ -93,13 +93,16 @@ static void parse_cpuid(const char *arg, int *cpuid)
 static void parse_cpuid_and_int(int argc, char *argv[],
                                 int *cpuid, int *val, const char *what)
 {
-    if ( argc > 1 )
-        parse_cpuid(argv[0], cpuid);
+    if ( argc == 0 )
+    {
+         fprintf(stderr, "Missing %s\n", what);
+         exit(EINVAL);
+    }
 
-    if ( argc == 0 || sscanf(argv[argc > 1], "%d", val) != 1 )
+    parse_cpuid(argv[0], cpuid);
+    if ( sscanf(argv[1], "%d", val) != 1 )
     {
-        fprintf(stderr, argc ? "Invalid %s '%s'\n" : "Missing %s\n",
-                what, argv[argc > 1]);
+        fprintf(stderr, "Invalid %s '%s'\n", what, argv[1]);
         exit(EINVAL);
     }
 }
xen/arch/x86/cpu/mcheck/mce.c +2 -3
index 2695b0c..d091bfa 100644
@@ -595,9 +595,8 @@ int show_mca_info(int inited, struct cpuinfo_x86 *c)
             [mcheck_intel] = "Intel"
         };
 
-        snprintf(prefix, ARRAY_SIZE(prefix),
-                 g_type != mcheck_unset ? XENLOG_WARNING "CPU%i: "
-                 : XENLOG_INFO,
+        snprintf(prefix, ARRAY_SIZE(prefix), "%sCPU%i: ",
+                 g_type != mcheck_unset ? XENLOG_WARNING : XENLOG_INFO,
                  smp_processor_id());
         BUG_ON(inited >= ARRAY_SIZE(type_str));
         switch (inited) {
Signature · 7 lines
2.10.1 (Apple Git-78)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] build/printf: fix incorrect format specifiers

Quoted 35 lines · Roger Pau Monne

The following incorrect format specifiers and incorrect number of parameters passed to printf like functions are reported by clang:

mce.c:601:18: error: data argument not used by format string [-Werror,-Wformat-extra-args]

                 smp_processor_id());
                 ^

xenpm.c:102:23: error: data argument not used by format string [-Werror,-Wformat-extra-args]

                what, argv[argc > 1]);
                      ^

libxl_internal.c:25:69: error: data argument not used by format string

      [-Werror,-Wformat-extra-args]
    libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0,0, func, INVALID_DOMID, L);
                                                                    ^

libxl_internal.c:24:17: note: expanded from macro 'L'
func, (unsigned long)nmemb, (unsigned long)size
^
libxl_internal.c:26:21: error: data argument not used by format string

      [-Werror,-Wformat-extra-args]
    fprintf(stderr, L);
                    ^

libxl_internal.c:24:17: note: expanded from macro 'L'
func, (unsigned long)nmemb, (unsigned long)size
^

This patch contains the fixes for them and enabled -Wformat for clang.

---
NB: FWIW, there's a way to disable extra arguments checks (-Wno-format-extra-args), that would prevent us from having to apply some of the changes here. However, given that there are not that many occurrences, I would rather leave the full checks of Wformat enabled.

Quoted 10 lines

NB2: this has only been tested with a FreeBSD clang build (3.8.0), and only against the components that build on FreeBSD (ie: no qemu-trad, and certainly no blktap).
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Christoph Egger <[email protected]>
Cc: Liu Jinsong <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

+1 for all the checking. It all leads to better code.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v2 2/2] build/printf: fix incorrect format specifiers

In reply to Roger Pau Monne

xen/arch/x86/cpu/mcheck/mce.c int show_mca_info(int inited, struct cpuinfo_x86 *c) · line 600

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:34, <[email protected]> wrote:
xen/arch/x86/cpu/mcheck/mce.c +2 -3
@@ -595,9 +595,8 @@ int show_mca_info(int inited, struct cpuinfo_x86 *c)
             [mcheck_intel] = "Intel"
         };
 
-        snprintf(prefix, ARRAY_SIZE(prefix),
-                 g_type != mcheck_unset ? XENLOG_WARNING "CPU%i: "
-                 : XENLOG_INFO,
+        snprintf(prefix, ARRAY_SIZE(prefix), "%sCPU%i: ",
+                 g_type != mcheck_unset ? XENLOG_WARNING : XENLOG_INFO,
                  smp_processor_id());

Should I end up committing this, I'll take the liberty of using %u instead of %i here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v2 2/2] build/printf: fix incorrect format specifiers

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:34, <[email protected]> wrote:
xen/arch/x86/cpu/mcheck/mce.c +0 -0
@@ -595,9 +595,8 @@ int show_mca_info(int inited, struct cpuinfo_x86 *c)
             [mcheck_intel] = "Intel"
         };
 
Quoted 9 lines

xen/arch/x86/cpu/mcheck/mce.c int show_mca_info(int inited, struct cpuinfo_x86 *c) · line 600

Quoted 6 lines
xen/arch/x86/cpu/mcheck/mce.c +2 -3
-        snprintf(prefix, ARRAY_SIZE(prefix),
-                 g_type != mcheck_unset ? XENLOG_WARNING "CPU%i: "
-                 : XENLOG_INFO,
+        snprintf(prefix, ARRAY_SIZE(prefix), "%sCPU%i: ",
+                 g_type != mcheck_unset ? XENLOG_WARNING : XENLOG_INFO,
                  smp_processor_id());

Should I end up committing this, I'll take the liberty of using %u instead of %i here.

Done, I will be sending a new version shortly.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel