diff --git a/src/gallium/frontends/rusticl/api/context.rs b/src/gallium/frontends/rusticl/api/context.rs index da74b7ddc17..5654f0e0115 100644 --- a/src/gallium/frontends/rusticl/api/context.rs +++ b/src/gallium/frontends/rusticl/api/context.rs @@ -80,7 +80,8 @@ pub fn get_gl_context_info_khr( // SAFETY: properties is a 0 terminated array by spec. let props = unsafe { Properties::new(properties) }.ok_or(CL_INVALID_PROPERTY)?; for (&key, &val) in props.iter() { - match key as u32 { + let key = u32::try_from(key).or(Err(CL_INVALID_PROPERTY))?; + match key { // CL_INVALID_PLATFORM [...] if platform value specified in properties is not a valid platform. CL_CONTEXT_PLATFORM => { (val as cl_platform_id).get_ref()?; @@ -143,7 +144,8 @@ fn create_context( // SAFETY: properties is a 0 terminated array by spec. let props = unsafe { Properties::new(properties) }.ok_or(CL_INVALID_PROPERTY)?; for (&key, &val) in props.iter() { - match key as u32 { + let key = u32::try_from(key).or(Err(CL_INVALID_PROPERTY))?; + match key { // CL_INVALID_PLATFORM [...] if platform value specified in properties is not a valid platform. CL_CONTEXT_PLATFORM => { (val as cl_platform_id).get_ref()?; diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 4702992fd4e..1229cdfe76e 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -1020,10 +1020,16 @@ fn create_sampler_with_properties( let sampler_properties = unsafe { Properties::new(sampler_properties) }.ok_or(CL_INVALID_VALUE)?; for (&key, &val) in sampler_properties.iter() { - match key as u32 { - CL_SAMPLER_ADDRESSING_MODE => addressing_mode = val as u32, - CL_SAMPLER_FILTER_MODE => filter_mode = val as u32, - CL_SAMPLER_NORMALIZED_COORDS => normalized_coords = val as u32, + match u32::try_from(key).or(Err(CL_INVALID_VALUE))? { + CL_SAMPLER_ADDRESSING_MODE => { + addressing_mode = cl_addressing_mode::try_from(val).or(Err(CL_INVALID_VALUE))? + } + CL_SAMPLER_FILTER_MODE => { + filter_mode = cl_filter_mode::try_from(val).or(Err(CL_INVALID_VALUE))? + } + CL_SAMPLER_NORMALIZED_COORDS => { + normalized_coords = cl_bool::try_from(val).or(Err(CL_INVALID_VALUE))? + } // CL_INVALID_VALUE if the property name in sampler_properties is not a supported // property name _ => return Err(CL_INVALID_VALUE), diff --git a/src/gallium/frontends/rusticl/api/queue.rs b/src/gallium/frontends/rusticl/api/queue.rs index bf032666de1..1b6b887a9fb 100644 --- a/src/gallium/frontends/rusticl/api/queue.rs +++ b/src/gallium/frontends/rusticl/api/queue.rs @@ -132,9 +132,9 @@ fn create_command_queue_with_properties( // SAFETY: properties is a 0 terminated array by spec. let properties = unsafe { Properties::new(properties) }.ok_or(CL_INVALID_PROPERTY)?; - for (k, v) in properties.iter() { - match *k as cl_uint { - CL_QUEUE_PROPERTIES => queue_properties = *v, + for (&key, &val) in properties.iter() { + match u32::try_from(key).or(Err(CL_INVALID_PROPERTY))? { + CL_QUEUE_PROPERTIES => queue_properties = val, // CL_INVALID_QUEUE_PROPERTIES if values specified in properties are valid but are not // supported by the device. CL_QUEUE_SIZE => return Err(CL_INVALID_QUEUE_PROPERTIES),