hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
....@@ -1998,7 +1998,7 @@
19981998
19991999 cmd = container_of(header, typeof(*cmd), header);
20002000
2001
- if (cmd->body.type >= SVGA3D_SHADERTYPE_PREDX_MAX) {
2001
+ if (!vmw_shadertype_is_valid(VMW_SM_LEGACY, cmd->body.type)) {
20022002 VMW_DEBUG_USER("Illegal shader type %u.\n",
20032003 (unsigned int) cmd->body.type);
20042004 return -EINVAL;
....@@ -2120,8 +2120,6 @@
21202120 SVGA3dCmdHeader *header)
21212121 {
21222122 VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetSingleConstantBuffer);
2123
- SVGA3dShaderType max_shader_num = has_sm5_context(dev_priv) ?
2124
- SVGA3D_NUM_SHADERTYPE : SVGA3D_NUM_SHADERTYPE_DX10;
21252123
21262124 struct vmw_resource *res = NULL;
21272125 struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
....@@ -2138,6 +2136,14 @@
21382136 if (unlikely(ret != 0))
21392137 return ret;
21402138
2139
+ if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type) ||
2140
+ cmd->body.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2141
+ VMW_DEBUG_USER("Illegal const buffer shader %u slot %u.\n",
2142
+ (unsigned int) cmd->body.type,
2143
+ (unsigned int) cmd->body.slot);
2144
+ return -EINVAL;
2145
+ }
2146
+
21412147 binding.bi.ctx = ctx_node->ctx;
21422148 binding.bi.res = res;
21432149 binding.bi.bt = vmw_ctx_binding_cb;
....@@ -2145,14 +2151,6 @@
21452151 binding.offset = cmd->body.offsetInBytes;
21462152 binding.size = cmd->body.sizeInBytes;
21472153 binding.slot = cmd->body.slot;
2148
-
2149
- if (binding.shader_slot >= max_shader_num ||
2150
- binding.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) {
2151
- VMW_DEBUG_USER("Illegal const buffer shader %u slot %u.\n",
2152
- (unsigned int) cmd->body.type,
2153
- (unsigned int) binding.slot);
2154
- return -EINVAL;
2155
- }
21562154
21572155 vmw_binding_add(ctx_node->staged, &binding.bi, binding.shader_slot,
21582156 binding.slot);
....@@ -2174,15 +2172,13 @@
21742172 {
21752173 VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShaderResources) =
21762174 container_of(header, typeof(*cmd), header);
2177
- SVGA3dShaderType max_allowed = has_sm5_context(dev_priv) ?
2178
- SVGA3D_SHADERTYPE_MAX : SVGA3D_SHADERTYPE_DX10_MAX;
21792175
21802176 u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) /
21812177 sizeof(SVGA3dShaderResourceViewId);
21822178
21832179 if ((u64) cmd->body.startView + (u64) num_sr_view >
21842180 (u64) SVGA3D_DX_MAX_SRVIEWS ||
2185
- cmd->body.type >= max_allowed) {
2181
+ !vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
21862182 VMW_DEBUG_USER("Invalid shader binding.\n");
21872183 return -EINVAL;
21882184 }
....@@ -2206,8 +2202,6 @@
22062202 SVGA3dCmdHeader *header)
22072203 {
22082204 VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShader);
2209
- SVGA3dShaderType max_allowed = has_sm5_context(dev_priv) ?
2210
- SVGA3D_SHADERTYPE_MAX : SVGA3D_SHADERTYPE_DX10_MAX;
22112205 struct vmw_resource *res = NULL;
22122206 struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context);
22132207 struct vmw_ctx_bindinfo_shader binding;
....@@ -2218,8 +2212,7 @@
22182212
22192213 cmd = container_of(header, typeof(*cmd), header);
22202214
2221
- if (cmd->body.type >= max_allowed ||
2222
- cmd->body.type < SVGA3D_SHADERTYPE_MIN) {
2215
+ if (!vmw_shadertype_is_valid(dev_priv->sm_type, cmd->body.type)) {
22232216 VMW_DEBUG_USER("Illegal shader type %u.\n",
22242217 (unsigned int) cmd->body.type);
22252218 return -EINVAL;