rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Ryosuke Yasuoka" <ryasuoka@redhat.com>, <arnd@arndb.de>,
	<gregkh@linuxfoundation.org>, <ojeda@kernel.org>,
	<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
	<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
	<a.hindborg@kernel.org>, <aliceryhl@google.com>,
	<tmgross@umich.edu>, <dakr@kernel.org>, <lee@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH rust-next 2/2] rust: samples: miscdevice: add lseek samples
Date: Tue, 19 Aug 2025 00:05:41 +0200	[thread overview]
Message-ID: <DC5W7UQHOJSG.310L4WJ0AKZFE@kernel.org> (raw)
In-Reply-To: <20250818135846.133722-3-ryasuoka@redhat.com>

On Mon Aug 18, 2025 at 3:58 PM CEST, Ryosuke Yasuoka wrote:
> +    fn llseek(me: Pin<&RustMiscDevice>, file: &File, offset: i64, whence: i32) -> Result<isize> {
> +        dev_info!(me.dev, "LLSEEK Rust Misc Device Sample\n");
> +        let pos: i64;
> +        let eof: i64;
> +
> +        // SAFETY:
> +        // * The file is valid for the duration of this call.
> +        // * f_inode must be valid while the file is valid.
> +        unsafe {
> +            pos = (*file.as_ptr()).f_pos;
> +            eof = (*(*file.as_ptr()).f_inode).i_size;
> +        }

Please include abstractions for writing & reading the file position
instead of using `unsafe`.

---
Cheers,
Benno

> +
> +        let new_pos = match whence {
> +            SEEK_SET => offset,
> +            SEEK_CUR => pos + offset,
> +            SEEK_END => eof + offset,
> +            _ => {
> +                dev_err!(me.dev, "LLSEEK does not recognised: {}.\n", whence);
> +                return Err(EINVAL);
> +            }
> +        };
> +
> +        if new_pos < 0 {
> +            dev_err!(me.dev, "The file offset becomes negative: {}.\n", new_pos);
> +            return Err(EINVAL);
> +        }
> +
> +        // SAFETY: The file is valid for the duration of this call.
> +        let ret: isize = unsafe {
> +            (*file.as_ptr()).f_pos = new_pos;
> +            new_pos as isize
> +        };
> +
> +        Ok(ret)
> +    }
> +
>      fn ioctl(me: Pin<&RustMiscDevice>, _file: &File, cmd: u32, arg: usize) -> Result<isize> {
>          dev_info!(me.dev, "IOCTLing Rust Misc Device Sample\n");
>  


  reply	other threads:[~2025-08-18 22:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 13:58 [PATCH rust-next 0/2] Add llseek support to miscdevice and samples Ryosuke Yasuoka
2025-08-18 13:58 ` [PATCH rust-next 1/2] rust: miscdevice: add llseek support Ryosuke Yasuoka
2025-08-18 14:17   ` Greg KH
2025-08-19  5:10     ` Ryosuke Yasuoka
2025-08-19  6:04       ` Greg KH
2025-08-19 14:12         ` Ryosuke Yasuoka
2025-08-21 14:48           ` Miguel Ojeda
2025-08-18 13:58 ` [PATCH rust-next 2/2] rust: samples: miscdevice: add lseek samples Ryosuke Yasuoka
2025-08-18 22:05   ` Benno Lossin [this message]
2025-08-19  5:18     ` Ryosuke Yasuoka
2025-08-18 14:18 ` [PATCH rust-next 0/2] Add llseek support to miscdevice and samples Greg KH

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=DC5W7UQHOJSG.310L4WJ0AKZFE@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=arnd@arndb.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=ryasuoka@redhat.com \
    --cc=tmgross@umich.edu \
    /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;
as well as URLs for NNTP newsgroup(s).