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

drm/stm: ltdc: fix late dereference check

In ltdc_crtc_set_crc_source(), struct drm_crtc was dereferenced in a
container_of() before the pointer check. This could cause a kernel panic.

Fix this smatch warning:
drivers/gpu/drm/stm/ltdc.c:1124 ltdc_crtc_set_crc_source() warn: variable dereferenced before check 'crtc' (see line 1119)

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/lkml/202212241802.zeLFZCXB-lkp@intel.com/
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/lkml/202212241802.zeLFZCXB-lkp@intel.com/
Signed-off-by: Raphael Gallais-Pou <raphael.gallais-pou@foss.st.com>
Acked-by: Philippe Cornu <philippe.cornu@foss.st.com>
Signed-off-by: Philippe Cornu <philippe.cornu@foss.st.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230515123818.93971-1-raphael.gallais-pou@foss.st.com

authored by

Raphael Gallais-Pou and committed by
Philippe Cornu
898a9e3f 34235f54

+3 -1
+3 -1
drivers/gpu/drm/stm/ltdc.c
··· 1145 1145 1146 1146 static int ltdc_crtc_set_crc_source(struct drm_crtc *crtc, const char *source) 1147 1147 { 1148 - struct ltdc_device *ldev = crtc_to_ltdc(crtc); 1148 + struct ltdc_device *ldev; 1149 1149 int ret; 1150 1150 1151 1151 DRM_DEBUG_DRIVER("\n"); 1152 1152 1153 1153 if (!crtc) 1154 1154 return -ENODEV; 1155 + 1156 + ldev = crtc_to_ltdc(crtc); 1155 1157 1156 1158 if (source && strcmp(source, "auto") == 0) { 1157 1159 ldev->crc_active = true;