Re: [PATCH 06/11] iov_iter: overlay struct iovec and ubuf/len

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

 



On Wed, Mar 29, 2023 at 11:41 AM Jens Axboe <axboe@xxxxxxxxx> wrote:
>
> +               struct iovec __ubuf_iovec;

I think this is the third time I say this: this should be "const struct iovec".

No other use is ever valid, and this cast:

> +static inline const struct iovec *iter_iov(const struct iov_iter *iter)
> +{
> +       if (iter->iter_type == ITER_UBUF)
> +               return (const struct iovec *) &iter->__ubuf_iovec;

should simply not exist.

The first rule of cast club is that casting one pointer to another is
generally a sign that something is wrong.

Casting a pointer to an integer? That's a valid way to get at the bit
representation for things like tagged pointers or for virtual address
arithmetic etc (ok, and by "valid" I mean "valid in kernel contexts -
not necessarily in all other contexts).

Casting an integer to a pointer? Same thing - some things just need to
do bit operations on what will become a pointer (allocators etc).

But casting a pointer to another one - that should basically always
raise eyebrows. You should try really hard to avoid it.

Yes, we do it in the kernel, and yes, it *can* be valid. But most of
the time it's really a bad sign.

             Linus




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux