Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: explicity type cast in bset_bkey_last()

In bset.h, macro bset_bkey_last() is defined as,
bkey_idx((struct bkey *) (i)->d, (i)->keys)

Parameter i can be variable type of data structure, the macro always
works once the type of struct i has member 'd' and 'keys'.

bset_bkey_last() is also used in macro csum_set() to calculate the
checksum of a on-disk data structure. When csum_set() is used to
calculate checksum of on-disk bcache super block, the parameter 'i'
data type is struct cache_sb_disk. Inside struct cache_sb_disk (also in
struct cache_sb) the member keys is __u16 type. But bkey_idx() expects
unsigned int (a 32bit width), so there is problem when sending
parameters via stack to call bkey_idx().

Sparse tool from Intel 0day kbuild system reports this incompatible
problem. bkey_idx() is part of user space API, so the simplest fix is
to cast the (i)->keys to unsigned int type in macro bset_bkey_last().

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Coly Li and committed by
Jens Axboe
7c02b005 5bebf748

+2 -1
+2 -1
drivers/md/bcache/bset.h
··· 397 397 398 398 /* Bkey utility code */ 399 399 400 - #define bset_bkey_last(i) bkey_idx((struct bkey *) (i)->d, (i)->keys) 400 + #define bset_bkey_last(i) bkey_idx((struct bkey *) (i)->d, \ 401 + (unsigned int)(i)->keys) 401 402 402 403 static inline struct bkey *bset_bkey_idx(struct bset *i, unsigned int idx) 403 404 {