Use DIV_ROUND_UP() instead of manually computing round-up division calculations. Signed-off-by: Joanne Koong --- fs/fuse/dev.c | 6 +++--- fs/fuse/file.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 6d59cbc877c6..698289b5539e 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset; nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset); - nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT; + nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE); err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0); if (!folio_test_uptodate(folio) && !err && offset == 0 && @@ -1883,7 +1883,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode, else if (outarg->offset + num > file_size) num = file_size - outarg->offset; - num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; + num_pages = DIV_ROUND_UP(num + offset, PAGE_SIZE); num_pages = min(num_pages, fc->max_pages); num = min(num, num_pages << PAGE_SHIFT); @@ -1918,7 +1918,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode, folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset; nr_bytes = min(folio_size(folio) - folio_offset, num); - nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT; + nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE); ap->folios[ap->num_folios] = folio; ap->descs[ap->num_folios].offset = folio_offset; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index eba70ebf6e77..a4342b269cb9 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2170,7 +2170,7 @@ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos, WARN_ON(!ap->num_folios); /* Reached max pages */ - if ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT > fc->max_pages) + if (DIV_ROUND_UP(bytes, PAGE_SIZE) > fc->max_pages) return true; if (bytes > max_bytes) -- 2.47.3 Use offset_in_folio() instead of manually calculating the folio offset. Signed-off-by: Joanne Koong --- fs/fuse/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 698289b5539e..4dda4e24cc90 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1812,7 +1812,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, if (IS_ERR(folio)) goto out_iput; - folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset; + folio_offset = offset_in_folio(folio, outarg.offset); nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset); nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE); @@ -1916,7 +1916,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode, if (IS_ERR(folio)) break; - folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset; + folio_offset = offset_in_folio(folio, outarg->offset); nr_bytes = min(folio_size(folio) - folio_offset, num); nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE); -- 2.47.3 Replace open-coded (x & ~PAGE_MASK) with offset_in_page(). Signed-off-by: Joanne Koong --- fs/fuse/dev.c | 4 ++-- fs/fuse/readdir.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 4dda4e24cc90..9ba8ca796ff3 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1792,7 +1792,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, mapping = inode->i_mapping; index = outarg.offset >> PAGE_SHIFT; - offset = outarg.offset & ~PAGE_MASK; + offset = offset_in_page(outarg.offset); file_size = i_size_read(inode); end = outarg.offset + outarg.size; if (end > file_size) { @@ -1874,7 +1874,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode, struct fuse_args_pages *ap; struct fuse_args *args; - offset = outarg->offset & ~PAGE_MASK; + offset = offset_in_page(outarg->offset); file_size = i_size_read(inode); num = min(outarg->size, fc->max_write); diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index c2aae2eef086..c88194e52d18 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -52,7 +52,7 @@ static void fuse_add_dirent_to_cache(struct file *file, } version = fi->rdc.version; size = fi->rdc.size; - offset = size & ~PAGE_MASK; + offset = offset_in_page(size); index = size >> PAGE_SHIFT; /* Dirent doesn't fit in current page? Jump to next page. */ if (offset + reclen > PAGE_SIZE) { @@ -392,7 +392,7 @@ static enum fuse_parse_result fuse_parse_cache(struct fuse_file *ff, void *addr, unsigned int size, struct dir_context *ctx) { - unsigned int offset = ff->readdir.cache_off & ~PAGE_MASK; + unsigned int offset = offset_in_page(ff->readdir.cache_off); enum fuse_parse_result res = FOUND_NONE; WARN_ON(offset >= size); @@ -518,13 +518,13 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx) index = ff->readdir.cache_off >> PAGE_SHIFT; if (index == (fi->rdc.size >> PAGE_SHIFT)) - size = fi->rdc.size & ~PAGE_MASK; + size = offset_in_page(fi->rdc.size); else size = PAGE_SIZE; spin_unlock(&fi->rdc.lock); /* EOF? */ - if ((ff->readdir.cache_off & ~PAGE_MASK) == size) + if (offset_in_page(ff->readdir.cache_off) == size) return 0; page = find_get_page_flags(file->f_mapping, index, -- 2.47.3