Rust for Linux List
 help / color / mirror / Atom feed
From: Janne Grunau <j@jannau.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: drm: ioctl: return Result<i32> from ioctl handlers
Date: Mon, 30 Nov 2026 12:43:13 +0100	[thread overview]
Message-ID: <20261130114313.GA41778@robin.jannau.net> (raw)
In-Reply-To: <20261130-drm-ioctl-return-i32-v1-1-2134e8274300@google.com>

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

  reply	other threads:[~2026-11-30 11:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:17 [PATCH 0/2] rust: drm: ioctl: make DRM ioctls easier to understand Alice Ryhl
2026-11-30 10:17 ` [PATCH 1/2] rust: drm: ioctl: return Result<i32> from ioctl handlers Alice Ryhl
2026-11-30 11:43   ` Janne Grunau [this message]
2026-11-30 10:17 ` [PATCH 2/2] rust: drm: ioctl: document declare_drm_ioctls! arguments and assertions Alice Ryhl
2026-11-30 11:45   ` Janne Grunau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130114313.GA41778@robin.jannau.net \
    --to=j@jannau.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox