nilfs2: use div64_ul() instead of do_div()
authorThorsten Blum <thorsten.blum@toblux.com>
Wed, 6 Mar 2024 14:25:47 +0000 (23:25 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 12 Mar 2024 20:09:23 +0000 (13:09 -0700)
Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.

Compared to do_div(), div64_ul() does not implicitly cast the divisor and
does not unnecessarily calculate the remainder.

Link: https://lkml.kernel.org/r/20240229210456.63234-2-thorsten.blum@toblux.com
Link: https://lkml.kernel.org/r/20240306142547.4612-1-konishi.ryusuke@gmail.com
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/nilfs2/cpfile.c
fs/nilfs2/dat.c
fs/nilfs2/ioctl.c
fs/nilfs2/sufile.c
fs/nilfs2/super.c
fs/nilfs2/the_nilfs.c

index 2c57132584de741692713c40cc344f5d1b962622..69a5cced1e84b947683bcc1deab3363ea0be8fb9 100644 (file)
@@ -28,7 +28,7 @@ nilfs_cpfile_get_blkoff(const struct inode *cpfile, __u64 cno)
 {
        __u64 tcno = cno + NILFS_MDT(cpfile)->mi_first_entry_offset - 1;
 
-       do_div(tcno, nilfs_cpfile_checkpoints_per_block(cpfile));
+       tcno = div64_ul(tcno, nilfs_cpfile_checkpoints_per_block(cpfile));
        return (unsigned long)tcno;
 }
 
index 8f71f8b0e2188b52bb793a998803ea21ebaedfbe..180fc8d36213df3b73a5be9ad744bfefd97f4b47 100644 (file)
@@ -460,7 +460,7 @@ ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *buf, unsigned int visz,
                kaddr = kmap_local_page(entry_bh->b_page);
                /* last virtual block number in this block */
                first = vinfo->vi_vblocknr;
-               do_div(first, entries_per_block);
+               first = div64_ul(first, entries_per_block);
                first *= entries_per_block;
                last = first + entries_per_block - 1;
                for (j = i, n = 0;
index cfb6aca5ec383020b6d05c712d03b49bf6218b26..f1a01c191cf53ad17131fcf2a256f70b37d0d86c 100644 (file)
@@ -1111,7 +1111,7 @@ static int nilfs_ioctl_set_alloc_range(struct inode *inode, void __user *argp)
        segbytes = nilfs->ns_blocks_per_segment * nilfs->ns_blocksize;
 
        minseg = range[0] + segbytes - 1;
-       do_div(minseg, segbytes);
+       minseg = div64_ul(minseg, segbytes);
 
        if (range[1] < 4096)
                goto out;
@@ -1120,7 +1120,7 @@ static int nilfs_ioctl_set_alloc_range(struct inode *inode, void __user *argp)
        if (maxseg < segbytes)
                goto out;
 
-       do_div(maxseg, segbytes);
+       maxseg = div64_ul(maxseg, segbytes);
        maxseg--;
 
        ret = nilfs_sufile_set_alloc_range(nilfs->ns_sufile, minseg, maxseg);
index abf05dc5750c79515617d310c47189671b6483c1..6748218be7c591e21af3740cb756dcec2df7818a 100644 (file)
@@ -48,7 +48,7 @@ nilfs_sufile_get_blkoff(const struct inode *sufile, __u64 segnum)
 {
        __u64 t = segnum + NILFS_MDT(sufile)->mi_first_entry_offset;
 
-       do_div(t, nilfs_sufile_segment_usages_per_block(sufile));
+       t = div64_ul(t, nilfs_sufile_segment_usages_per_block(sufile));
        return (unsigned long)t;
 }
 
index 5e630c179a1e2930600237207716d8832de0019e..ac24ed109ce93563e6c9c932709813bf1aec72dc 100644 (file)
@@ -448,7 +448,7 @@ int nilfs_resize_fs(struct super_block *sb, __u64 newsize)
 
        sb2off = NILFS_SB2_OFFSET_BYTES(newsize);
        newnsegs = sb2off >> nilfs->ns_blocksize_bits;
-       do_div(newnsegs, nilfs->ns_blocks_per_segment);
+       newnsegs = div64_ul(newnsegs, nilfs->ns_blocks_per_segment);
 
        ret = nilfs_sufile_resize(nilfs->ns_sufile, newnsegs);
        up_write(&nilfs->ns_segctor_sem);
index 71400496ed36519d2524ab552efed3e150899a52..2ae2c1bbf6d17c6aa10752679f5635329af362e4 100644 (file)
@@ -413,7 +413,7 @@ static u64 nilfs_max_segment_count(struct the_nilfs *nilfs)
 {
        u64 max_count = U64_MAX;
 
-       do_div(max_count, nilfs->ns_blocks_per_segment);
+       max_count = div64_ul(max_count, nilfs->ns_blocks_per_segment);
        return min_t(u64, max_count, ULONG_MAX);
 }