Skip to content

Commit

Permalink
fs/ntfs3: Do not use driver own alloc wrappers
Browse files Browse the repository at this point in the history
Problem with these wrapper is that we cannot take off example GFP_NOFS
flag. It is not recomended use those in all places. Also if we change
one driver specific wrapper to kernel wrapper then it would look really
weird. People should be most familiar with kernel wrappers so let's just
use those ones.

Driver specific alloc wrapper also confuse some static analyzing tools,
good example is example kernels checkpatch tool. After we converter
these to kernel specific then warnings is showed.

Following Coccinelle script was used to automate changing.

virtual patch

@alloc depends on patch@
expression x;
expression y;
@@
(
-	ntfs_malloc(x)
+	kmalloc(x, GFP_NOFS)
|
-	ntfs_zalloc(x)
+	kzalloc(x, GFP_NOFS)
|
-	ntfs_vmalloc(x)
+	kvmalloc(x, GFP_NOFS)
|
-	ntfs_free(x)
+	kfree(x)
|
-	ntfs_vfree(x)
+	kvfree(x)
|
-	ntfs_memdup(x, y)
+	kmemdup(x, y, GFP_NOFS)
)

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
  • Loading branch information
teksturi authored and xanmod committed Aug 31, 2021
1 parent 7b2edf8 commit 3d45b18
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 194 deletions.
6 changes: 3 additions & 3 deletions fs/ntfs3/attrib.c
Expand Up @@ -276,7 +276,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
run_init(run);

/* make a copy of original attribute */
attr_s = ntfs_memdup(attr, asize);
attr_s = kmemdup(attr, asize, GFP_NOFS);
if (!attr_s) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -333,7 +333,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
if (err)
goto out3;

ntfs_free(attr_s);
kfree(attr_s);
attr->nres.data_size = cpu_to_le64(rsize);
attr->nres.valid_size = attr->nres.data_size;

Expand All @@ -356,7 +356,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
run_deallocate(sbi, run, false);
run_close(run);
out1:
ntfs_free(attr_s);
kfree(attr_s);
/*reinsert le*/
out:
return err;
Expand Down
10 changes: 5 additions & 5 deletions fs/ntfs3/attrlist.c
Expand Up @@ -28,7 +28,7 @@ static inline bool al_is_valid_le(const struct ntfs_inode *ni,
void al_destroy(struct ntfs_inode *ni)
{
run_close(&ni->attr_list.run);
ntfs_free(ni->attr_list.le);
kfree(ni->attr_list.le);
ni->attr_list.le = NULL;
ni->attr_list.size = 0;
ni->attr_list.dirty = false;
Expand All @@ -51,7 +51,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)

if (!attr->non_res) {
lsize = le32_to_cpu(attr->res.data_size);
le = ntfs_malloc(al_aligned(lsize));
le = kmalloc(al_aligned(lsize), GFP_NOFS);
if (!le) {
err = -ENOMEM;
goto out;
Expand All @@ -74,7 +74,7 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
if (err < 0)
goto out;

le = ntfs_malloc(al_aligned(lsize));
le = kmalloc(al_aligned(lsize), GFP_NOFS);
if (!le) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -289,15 +289,15 @@ int al_add_le(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name,
off = PtrOffset(al->le, le);

if (new_size > asize) {
void *ptr = ntfs_malloc(new_asize);
void *ptr = kmalloc(new_asize, GFP_NOFS);

if (!ptr)
return -ENOMEM;

memcpy(ptr, al->le, off);
memcpy(Add2Ptr(ptr, off + sz), le, al->size - off);
le = Add2Ptr(ptr, off);
ntfs_free(al->le);
kfree(al->le);
al->le = ptr;
} else {
memmove(Add2Ptr(le, sz), le, al->size - off);
Expand Down
8 changes: 4 additions & 4 deletions fs/ntfs3/bitmap.c
Expand Up @@ -133,7 +133,7 @@ void wnd_close(struct wnd_bitmap *wnd)
{
struct rb_node *node, *next;

ntfs_free(wnd->free_bits);
kfree(wnd->free_bits);
run_close(&wnd->run);

node = rb_first(&wnd->start_tree);
Expand Down Expand Up @@ -683,7 +683,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
if (!wnd->bits_last)
wnd->bits_last = wbits;

wnd->free_bits = ntfs_zalloc(wnd->nwnd * sizeof(u16));
wnd->free_bits = kzalloc(wnd->nwnd * sizeof(u16), GFP_NOFS);
if (!wnd->free_bits)
return -ENOMEM;

Expand Down Expand Up @@ -1354,7 +1354,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
new_last = wbits;

if (new_wnd != wnd->nwnd) {
new_free = ntfs_malloc(new_wnd * sizeof(u16));
new_free = kmalloc(new_wnd * sizeof(u16), GFP_NOFS);
if (!new_free)
return -ENOMEM;

Expand All @@ -1363,7 +1363,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
wnd->nwnd * sizeof(short));
memset(new_free + wnd->nwnd, 0,
(new_wnd - wnd->nwnd) * sizeof(short));
ntfs_free(wnd->free_bits);
kfree(wnd->free_bits);
wnd->free_bits = new_free;
}

Expand Down
7 changes: 0 additions & 7 deletions fs/ntfs3/debug.h
Expand Up @@ -47,12 +47,5 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
#define ntfs_inode_warn(inode, fmt, ...) \
ntfs_inode_printk(inode, KERN_WARNING fmt, ##__VA_ARGS__)

#define ntfs_malloc(s) kmalloc(s, GFP_NOFS)
#define ntfs_zalloc(s) kzalloc(s, GFP_NOFS)
#define ntfs_vmalloc(s) kvmalloc(s, GFP_KERNEL)
#define ntfs_free(p) kfree(p)
#define ntfs_vfree(p) kvfree(p)
#define ntfs_memdup(src, len) kmemdup(src, len, GFP_NOFS)

#endif /* _LINUX_NTFS3_DEBUG_H */
// clang-format on
4 changes: 2 additions & 2 deletions fs/ntfs3/file.c
Expand Up @@ -900,7 +900,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
return -EOPNOTSUPP;
}

pages = ntfs_malloc(pages_per_frame * sizeof(struct page *));
pages = kmalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS);
if (!pages)
return -ENOMEM;

Expand Down Expand Up @@ -1076,7 +1076,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
}

out:
ntfs_free(pages);
kfree(pages);

current->backing_dev_info = NULL;

Expand Down
27 changes: 14 additions & 13 deletions fs/ntfs3/frecord.c
Expand Up @@ -388,7 +388,7 @@ bool ni_add_subrecord(struct ntfs_inode *ni, CLST rno, struct mft_inode **mi)
{
struct mft_inode *m;

m = ntfs_zalloc(sizeof(struct mft_inode));
m = kzalloc(sizeof(struct mft_inode), GFP_NOFS);
if (!m)
return false;

Expand Down Expand Up @@ -752,7 +752,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
run_deallocate(sbi, &ni->attr_list.run, true);
run_close(&ni->attr_list.run);
ni->attr_list.size = 0;
ntfs_free(ni->attr_list.le);
kfree(ni->attr_list.le);
ni->attr_list.le = NULL;
ni->attr_list.dirty = false;

Expand Down Expand Up @@ -787,7 +787,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
* Skip estimating exact memory requirement
* Looks like one record_size is always enough
*/
le = ntfs_malloc(al_aligned(rs));
le = kmalloc(al_aligned(rs), GFP_NOFS);
if (!le) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -893,7 +893,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
goto out;

out1:
ntfs_free(ni->attr_list.le);
kfree(ni->attr_list.le);
ni->attr_list.le = NULL;
ni->attr_list.size = 0;

Expand Down Expand Up @@ -2054,7 +2054,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct page *page)
idx = (vbo - frame_vbo) >> PAGE_SHIFT;

pages_per_frame = frame_size >> PAGE_SHIFT;
pages = ntfs_zalloc(pages_per_frame * sizeof(struct page *));
pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS);
if (!pages) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2092,7 +2092,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct page *page)

out:
/* At this point, err contains 0 or -EIO depending on the "critical" page */
ntfs_free(pages);
kfree(pages);
unlock_page(page);

return err;
Expand Down Expand Up @@ -2137,7 +2137,7 @@ int ni_decompress_file(struct ntfs_inode *ni)
frame_bits = ni_ext_compress_bits(ni);
frame_size = 1u << frame_bits;
pages_per_frame = frame_size >> PAGE_SHIFT;
pages = ntfs_zalloc(pages_per_frame * sizeof(struct page *));
pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS);
if (!pages) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2298,7 +2298,7 @@ int ni_decompress_file(struct ntfs_inode *ni)
mapping->a_ops = &ntfs_aops;

out:
ntfs_free(pages);
kfree(pages);
if (err) {
make_bad_inode(inode);
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
Expand Down Expand Up @@ -2564,7 +2564,7 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
goto out1;
}

pages_disk = ntfs_zalloc(npages_disk * sizeof(struct page *));
pages_disk = kzalloc(npages_disk * sizeof(struct page *), GFP_NOFS);
if (!pages_disk) {
err = -ENOMEM;
goto out2;
Expand Down Expand Up @@ -2633,7 +2633,7 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
put_page(pg);
}
}
ntfs_free(pages_disk);
kfree(pages_disk);

out2:
#ifdef CONFIG_NTFS3_LZX_XPRESS
Expand Down Expand Up @@ -2709,7 +2709,8 @@ int ni_write_frame(struct ntfs_inode *ni, struct page **pages,
goto out;
}

pages_disk = ntfs_zalloc(pages_per_frame * sizeof(struct page *));
pages_disk = kzalloc(pages_per_frame * sizeof(struct page *),
GFP_NOFS);
if (!pages_disk) {
err = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2769,7 +2770,7 @@ int ni_write_frame(struct ntfs_inode *ni, struct page **pages,
compr_size = compress_lznt(frame_mem, frame_size, frame_ondisk,
frame_size, sbi->compress.lznt);
mutex_unlock(&sbi->compress.mtx_lznt);
ntfs_free(lznt);
kfree(lznt);

if (compr_size + sbi->cluster_size > frame_size) {
/* frame is not compressed */
Expand Down Expand Up @@ -2818,7 +2819,7 @@ int ni_write_frame(struct ntfs_inode *ni, struct page **pages,
put_page(pg);
}
}
ntfs_free(pages_disk);
kfree(pages_disk);
out:
return err;
}
Expand Down

0 comments on commit 3d45b18

Please sign in to comment.