Re: [RFC PATCH] /dev/mem: Add initial documentation of memory_open() and mem_fops

From: Gabriele Paoloni
Date: Fri Aug 22 2025 - 11:20:53 EST


On Thu, Aug 21, 2025 at 7:35 PM Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Aug 21, 2025 at 07:04:19PM +0200, Gabriele Paoloni wrote:
> > This patch proposes initial kernel-doc documentation for memory_open()
> > and most of the functions in the mem_fops structure.
> > The format used for the **Description** intends to define testable
> > function's expectations and Assumptions of Use to be met by the
> > user of the function.
> >
> > Signed-off-by: Gabriele Paoloni <gpaoloni@xxxxxxxxxx>
> > ---
> > I have a couple of comments from this documentation activity:
> > 1) Shouldn't the check in read_mem() <<if (p != *ppos)>> return
> > -EFBIG (as done in write_mem())?
>
> I think that check implies you don't want to read any more memory,
> right? Try changing it and see what happens :)

Right I see, 0 is better to gracefully terminate a read routine of
a program that may have read the whole physical range..

>
> > 2) There is a note in memory_lseek() that states the return value
> > to be (0) for negative addresses, however I cannot see how that
> > would happen in the current implementation...
>
> How that you could have a negative address, or how you would return 0?

Today the note above memory_lseek() states

* The memory devices use the full 32/64 bits of the offset, and so we cannot
* check against negative addresses: they are ok. The return value is weird,
* though, in that case (0).

I interpret this as "if offset and orig lead to an f_pos that is
negative the function
returns 0"....however I cannot see where this happen...

>
> Also, you should cc: the mm developers, they touch this file all the
> time and know it quite well (recent changes to /dev/zero just got added
> in the past few days from them.)

Sorry, I just used the addresses returned by get_maintainers...
would adding linux-mm@xxxxxxxxx work ok?

Thanks
Gab

> thanks,
>
> greg k-h
>