Skip to content

Commit c23034a

Browse files
author
Lv Zheng
committed
Hardware: Fix a regression caused by bit width mask generation
A regression was reported to the shift offset >= width of type. This patch fixes this issue. BZ 1270. Lv Zheng. Link: https://bugs.acpica.org/show_bug.cgi?id=1270 Reported-by: Sascha Wildner <[email protected]> Signed-off-by: Lv Zheng <[email protected]>
1 parent b2294ca commit c23034a

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

source/components/executer/exfldio.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,20 +1018,9 @@ AcpiExInsertIntoField (
10181018

10191019
AccessBitWidth = ACPI_MUL_8 (ObjDesc->CommonField.AccessByteWidth);
10201020

1021-
/*
1022-
* Create the bitmasks used for bit insertion.
1023-
* Note: This if/else is used to bypass compiler differences with the
1024-
* shift operator
1025-
*/
1026-
if (AccessBitWidth == ACPI_INTEGER_BIT_SIZE)
1027-
{
1028-
WidthMask = ACPI_UINT64_MAX;
1029-
}
1030-
else
1031-
{
1032-
WidthMask = ACPI_MASK_BITS_ABOVE (AccessBitWidth);
1033-
}
1021+
/* Create the bitmasks used for bit insertion */
10341022

1023+
WidthMask = ACPI_MASK_BITS_ABOVE_64 (AccessBitWidth);
10351024
Mask = WidthMask &
10361025
ACPI_MASK_BITS_BELOW (ObjDesc->CommonField.StartFieldBitOffset);
10371026

source/components/hardware/hwregs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ AcpiHwRead (
315315
}
316316

317317
ACPI_SET_BITS (Value, Index * AccessWidth,
318-
(1 << AccessWidth) - 1, Value32);
318+
ACPI_MASK_BITS_ABOVE_32 (AccessWidth), Value32);
319319

320320
BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth;
321321
Index++;
@@ -386,7 +386,7 @@ AcpiHwWrite (
386386
while (BitWidth)
387387
{
388388
NewValue32 = ACPI_GET_BITS (&Value, Index * AccessWidth,
389-
(1 << AccessWidth) - 1);
389+
ACPI_MASK_BITS_ABOVE_32 (AccessWidth));
390390

391391
if (BitOffset > AccessWidth)
392392
{

source/include/acmacros.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,21 @@
345345
* Bit positions start at zero.
346346
* MASK_BITS_ABOVE creates a mask starting AT the position and above
347347
* MASK_BITS_BELOW creates a mask starting one bit BELOW the position
348+
* MASK_BITS_ABOVE/BELOW accpets a bit offset to create a mask
349+
* MASK_BITS_ABOVE/BELOW_32/64 accpets a bit width to create a mask
350+
* Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
351+
* differences with the shift operator
348352
*/
349353
#define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_UINT64_MAX) << ((UINT32) (position))))
350354
#define ACPI_MASK_BITS_BELOW(position) ((ACPI_UINT64_MAX) << ((UINT32) (position)))
355+
#define ACPI_MASK_BITS_ABOVE_32(width) ((UINT32) ACPI_MASK_BITS_ABOVE(width))
356+
#define ACPI_MASK_BITS_BELOW_32(width) ((UINT32) ACPI_MASK_BITS_BELOW(width))
357+
#define ACPI_MASK_BITS_ABOVE_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
358+
ACPI_UINT64_MAX : \
359+
ACPI_MASK_BITS_ABOVE(width))
360+
#define ACPI_MASK_BITS_BELOW_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
361+
(UINT64) 0 : \
362+
ACPI_MASK_BITS_BELOW(width))
351363

352364
/* Bitfields within ACPI registers */
353365

0 commit comments

Comments
 (0)