__bitmap_set/__bitmap_clear only works with bitmaps in CPU order.
Define a variant of these functions in ntfs3 to handle modifying bitmaps
read from the filesystem.
Signed-off-by: Thomas Kühnel <[email protected]>
Reviewed-by: Nicolas Schier <[email protected]>
---
fs/ntfs3/bitmap.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
fs/ntfs3/fslog.c | 4 ++--
fs/ntfs3/ntfs_fs.h | 3 +++
3 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
index aa184407520f..b61cf533b030 100644
--- a/fs/ntfs3/bitmap.c
+++ b/fs/ntfs3/bitmap.c
@@ -741,7 +741,7 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
lock_buffer(bh);
- __bitmap_clear(buf, wbit, op);
+ ntfs_bitmap_clear_le(buf, wbit, op);
wnd->free_bits[iw] += op;
@@ -793,7 +793,7 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
lock_buffer(bh);
- __bitmap_set(buf, wbit, op);
+ ntfs_bitmap_set_le(buf, wbit, op);
wnd->free_bits[iw] -= op;
set_buffer_uptodate(bh);
@@ -1370,7 +1370,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
lock_buffer(bh);
buf = (ulong *)bh->b_data;
- __bitmap_clear(buf, b0, blocksize * 8 - b0);
+ ntfs_bitmap_clear_le(buf, b0, blocksize * 8 - b0);
frb = wbits - __bitmap_weight(buf, wbits);
wnd->total_zeroes += frb - wnd->free_bits[iw];
wnd->free_bits[iw] = frb;
@@ -1489,3 +1489,43 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
return err;
}
+
+void ntfs_bitmap_set_le(unsigned long *map, unsigned int start, int len)
+{
+ unsigned long *p = map + BIT_WORD(start);
+ const unsigned int size = start + len;
+ int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
+ unsigned long mask_to_set = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
+
+ while (len - bits_to_set >= 0) {
+ *p |= mask_to_set;
+ len -= bits_to_set;
+ bits_to_set = BITS_PER_LONG;
+ mask_to_set = ~0UL;
+ p++;
+ }
+ if (len) {
+ mask_to_set &= cpu_to_le32(BITMAP_LAST_WORD_MASK(size));
+ *p |= mask_to_set;
+ }
+}
+
+void ntfs_bitmap_clear_le(unsigned long *map, unsigned int start, int len)
+{
+ unsigned long *p = map + BIT_WORD(start);
+ const unsigned int size = start + len;
+ int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
+ unsigned long mask_to_clear = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
+
+ while (len - bits_to_clear >= 0) {
+ *p &= ~mask_to_clear;
+ len -= bits_to_clear;
+ bits_to_clear = BITS_PER_LONG;
+ mask_to_clear = ~0UL;
+ p++;
+ }
+ if (len) {
+ mask_to_clear &= cpu_to_le32(BITMAP_LAST_WORD_MASK(size));
+ *p &= ~mask_to_clear;
+ }
+}
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 06492f088d60..5ec7dbad3add 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -3646,7 +3646,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
goto dirty_vol;
}
- __bitmap_set(Add2Ptr(buffer_le, roff), bmp_off, bmp_bits);
+ ntfs_bitmap_set_le(Add2Ptr(buffer_le, roff), bmp_off, bmp_bits);
a_dirty = true;
break;
@@ -3660,7 +3660,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
goto dirty_vol;
}
- __bitmap_clear(Add2Ptr(buffer_le, roff), bmp_off, bmp_bits);
+ ntfs_bitmap_clear_le(Add2Ptr(buffer_le, roff), bmp_off, bmp_bits);
a_dirty = true;
break;
diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index 8aaec7e0804e..aaecddeff4e5 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -828,6 +828,9 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits);
void wnd_zone_set(struct wnd_bitmap *wnd, size_t Lcn, size_t Len);
int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range);
+void ntfs_bitmap_set_le(unsigned long *map, unsigned int start, int len);
+void ntfs_bitmap_clear_le(unsigned long *map, unsigned int start, int len);
+
/* Globals from upcase.c */
int ntfs_cmp_names(const __le16 *s1, size_t l1, const __le16 *s2, size_t l2,
const u16 *upcase, bool bothcase);
--
2.25.1
Hi "Thomas,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on 0fcfb00b28c0b7884635dacf38e46d60bf3d4eb1]
url: https://github.com/0day-ci/linux/commits/Thomas-K-hnel/fs-ntfs3-Fixes-for-big-endian-systems/20211207-184206
base: 0fcfb00b28c0b7884635dacf38e46d60bf3d4eb1
config: arm64-randconfig-s031-20211207 (https://download.01.org/0day-ci/archive/20211208/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/2227622e39d3100d10077199481f05ccb9a17204
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Thomas-K-hnel/fs-ntfs3-Fixes-for-big-endian-systems/20211207-184206
git checkout 2227622e39d3100d10077199481f05ccb9a17204
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash fs/ntfs3/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
sparse warnings: (new ones prefixed by >>)
>> fs/ntfs3/bitmap.c:1498:37: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long mask_to_set @@ got restricted __le32 [usertype] @@
fs/ntfs3/bitmap.c:1498:37: sparse: expected unsigned long mask_to_set
fs/ntfs3/bitmap.c:1498:37: sparse: got restricted __le32 [usertype]
>> fs/ntfs3/bitmap.c:1508:29: sparse: sparse: invalid assignment: &=
>> fs/ntfs3/bitmap.c:1508:29: sparse: left side has type unsigned long
>> fs/ntfs3/bitmap.c:1508:29: sparse: right side has type restricted __le32
>> fs/ntfs3/bitmap.c:1518:39: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long mask_to_clear @@ got restricted __le32 [usertype] @@
fs/ntfs3/bitmap.c:1518:39: sparse: expected unsigned long mask_to_clear
fs/ntfs3/bitmap.c:1518:39: sparse: got restricted __le32 [usertype]
fs/ntfs3/bitmap.c:1528:31: sparse: sparse: invalid assignment: &=
fs/ntfs3/bitmap.c:1528:31: sparse: left side has type unsigned long
fs/ntfs3/bitmap.c:1528:31: sparse: right side has type restricted __le32
vim +1498 fs/ntfs3/bitmap.c
1492
1493 void ntfs_bitmap_set_le(unsigned long *map, unsigned int start, int len)
1494 {
1495 unsigned long *p = map + BIT_WORD(start);
1496 const unsigned int size = start + len;
1497 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
> 1498 unsigned long mask_to_set = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
1499
1500 while (len - bits_to_set >= 0) {
1501 *p |= mask_to_set;
1502 len -= bits_to_set;
1503 bits_to_set = BITS_PER_LONG;
1504 mask_to_set = ~0UL;
1505 p++;
1506 }
1507 if (len) {
> 1508 mask_to_set &= cpu_to_le32(BITMAP_LAST_WORD_MASK(size));
1509 *p |= mask_to_set;
1510 }
1511 }
1512
1513 void ntfs_bitmap_clear_le(unsigned long *map, unsigned int start, int len)
1514 {
1515 unsigned long *p = map + BIT_WORD(start);
1516 const unsigned int size = start + len;
1517 int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
> 1518 unsigned long mask_to_clear = cpu_to_le32(BITMAP_FIRST_WORD_MASK(start));
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]