drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_plane.c:1263 amdgpu_dm_plane_handle_cursor_update() error: we previously assumed 'afb' could be null (see line 1222)

From: Dan Carpenter
Date: Mon May 22 2023 - 02:54:20 EST


Hi David,

FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d635f6cc934bcd467c5d67148ece74632fd96abf
commit: 8bf0d9cdf36b0bebf17b733e3f5158783d765df3 drm/amd/display: add prefix to amdgpu_dm_plane.h functions
config: ia64-randconfig-m041-20230514
compiler: ia64-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Closes: https://lore.kernel.org/r/202305210251.IqE6U5XP-lkp@xxxxxxxxx/

smatch warnings:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_plane.c:1263 amdgpu_dm_plane_handle_cursor_update() error: we previously assumed 'afb' could be null (see line 1222)

vim +/afb +1263 drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_plane.c

8bf0d9cdf36b0b David Tadokoro 2023-03-05 1214 void amdgpu_dm_plane_handle_cursor_update(struct drm_plane *plane,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1215 struct drm_plane_state *old_plane_state)
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1216 {
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1217 struct amdgpu_device *adev = drm_to_adev(plane->dev);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1218 struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(plane->state->fb);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1219 struct drm_crtc *crtc = afb ? plane->state->crtc : old_plane_state->crtc;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1220 struct dm_crtc_state *crtc_state = crtc ? to_dm_crtc_state(crtc->state) : NULL;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1221 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 @1222 uint64_t address = afb ? afb->address : 0;
^^^
Is this check required?

5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1223 struct dc_cursor_position position = {0};
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1224 struct dc_cursor_attributes attributes;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1225 int ret;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1226
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1227 if (!plane->state->fb && !old_plane_state->fb)
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1228 return;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1229
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1230 DC_LOG_CURSOR("%s: crtc_id=%d with size %d to %d\n",
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1231 __func__,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1232 amdgpu_crtc->crtc_id,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1233 plane->state->crtc_w,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1234 plane->state->crtc_h);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1235
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1236 ret = get_cursor_position(plane, crtc, &position);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1237 if (ret)
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1238 return;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1239
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1240 if (!position.enable) {
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1241 /* turn off cursor */
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1242 if (crtc_state && crtc_state->stream) {
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1243 mutex_lock(&adev->dm.dc_lock);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1244 dc_stream_set_cursor_position(crtc_state->stream,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1245 &position);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1246 mutex_unlock(&adev->dm.dc_lock);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1247 }
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1248 return;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1249 }
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1250
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1251 amdgpu_crtc->cursor_width = plane->state->crtc_w;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1252 amdgpu_crtc->cursor_height = plane->state->crtc_h;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1253
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1254 memset(&attributes, 0, sizeof(attributes));
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1255 attributes.address.high_part = upper_32_bits(address);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1256 attributes.address.low_part = lower_32_bits(address);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1257 attributes.width = plane->state->crtc_w;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1258 attributes.height = plane->state->crtc_h;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1259 attributes.color_format = CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1260 attributes.rotation_angle = 0;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1261 attributes.attribute_flags.value = 0;
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1262
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 @1263 attributes.pitch = afb->base.pitches[0] / afb->base.format->cpp[0];
^^^^^ ^^^^^
It's not checked here.

5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1264
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1265 if (crtc_state->stream) {
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1266 mutex_lock(&adev->dm.dc_lock);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1267 if (!dc_stream_set_cursor_attributes(crtc_state->stream,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1268 &attributes))
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1269 DRM_ERROR("DC failed to set cursor attributes\n");
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1270
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1271 if (!dc_stream_set_cursor_position(crtc_state->stream,
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1272 &position))
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1273 DRM_ERROR("DC failed to set cursor position\n");
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1274 mutex_unlock(&adev->dm.dc_lock);
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1275 }
5d945cbcd4b16a Rodrigo Siqueira 2022-07-20 1276 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki