Re: Deduplicate io_*_prep calls?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2020-02-25 12:26:34 +0300, Pavel Begunkov wrote:
> On 2/24/2020 6:50 PM, Pavel Begunkov wrote:
> It seems I have one. It can be done by using a const-attributed getter
> function. And I see nothing against it in gcc manuals.
> 
> __attribute__((const))
> static inline u8 io_get_opcode(struct io_kiocb *req)
> {
>     return req->opcode;
> }

That's practically safe, I'd assume, but I'm not sure it's theoretically
sound. The gcc manual says:

> Note that a function that has pointer arguments and examines the data
> pointed to must not be declared const if the pointed-to data might
> change between successive invocations of the function. In general, since
> a function cannot distinguish data that might change from data that
> cannot, const functions should never take pointer or, in C++, reference
> arguments. Likewise, a function that calls a non-const function usually
> must not be const itself.

and since req might be reused, this seems to violate the point about
reading pointers that could change. Which certainly isn't the case
here. Theoretically the compiler could e.g. understand that fallback_req
or such should never change it's opcode.

Greetings,

Andres Freund



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux