From: Roland Dreier <rdreier@cisco.com>
To: linux-kernel@vger.kernel.org
Subject: C language lawyers needed
Date: Wed, 27 Aug 2008 14:43:05 -0700 [thread overview]
Message-ID: <adaod3ef82e.fsf@cisco.com> (raw)
Can anyone explain why building the current kernel gives
drivers/net/mlx4/mcg.c: In function 'mlx4_multicast_attach':
drivers/net/mlx4/mcg.c:217: warning: integer overflow in expression
(with gcc (Ubuntu 4.3.1-9ubuntu1) 4.3.1 on x86-64), while the patch
below gets rid of the warning? I can't see what is overflowing in the
expression that is warned out.
MGM_BLCK_LB_BIT is 30, and 1 << 30 is not negative or close to
overflowing. And MGM_QPN_MASK is 0x00FFFFFF, which is also nowhere near
to integer overflow.
A fairly small test case that I don't understand either is:
unsigned foo(int x)
{
return (((x & 0xffffff) | (1 << 30)) & 0xff000000) >> 24;
}
just running "gcc -c" (ie no extra warnings enabled) on that produces
the same:
b.c: In function 'foo':
b.c:3: warning: integer overflow in expression
I'm sure there's some promotion rule or something that makes sense of
this, but it's a mystery to me...
Thanks,
Roland
diff --git a/drivers/net/mlx4/mcg.c b/drivers/net/mlx4/mcg.c
index c83f88c..6af5c6d 100644
--- a/drivers/net/mlx4/mcg.c
+++ b/drivers/net/mlx4/mcg.c
@@ -215,7 +215,7 @@ int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
if (block_mcast_loopback)
mgm->qp[members_count++] = cpu_to_be32((qp->qpn & MGM_QPN_MASK) |
- (1 << MGM_BLCK_LB_BIT));
+ (1u << MGM_BLCK_LB_BIT));
else
mgm->qp[members_count++] = cpu_to_be32(qp->qpn & MGM_QPN_MASK);
next reply other threads:[~2008-08-27 21:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-27 21:43 Roland Dreier [this message]
2008-08-27 22:00 ` C language lawyers needed H. Peter Anvin
2008-08-27 22:17 ` Al Viro
2008-08-27 22:18 ` H. Peter Anvin
2008-08-27 22:06 ` Al Viro
2008-08-27 23:02 ` Roland Dreier
2008-09-01 6:25 ` Roland Dreier
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=adaod3ef82e.fsf@cisco.com \
--to=rdreier@cisco.com \
--cc=linux-kernel@vger.kernel.org \
/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.