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

RE: [PATCH 2/2] Arm32: tidy the memset() macro


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <Wei.Chen@xxxxxxx>
  • Date: Fri, 19 Aug 2022 07:59:59 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=8+ulrW9YHHzaOanOWv0Pi1jye8WvHvzvc2I+Y6apo8g=; b=Nxs6SmjKkA8+1fI+++imCvzl4r9S9YWqjkPYamXzaY5xDOUVruuvKy5ETPzTbNtinZ326UEK/JyqXXG+mhLpDiOBAfocYyzXL1U2Kgc0vvZM91nVbqIMDy/z3vwU2MneCmYPJN3aANGKmsZRCpxAMhl/gyLGPW2X40nSoYLW9Vna5DHsYjvcLFrKhi5lR+TRWUjhz+STu3h/Czmmf9FTdCoM+TJ15y0p+RIBswTEdZ8fW+1al3dj0Lh0ewNQ8N9d5QqrgvFqGDIYI7y9DlD1hTAne9Kidp8hiT5JDlZ0I26x1wfFxZzQnS1M1vkN5/f7HOM/Ok8W0sA0pDOMF2Msqw==
  • 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=8+ulrW9YHHzaOanOWv0Pi1jye8WvHvzvc2I+Y6apo8g=; b=OA39WTp2Ikg6gkgJrxdz8Kd+05B55p92gXThJPr9HidHmVCy976YuQWnRczHf8RnPB9o0Oiib7VnAeOJUk7FmlgNpqz7JhXAqu0mE9XrZ4WvrwD92FwNotV8ZOZhStM8uFYhO/Ym9VXy/+GU4DxAW3/tsBzGc47tAnTnL5F+tZqSVjCnoxIZ8IE/Pts+rNSRp441Rqy2++O0nEYDhA1S/TfCav/WKV473TBNjrxTvAN8n4gtgIU8SoOCVf+xaW4WcJnIvas+MnpVRZo8a1Cznv5o9B4OvqAvcgMbKBUpt5RFVGMhDOamX3MIdhvOwMicd+YNsd4UPJ9HiYRbIWmcXw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SessV6iYulDqtjNVvujWu6iMQdJmjawT/Hw4S6omXRIlnRdjX05T0LCLGbuXypaIug3P+uPUdD9ZjeHzAAuAyWfzEp+nauGb4vMT6BPZE7aG7CLIQkM1ZmB3yVv1ElwL8TZkUYE80M4+m2gJwO4G5Dlua3yPZEIhcBDCnqaqBMvAFptOnjIiBSfjGwPAxrRingkWEmb1eMnW3RyecQBOMcIcBpuXLMvEvUvb6MXxwp7Bp9nnr6X0JC6uBnLgW0oHY5jHJc7YEETbr1idEZIRgfqekpDeaazXYQ+HotIlEsGScR2LbyE6vGRSwnD2INfBuFmjSePlnpMr3A6SXhUPGg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E67rEQe3XkHl63wxVcjVNzu390SQFwU0Wpkf3kxBSum19KibHDtjQrSqMn0u/aTOVLJVY3T3xPaYcoIu05MCWtZDrgujJX6dz1WXB8KRmY+vpGY4vUHzf1y4uKz2N2prAWVj+6jAsKrX0dD9cihFWQmO3El27eAQhy52atL5VgXl80Od0ZL27SBdZaz95jxt7EhqhWoIG/tmJx+nwqKmTOmhUu+cBMZ8123Y8QT0n+oTMy53u2CBwt7Rjh/2Ay5Pt+t56pfoQ+fWUZGmbezlMcavsncxdui1oO/GWn+DiROpu+DDDjWIG9yGmCxo6cZh/wY58eLWOcCIIY2CUeXLTw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Fri, 19 Aug 2022 08:00:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYs6BtEnYIw9a2QEK+U+CB1vg/Xq21221A
  • Thread-topic: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx> On Behalf Of Jan
> Beulich
> Sent: 2022年8月19日 15:50
> To: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Julien Grall <julien@xxxxxxx>; Stefano Stabellini
> <sstabellini@xxxxxxxxxx>; Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>;
> Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
> Subject: [PATCH 2/2] Arm32: tidy the memset() macro
> 
> - add parentheses where they were missing (MISRA)
> - make sure to evaluate also v exactly once (MISRA)
> - remove excess parentheses
> - rename local variables to not have leading underscores
> - apply Xen coding style
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> I wonder whether "if ( n_ )" is really helpful: It's extra code in all
> callers passing a non-constant size, just to cover a pretty rare case
> which memset() is required to deal with correctly anyway, and which

What rare case we need to use n_ that can make memset happy? As your
comment, I read the code again, but it seems to work fine without n_.

Cheers,
Wei Chen

> __memzero() also handles quite fine from all I can tell.
> 
> --- a/xen/arch/arm/include/asm/string.h
> +++ b/xen/arch/arm/include/asm/string.h
> @@ -28,17 +28,19 @@
> 
>  void __memzero(void *ptr, size_t n);
> 
> -#define memset(p, v, n)                                                 \
> -        ({                                                              \
> -                void *__p = (p); size_t __n = n;                        \
> -                if ((__n) != 0) {                                       \
> -                        if (__builtin_constant_p((v)) && (v) == 0)      \
> -                                __memzero((__p),(__n));                 \
> -                        else                                            \
> -                                memset((__p),(v),(__n));                \
> -                }                                                       \
> -                (__p);                                                  \
> -        })
> +#define memset(p, v, n)                                 \
> +    ({                                                  \
> +        void *p_ = (p); size_t n_ = (n);                \
> +        typeof(v) v_ = (v);                             \
> +        if ( n_ )                                       \
> +        {                                               \
> +            if ( __builtin_constant_p(v) && !v_ )       \
> +                __memzero(p_, n_);                      \
> +            else                                        \
> +                memset(p_, v_, n_);                     \
> +        }                                               \
> +        p_;                                             \
> +    })
> 
>  #endif
> 
> 


 


Rackspace

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