Skip to content

Commit 293f532

Browse files
diandersAbhinav Kumar
authored andcommitted
drm/msm: Avoid NULL dereference in msm_disp_state_print_regs()
If the allocation in msm_disp_state_dump_regs() failed then `block->state` can be NULL. The msm_disp_state_print_regs() function _does_ have code to try to handle it with: if (*reg) dump_addr = *reg; ...but since "dump_addr" is initialized to NULL the above is actually a noop. The code then goes on to dereference `dump_addr`. Make the function print "Registers not stored" when it sees a NULL to solve this. Since we're touching the code, fix msm_disp_state_print_regs() not to pointlessly take a double-pointer and properly mark the pointer as `const`. Fixes: 9865948 ("drm/msm: add support to take dpu snapshot") Signed-off-by: Douglas Anderson <[email protected]> Reviewed-by: Abhinav Kumar <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/619657/ Link: https://lore.kernel.org/r/20241014093605.1.Ia1217cecec9ef09eb3c6d125360cc6c8574b0e73@changeid Signed-off-by: Abhinav Kumar <[email protected]>
1 parent 358b762 commit 293f532

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ static void msm_disp_state_dump_regs(u32 **reg, u32 aligned_len, void __iomem *b
4848
}
4949
}
5050

51-
static void msm_disp_state_print_regs(u32 **reg, u32 len, void __iomem *base_addr,
52-
struct drm_printer *p)
51+
static void msm_disp_state_print_regs(const u32 *dump_addr, u32 len,
52+
void __iomem *base_addr, struct drm_printer *p)
5353
{
5454
int i;
55-
u32 *dump_addr = NULL;
5655
void __iomem *addr;
5756
u32 num_rows;
5857

58+
if (!dump_addr) {
59+
drm_printf(p, "Registers not stored\n");
60+
return;
61+
}
62+
5963
addr = base_addr;
6064
num_rows = len / REG_DUMP_ALIGN;
6165

62-
if (*reg)
63-
dump_addr = *reg;
64-
6566
for (i = 0; i < num_rows; i++) {
6667
drm_printf(p, "0x%lx : %08x %08x %08x %08x\n",
6768
(unsigned long)(addr - base_addr),
@@ -89,7 +90,7 @@ void msm_disp_state_print(struct msm_disp_state *state, struct drm_printer *p)
8990

9091
list_for_each_entry_safe(block, tmp, &state->blocks, node) {
9192
drm_printf(p, "====================%s================\n", block->name);
92-
msm_disp_state_print_regs(&block->state, block->size, block->base_addr, p);
93+
msm_disp_state_print_regs(block->state, block->size, block->base_addr, p);
9394
}
9495

9596
drm_printf(p, "===================dpu drm state================\n");

0 commit comments

Comments
 (0)