Re: drivers/md/bcache/super.c:108:14: sparse: sparse: restricted __le64 degrades to integer

From: Coly Li
Date: Thu Dec 12 2024 - 12:48:19 EST




> 2024年12月12日 14:23,Christoph Hellwig <hch@xxxxxx> 写道:
>
> On Wed, Dec 11, 2024 at 12:34:20AM +0800, Coly Li wrote:
>>> drivers/md/bcache/super.c:108:24: sparse: expected unsigned int nr_keys
>>> drivers/md/bcache/super.c:108:24: sparse: got restricted __le16 [usertype] keys
>>>>> drivers/md/bcache/super.c:108:14: sparse: sparse: restricted __le64 degrades to integer
>>
>> It complains about line 108 which is,
>>> cafe563591446cf Kent Overstreet 2013-03-23 107 err = "Bad checksum";
>>> cafe563591446cf Kent Overstreet 2013-03-23 @108 if (s->csum != csum_set(s))
>>> cafe563591446cf Kent Overstreet 2013-03-23 109 goto err;
>>
>> Here s->sum is __le64, csum_set() is uint64_t, these two types have same length. I don’t see the direct connection between code and warning.
>
> The are the same size, but not the same endianess. In other words this
> is a hint that this code is most likely broken on big endian systems
> due to the lack of a bytespace (which is a no-op on little endian
> systems).

Oh I see. Thank you for the information.

Bcache doesn’t support moving cache device between machines with different endians. The on-disk data always has identical endian type as the in-memory data. The reason for __le64 was because it had to be a type defined.
Although there are some cpu_to_xxx used in code, indeed the btree keys are used directly after reading in from disk, or written directly without any cpu_to_xxx convert.

So this warning can be ignored.


Coly Li