[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH][for-4.19 v2 8/8] xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 17 Oct 2023 08:09:39 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GpuBrt9CJvySavkfGfUcB7OReHxmvuzZluMFYX8FOus=; b=UlSDhihfDEDuBfj2pjr6ffKhKkI/GxBp5703rE4hkdEAQdQMxYqBZ5dejz+cTrZGsxf9A/6kM7attRzS4/sBHy357A4S6rpv1L8xkV6P0RTMof3nbCmGD+6MFcGrPy3FH1z9sTb0zyzyesGsz2GvtER4HEkINCRwYnVGocj8IoAxW8+N62oo/Z7boPgx43s7Fr3t70cGt6LTMxBGrqw0Sf7TlZIXuhuXx/RvpP3lKXz98Cq39N0CTe6JMqYG5EWZVjJvKLeidBtBZ6e45mNAG3dAlKm0L/LGJpZffyRVtp9Qkgtmt2oMoudMRMc1MYUAxHf/S8ye68T8qY9l1fGfCg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=REYGKUaCvwYzvL4fwpTAwYfjtdDkcB76iwqJLcM8GKVFPga8VF8ukNf2srLdXNOMxG5Hdn339+TLv4bVjrhYG2ESXXgzFt0MUEKJdLzUuz7mUDxRfxQoZUloOQmplkZSdS00JvApZ8lVqsRHH+R5rqEMXlCHpRNPoh06imT22SrmA6xIgWe3Mv1mXT74ke4rUEb+Mt2u37DH4b1fGt27RLKVshYXS8rLFbMonWm0jqeHoB6sLboY9pNzKsRAxLTT60rJpMQqueSrhiTTBQxpDpTFpWnQ/NflkDJgWIS8t8N2152z6eMm096Hepds8dJ2jjl50QemVjBJfp+SqC+pSw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: sstabellini@xxxxxxxxxx, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger.pau@xxxxxxxxxx, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 17 Oct 2023 06:09:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.10.2023 17:28, Nicola Vetrini wrote:
> BUILD_BUG_ON is the preferred way to induce a build error
> upon statically determined incorrect conditions.
> 
> This also fixes a MISRA C:2012 Rule 10.1 violation in the
> previous formulation.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>

Hmm, looking back it's indeed not clear why I didn't use BUILD_BUG_ON() right
away. Perhaps just to avoid inline functions when things can be done without.
And/or because originally the macros were intended to be usable in function
bodies, not (just) at file scope. However, ...

> --- a/xen/include/xen/compat.h
> +++ b/xen/include/xen/compat.h
> @@ -151,12 +151,20 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
>      return x == c; \
>  }
>  
> -#define CHECK_SIZE(name) \
> -    typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \
> -                                         sizeof(compat_ ## name ## _t)) * 2]
> +#define CHECK_SIZE(name)                                  \
> +static inline void __maybe_unused CHECK_SIZE_##name(void) \
> +{                                                         \
> +    typedef int CHECK_NAME(name, S)[1];                   \

... what's this and ...

> +    BUILD_BUG_ON(sizeof(xen_ ## name ## _t) !=            \
> +                 sizeof(compat_ ## name ## _t));          \
> +}
>  #define CHECK_SIZE_(k, n) \
> -    typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \
> -                                          sizeof(k compat_ ## n)) * 2]
> +static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \
> +{                                                          \
> +    typedef int CHECK_NAME_(k, n, S)[1];                   \

... this needed for? The types aren't used anywhere afaict.

Jan

> +    BUILD_BUG_ON(sizeof(k xen_ ## n) !=                    \
> +                 sizeof(k compat_ ## n));                  \
> +}
>  
>  #define CHECK_FIELD_COMMON(name, t, f) \
>  static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t 
> *c) \




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.