From: Paolo Bonzini <pbonzini@redhat.com>
To: Xi Wang <xi.wang@gmail.com>
Cc: Blue Swirl <blauwirbel@gmail.com>,
qemu-devel@nongnu.org, Jia Liu <proljc@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] target-or32: fix masking in openrisc_pic_cpu_handler()
Date: Sat, 27 Jul 2013 01:07:32 +0200 [thread overview]
Message-ID: <51F30134.7070300@redhat.com> (raw)
In-Reply-To: <1358870255-32335-1-git-send-email-xi.wang@gmail.com>
Il 22/01/2013 16:57, Xi Wang ha scritto:
> A correct mask should be `x & (1 << i)', rather than `x && (1 << i)'.
>
> Also, in C99 signed shift (1 << 31) is undefined behavior, since the
> result exceeds INT_MAX; use 1U instead.
>
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> ---
> hw/openrisc_pic.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/hw/openrisc_pic.c b/hw/openrisc_pic.c
> index aaeb9a9..4f6d5a0 100644
> --- a/hw/openrisc_pic.c
> +++ b/hw/openrisc_pic.c
> @@ -26,12 +26,14 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level)
> {
> OpenRISCCPU *cpu = (OpenRISCCPU *)opaque;
> int i;
> - uint32_t irq_bit = 1 << irq;
> + uint32_t irq_bit;
>
> if (irq > 31 || irq < 0) {
> return;
> }
>
> + irq_bit = 1U << irq;
> +
> if (level) {
> cpu->env.picsr |= irq_bit;
> } else {
> @@ -39,11 +41,11 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level)
> }
>
> for (i = 0; i < 32; i++) {
> - if ((cpu->env.picsr && (1 << i)) && (cpu->env.picmr && (1 << i))) {
> + if ((cpu->env.picsr & (1U << i)) && (cpu->env.picmr & (1U << i))) {
> cpu_interrupt(&cpu->env, CPU_INTERRUPT_HARD);
> } else {
> cpu_reset_interrupt(&cpu->env, CPU_INTERRUPT_HARD);
> - cpu->env.picsr &= ~(1 << i);
> + cpu->env.picsr &= ~(1U << i);
> }
> }
> }
>
Ping.
Paolo
next parent reply other threads:[~2013-07-26 23:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1358870255-32335-1-git-send-email-xi.wang@gmail.com>
2013-07-26 23:07 ` Paolo Bonzini [this message]
2013-07-28 12:48 ` [Qemu-devel] [PATCH] target-or32: fix masking in openrisc_pic_cpu_handler() Jia 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=51F30134.7070300@redhat.com \
--to=pbonzini@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=proljc@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=xi.wang@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.