From: Laszlo Ersek <lersek@redhat.com>
To: Hao Wu <hao.a.wu@intel.com>, edk2-devel@lists.01.org
Cc: Jiewen Yao <jiewen.yao@intel.com>
Subject: Re: [PATCH] MdeModulePkg/PciHostBridgeDxe: Make bitwise operands of the same size
Date: Thu, 8 Jun 2017 22:40:23 +0200 [thread overview]
Message-ID: <ee911cc4-567d-79e8-03df-4587bde3e3d3@redhat.com> (raw)
In-Reply-To: <20170608082230.13984-1-hao.a.wu@intel.com>
On 06/08/17 10:22, Hao Wu wrote:
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
> MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> index a0e7e5b6f2..8e4f032772 100644
> --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> @@ -1349,7 +1349,7 @@ RootBridgeIoAllocateBuffer (
> //
> // Clear DUAL_ADDRESS_CYCLE
> //
> - Attributes &= ~EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE;
> + Attributes &= ~((UINT64) EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE);
> }
> Status = mIoMmuProtocol->AllocateBuffer (
> mIoMmuProtocol,
>
* Side remark: my general preference would be to #define the macros
immediately with the right type, which can often be deduced from the
intended use. So in this case, we could have one of:
#define EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE ((UINT64)0x8000)
or
#define EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000ULL
* In particular, all macros that are bitmasks should be suffixed with
"U" minimally, or cast to UINT32. For example,
#define BIT26 0x04000000
should actually be
#define BIT26 0x04000000U
or else
#define BIT26 ((UINT32)0x04000000)
This is because bitmasks are often bitwise-negated (ex.: ~BIT26), and
given that the original is of type "int", the negated one is also an
"int", with negative value. If, on top, you shift that left, for example
(~BIT26 << 1)
you immediately have undefined behavior at your hands.
* I think the most curious example might be
#define BIT31 0x80000000
Namely, *unlike* the other BIT{N} macros, with N<=30, this has type
"unsigned int" (--> UINT32) automatically. The reason is that the 0x
prefix enables the C language to include unsigned types when trying to
determine the type of the integer constant. Given that this one doesn't
fit in an "int" (INT32), the language picks the next type on the
"ladder", and due to the 0x prefix, "unsigned int" comes next on the ladder.
* Here's a good way to think about integer constant prefixes and suffixes:
- normally the "ladder" only contains signed types -- int, long, long long
- if you add a 0x -- hex -- or 0 -- octal -- prefix, then you *insert*
unsigned types to the ladder. int, unsigned, long, unsigned long, long
long, unsigned long long.
- if you add the "u" suffix, then you *exclude* the signed types from
the ladder, and force the unsigned types (regardless of 0 or 0x prefix).
So you get unsigned, unsigned long, unsigned long long.
- the "l" and "ll" suffixes are orthogonal to signedness. They determine
the "height" of the first step on the ladder, where the search starts.
* Anyway, the patch seems good.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
next prev parent reply other threads:[~2017-06-08 20:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-08 8:22 [PATCH] MdeModulePkg/PciHostBridgeDxe: Make bitwise operands of the same size Hao Wu
2017-06-08 8:37 ` Yao, Jiewen
2017-06-08 20:40 ` Laszlo Ersek [this message]
2017-06-09 1:13 ` Wu, Hao A
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-list 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=ee911cc4-567d-79e8-03df-4587bde3e3d3@redhat.com \
--to=devel@edk2.groups.io \
/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