Re: [PATCH 1/2] rust: drm: ioctl: return Result<i32> from ioctl handlers
From: Janne Grunau
Date: Mon Nov 30 2026 - 06:43:31 EST
On Mon, Nov 30, 2026 at 10:17:44AM +0000, Alice Ryhl wrote:
> Currently drm ioctl handlers return a Result<u32> where errors are
> translated to negative numbers and values are converted to a
> non-negative i32. The values above i32::MAX are considered erroronous
> and mapped to -ERANGE.
>
> While teaching the Rust for Linux course, we ended up discussing the
> above after a student found it confusing and asked about this return
> value. Of course, the students knew that the C side returns a signed
> integer, so it's not clear what values about i32::MAX would mean.
>
> Based on this discussion, I'm suggesting here that we change the return
> value to Result<i32>. This means that there are two ways of returning a
> negative value to userspace (either Err(err) or Ok(-x)), and that
> userspace cannot distinguish whether the driver did one or the other.
I'd argue that userspace is not the main problem but allowing more
sutle variants of `Ok(EINVAL.to_errno())` in the driver may hide bugs.
I'm not sure what happens if the the ioctl returns a random negative
number and not a defined error. If that ends up in userspace's errno it
is probably confusing as well.
Would be using `Bounded::<u32, 31>` as return value an option? Do we
even have DRM ioctls that return a different value than `0` on success?
If not and we don't foresee ever adding them we could simplify the
return value to a plain Result.
Janne