Skip to content

Commit 5c88a9c

Browse files
committed
cxl/core/regs: Fix usage of map->reg_type in cxl_decode_regblock() before assigned
In the error path, map->reg_type is being used for kernel warning before its value is setup. Found by code inspection. Exposure to user is wrong reg_type being emitted via kernel log. Use a local var for reg_type and retrieve value for usage. Fixes: 6c7f4f1 ("cxl/core/regs: Make cxl_map_{component, device}_regs() device generic") Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Signed-off-by: Dave Jiang <[email protected]>
1 parent b7c59b0 commit 5c88a9c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/cxl/core/regs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,19 @@ EXPORT_SYMBOL_NS_GPL(cxl_map_device_regs, CXL);
271271
static bool cxl_decode_regblock(struct pci_dev *pdev, u32 reg_lo, u32 reg_hi,
272272
struct cxl_register_map *map)
273273
{
274+
u8 reg_type = FIELD_GET(CXL_DVSEC_REG_LOCATOR_BLOCK_ID_MASK, reg_lo);
274275
int bar = FIELD_GET(CXL_DVSEC_REG_LOCATOR_BIR_MASK, reg_lo);
275276
u64 offset = ((u64)reg_hi << 32) |
276277
(reg_lo & CXL_DVSEC_REG_LOCATOR_BLOCK_OFF_LOW_MASK);
277278

278279
if (offset > pci_resource_len(pdev, bar)) {
279280
dev_warn(&pdev->dev,
280281
"BAR%d: %pr: too small (offset: %pa, type: %d)\n", bar,
281-
&pdev->resource[bar], &offset, map->reg_type);
282+
&pdev->resource[bar], &offset, reg_type);
282283
return false;
283284
}
284285

285-
map->reg_type = FIELD_GET(CXL_DVSEC_REG_LOCATOR_BLOCK_ID_MASK, reg_lo);
286+
map->reg_type = reg_type;
286287
map->resource = pci_resource_start(pdev, bar) + offset;
287288
map->max_size = pci_resource_len(pdev, bar) - offset;
288289
return true;

0 commit comments

Comments
 (0)