Unverified Commit 195c52bd authored by Kari Argillander's avatar Kari Argillander Committed by Konstantin Komarov
Browse files

fs/ntfs3: Do not use driver own alloc wrappers



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: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarKari Argillander <kari.argillander@gmail.com>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent fa3cacf5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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;

@@ -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;
+5 −5
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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;
@@ -289,7 +289,7 @@ 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;
@@ -297,7 +297,7 @@ int al_add_le(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name,
		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);
+4 −4
Original line number Diff line number Diff line
@@ -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);
@@ -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;

@@ -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;

@@ -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;
	}

+0 −7
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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;

@@ -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;

Loading