qemu-rust.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Zhao Liu <zhao1.liu@intel.com>,
	Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org
Subject: Re: [PATCH] rust/qemu-macros: Convert bit value to u8 within #[property]
Date: Tue, 14 Oct 2025 17:09:34 +0200	[thread overview]
Message-ID: <0d7741c3-2ffb-4076-8baa-864a83197805@redhat.com> (raw)
In-Reply-To: <20251014150251.2473680-1-zhao1.liu@intel.com>

On 10/14/25 17:02, Zhao Liu wrote:
> diff --git a/rust/qemu-macros/src/lib.rs b/rust/qemu-macros/src/lib.rs
> index 3e21b67b4719..2a7454da2416 100644
> --- a/rust/qemu-macros/src/lib.rs
> +++ b/rust/qemu-macros/src/lib.rs
> @@ -271,7 +271,10 @@ macro_rules! str_to_c_str {
>                   name: ::std::ffi::CStr::as_ptr(#prop_name),
>                   info: #qdev_prop,
>                   offset: ::core::mem::offset_of!(#name, #field_name) as isize,
> -                bitnr: #bitnr,
> +                bitnr: {
> +                    const { assert!(#bitnr >= 0 && #bitnr <= u8::MAX as _, "bit exceeds u8 range"); }

The check for the upper limit must be "#bitnr < $field_ty::BITS as _", 
for example rejecting 32 for an u32 field.

Also, the tests need to be updated.

Thanks for remembering about this change!

Paolo

> +                    #bitnr as u8
> +                },
>                   set_default: #set_default,
>                   defval: ::hwcore::bindings::Property__bindgen_ty_1 { u: #defval as u64 },
>                   ..::common::Zeroable::ZERO



  reply	other threads:[~2025-10-14 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 15:02 [PATCH] rust/qemu-macros: Convert bit value to u8 within #[property] Zhao Liu
2025-10-14 15:09 ` Paolo Bonzini [this message]
2025-10-14 15:39   ` Zhao Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d7741c3-2ffb-4076-8baa-864a83197805@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).