Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vc4: kms: Fix return code check

The HVS global state functions return an error pointer, but in most
cases we check if it's NULL, possibly resulting in an invalid pointer
dereference.

Fixes: 9ec03d7f1ed3 ("drm/vc4: kms: Wait on previous FIFO users before a commit")
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Tested-by: Jian-Hong Pan <jhp@endlessos.org>
Link: https://lore.kernel.org/r/20211117094527.146275-3-maxime@cerno.tech

+5 -5
+5 -5
drivers/gpu/drm/vc4/vc4_kms.c
··· 354 354 } 355 355 356 356 old_hvs_state = vc4_hvs_get_old_global_state(state); 357 - if (!old_hvs_state) 357 + if (IS_ERR(old_hvs_state)) 358 358 return; 359 359 360 360 for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) { ··· 410 410 unsigned int i; 411 411 412 412 hvs_state = vc4_hvs_get_new_global_state(state); 413 - if (!hvs_state) 414 - return -EINVAL; 413 + if (WARN_ON(IS_ERR(hvs_state))) 414 + return PTR_ERR(hvs_state); 415 415 416 416 for_each_new_crtc_in_state(state, crtc, crtc_state, i) { 417 417 struct vc4_crtc_state *vc4_crtc_state = ··· 762 762 unsigned int i; 763 763 764 764 hvs_new_state = vc4_hvs_get_global_state(state); 765 - if (!hvs_new_state) 766 - return -EINVAL; 765 + if (IS_ERR(hvs_new_state)) 766 + return PTR_ERR(hvs_new_state); 767 767 768 768 for (i = 0; i < ARRAY_SIZE(hvs_new_state->fifo_state); i++) 769 769 if (!hvs_new_state->fifo_state[i].in_use)