[radeon-alex:amd-staging-drm-next 377/447] drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1007 amdgpu_ras_add_bad_pages() warn: variable dereferenced before check 'con' (see line 1003)

Dan Carpenter dan.carpenter at oracle.com
Tue Mar 26 07:16:17 UTC 2019


tree:   git://people.freedesktop.org/~agd5f/linux.git amd-staging-drm-next
head:   c9115f8904eef0f880d3b4f8306f553b1bb1c532
commit: ef3da5cab664c16ca25a8d479fac95a7f04080e3 [377/447] drm/amdgpu: add amdgpu_ras.c to support ras

smatch warnings:
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1007 amdgpu_ras_add_bad_pages() warn: variable dereferenced before check 'con' (see line 1003)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1039 amdgpu_ras_reserve_bad_pages() warn: variable dereferenced before check 'con' (see line 1034)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1066 amdgpu_ras_release_bad_pages() warn: variable dereferenced before check 'con' (see line 1062)

git remote add radeon-alex git://people.freedesktop.org/~agd5f/linux.git
git remote update radeon-alex
git checkout ef3da5cab664c16ca25a8d479fac95a7f04080e3
vim +/con +1007 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

ef3da5ca xinhui pan 2018-10-31   997  
ef3da5ca xinhui pan 2018-10-31   998  /* it deal with vram only. */
ef3da5ca xinhui pan 2018-10-31   999  int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
ef3da5ca xinhui pan 2018-10-31  1000  		unsigned long *bps, int pages)
ef3da5ca xinhui pan 2018-10-31  1001  {
ef3da5ca xinhui pan 2018-10-31  1002  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
ef3da5ca xinhui pan 2018-10-31 @1003  	struct ras_err_handler_data *data = con->eh_data;
                                                                            ^^^^^^^^^^^^
ef3da5ca xinhui pan 2018-10-31  1004  	int i = pages;
ef3da5ca xinhui pan 2018-10-31  1005  	int ret = 0;
ef3da5ca xinhui pan 2018-10-31  1006  
ef3da5ca xinhui pan 2018-10-31 @1007  	if (!con || !data || !bps || pages <= 0)
                                             ^^^
ef3da5ca xinhui pan 2018-10-31  1008  		return 0;
ef3da5ca xinhui pan 2018-10-31  1009  
ef3da5ca xinhui pan 2018-10-31  1010  	mutex_lock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1011  	if (!data)
ef3da5ca xinhui pan 2018-10-31  1012  		goto out;
ef3da5ca xinhui pan 2018-10-31  1013  
ef3da5ca xinhui pan 2018-10-31  1014  	if (data->space_left <= pages)
ef3da5ca xinhui pan 2018-10-31  1015  		if (amdgpu_ras_realloc_eh_data_space(adev, data, pages)) {
ef3da5ca xinhui pan 2018-10-31  1016  			ret = -ENOMEM;
ef3da5ca xinhui pan 2018-10-31  1017  			goto out;
ef3da5ca xinhui pan 2018-10-31  1018  		}
ef3da5ca xinhui pan 2018-10-31  1019  
ef3da5ca xinhui pan 2018-10-31  1020  	while (i--)
ef3da5ca xinhui pan 2018-10-31  1021  		data->bps[data->count++].bp = bps[i];
ef3da5ca xinhui pan 2018-10-31  1022  
ef3da5ca xinhui pan 2018-10-31  1023  	data->space_left -= pages;
ef3da5ca xinhui pan 2018-10-31  1024  out:
ef3da5ca xinhui pan 2018-10-31  1025  	mutex_unlock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1026  
ef3da5ca xinhui pan 2018-10-31  1027  	return ret;
ef3da5ca xinhui pan 2018-10-31  1028  }
ef3da5ca xinhui pan 2018-10-31  1029  
ef3da5ca xinhui pan 2018-10-31  1030  /* called in gpu recovery/init */
ef3da5ca xinhui pan 2018-10-31  1031  int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
ef3da5ca xinhui pan 2018-10-31  1032  {
ef3da5ca xinhui pan 2018-10-31  1033  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
ef3da5ca xinhui pan 2018-10-31 @1034  	struct ras_err_handler_data *data = con->eh_data;
ef3da5ca xinhui pan 2018-10-31  1035  	uint64_t bp;
ef3da5ca xinhui pan 2018-10-31  1036  	struct amdgpu_bo *bo;
ef3da5ca xinhui pan 2018-10-31  1037  	int i;
ef3da5ca xinhui pan 2018-10-31  1038  
ef3da5ca xinhui pan 2018-10-31 @1039  	if (!con || !data)
ef3da5ca xinhui pan 2018-10-31  1040  		return 0;
ef3da5ca xinhui pan 2018-10-31  1041  
ef3da5ca xinhui pan 2018-10-31  1042  	mutex_lock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1043  	/* reserve vram at driver post stage. */
ef3da5ca xinhui pan 2018-10-31  1044  	for (i = data->last_reserved; i < data->count; i++) {
ef3da5ca xinhui pan 2018-10-31  1045  		bp = data->bps[i].bp;
ef3da5ca xinhui pan 2018-10-31  1046  
ef3da5ca xinhui pan 2018-10-31  1047  		if (amdgpu_ras_reserve_vram(adev, bp << PAGE_SHIFT,
ef3da5ca xinhui pan 2018-10-31  1048  					PAGE_SIZE, &bo))
ef3da5ca xinhui pan 2018-10-31  1049  			DRM_ERROR("RAS ERROR: reserve vram %llx fail\n", bp);
ef3da5ca xinhui pan 2018-10-31  1050  
ef3da5ca xinhui pan 2018-10-31  1051  		data->bps[i].bo = bo;
ef3da5ca xinhui pan 2018-10-31  1052  		data->last_reserved = i + 1;
ef3da5ca xinhui pan 2018-10-31  1053  	}
ef3da5ca xinhui pan 2018-10-31  1054  	mutex_unlock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1055  	return 0;
ef3da5ca xinhui pan 2018-10-31  1056  }
ef3da5ca xinhui pan 2018-10-31  1057  
ef3da5ca xinhui pan 2018-10-31  1058  /* called when driver unload */
ef3da5ca xinhui pan 2018-10-31  1059  static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
ef3da5ca xinhui pan 2018-10-31  1060  {
ef3da5ca xinhui pan 2018-10-31  1061  	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
ef3da5ca xinhui pan 2018-10-31 @1062  	struct ras_err_handler_data *data = con->eh_data;
ef3da5ca xinhui pan 2018-10-31  1063  	struct amdgpu_bo *bo;
ef3da5ca xinhui pan 2018-10-31  1064  	int i;
ef3da5ca xinhui pan 2018-10-31  1065  
ef3da5ca xinhui pan 2018-10-31 @1066  	if (!con || !data)
ef3da5ca xinhui pan 2018-10-31  1067  		return 0;
ef3da5ca xinhui pan 2018-10-31  1068  
ef3da5ca xinhui pan 2018-10-31  1069  	mutex_lock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1070  	for (i = data->last_reserved - 1; i >= 0; i--) {
ef3da5ca xinhui pan 2018-10-31  1071  		bo = data->bps[i].bo;
ef3da5ca xinhui pan 2018-10-31  1072  
ef3da5ca xinhui pan 2018-10-31  1073  		amdgpu_ras_release_vram(adev, &bo);
ef3da5ca xinhui pan 2018-10-31  1074  
ef3da5ca xinhui pan 2018-10-31  1075  		data->bps[i].bo = bo;
ef3da5ca xinhui pan 2018-10-31  1076  		data->last_reserved = i;
ef3da5ca xinhui pan 2018-10-31  1077  	}
ef3da5ca xinhui pan 2018-10-31  1078  	mutex_unlock(&con->recovery_lock);
ef3da5ca xinhui pan 2018-10-31  1079  	return 0;
ef3da5ca xinhui pan 2018-10-31  1080  }
ef3da5ca xinhui pan 2018-10-31  1081  

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation


More information about the dri-devel mailing list