[PATCH 1/3] hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()

Philippe Mathieu-Daudé posted 3 patches 1 week ago
There is a newer version of this series
[PATCH 1/3] hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()
Posted by Philippe Mathieu-Daudé 1 week ago
Replace magic 8 by BITS_PER_BYTE, use MAKE_64BIT_MASK()
instead of open coding it.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/xen/xen-hvm-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c
index 52e2cce397a..258014370e1 100644
--- a/hw/xen/xen-hvm-common.c
+++ b/hw/xen/xen-hvm-common.c
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/bitops.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "exec/target_long.h"
@@ -448,12 +449,14 @@ static void cpu_ioreq_config(XenIOState *state, ioreq_t *req)
 
 static void handle_ioreq(XenIOState *state, ioreq_t *req)
 {
+    size_t req_size_bits = req->size * BITS_PER_BYTE;
+
     trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr,
                        req->addr, req->data, req->count, req->size);
 
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
             (req->size < sizeof (target_ulong))) {
-        req->data &= ((target_ulong) 1 << (8 * req->size)) - 1;
+        req->data &= MAKE_64BIT_MASK(0, req_size_bits);
     }
 
     if (req->dir == IOREQ_WRITE)
-- 
2.51.0


Re: [PATCH 1/3] hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()
Posted by Edgar E. Iglesias 1 day, 9 hours ago
On Wed, Oct 22, 2025 at 04:01:11PM +0200, Philippe Mathieu-Daudé wrote:
> Replace magic 8 by BITS_PER_BYTE, use MAKE_64BIT_MASK()
> instead of open coding it.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com>



> ---
>  hw/xen/xen-hvm-common.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c
> index 52e2cce397a..258014370e1 100644
> --- a/hw/xen/xen-hvm-common.c
> +++ b/hw/xen/xen-hvm-common.c
> @@ -1,5 +1,6 @@
>  #include "qemu/osdep.h"
>  #include "qemu/units.h"
> +#include "qemu/bitops.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "exec/target_long.h"
> @@ -448,12 +449,14 @@ static void cpu_ioreq_config(XenIOState *state, ioreq_t *req)
>  
>  static void handle_ioreq(XenIOState *state, ioreq_t *req)
>  {
> +    size_t req_size_bits = req->size * BITS_PER_BYTE;
> +
>      trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr,
>                         req->addr, req->data, req->count, req->size);
>  
>      if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
>              (req->size < sizeof (target_ulong))) {
> -        req->data &= ((target_ulong) 1 << (8 * req->size)) - 1;
> +        req->data &= MAKE_64BIT_MASK(0, req_size_bits);
>      }
>  
>      if (req->dir == IOREQ_WRITE)
> -- 
> 2.51.0
> 
Re: [PATCH 1/3] hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()
Posted by Pierrick Bouvier 1 day, 13 hours ago
On 2025-10-22 16:01, Philippe Mathieu-Daudé wrote:
> Replace magic 8 by BITS_PER_BYTE, use MAKE_64BIT_MASK()
> instead of open coding it.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/xen/xen-hvm-common.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>