Skip to content

Commit b0c5bc5

Browse files
lrq-maxgregkh
authored andcommitted
PCI: mediatek: Fix operator precedence in PCIE_FTS_NUM_L0 macro
[ Upstream commit 282305d ] The original PCIE_FTS_NUM_L0(x) macro was buggy due to improper operator precedence, where ((x) & 0xff << 8) was evaluated as ((x) & 0xff00). Instead of just fixing the parentheses, use the standard FIELD_PREP() macro. This makes the code more robust by automatically handling masks and shifts, while also adding compile-time type and range checking to ensure the value fits within PCIE_FTS_NUM_MASK. Fixes: 637cfac ("PCI: mediatek: Add MediaTek PCIe host controller support") Signed-off-by: Li RongQing <lirongqing@baidu.com> [mani: added the bitfield header include spotted by Sashiko] Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Link: https://patch.msgid.link/20260515005552.2343-1-lirongqing@baidu.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4bc7e5c commit b0c5bc5

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/pci/controller/pcie-mediatek.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Honghui Zhang <honghui.zhang@mediatek.com>
88
*/
99

10+
#include <linux/bitfield.h>
1011
#include <linux/clk.h>
1112
#include <linux/delay.h>
1213
#include <linux/iopoll.h>
@@ -60,7 +61,7 @@
6061
/* MediaTek specific configuration registers */
6162
#define PCIE_FTS_NUM 0x70c
6263
#define PCIE_FTS_NUM_MASK GENMASK(15, 8)
63-
#define PCIE_FTS_NUM_L0(x) ((x) & 0xff << 8)
64+
#define PCIE_FTS_NUM_L0(x) FIELD_PREP(PCIE_FTS_NUM_MASK, x)
6465

6566
#define PCIE_FC_CREDIT 0x73c
6667
#define PCIE_FC_CREDIT_MASK (GENMASK(31, 31) | GENMASK(28, 16))

0 commit comments

Comments
 (0)