Skip to contentSkip to conversation

fs/ntfs3: Do not use driver own alloc wrappers

PATCH Superseded Kari Argillander 1 participant 2 messages Aug 17, 2021 NTFS3 filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: Do not use driver own alloc wrappers

Ntfs3 driver contains self made alloc wrappers. Problem with these wrappers 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 wierd. People should be most familiar with kernel wrappers so let's just use those ones.

Driver specific alloc wrapper might also confuse some static analyzing tools, but I do not have real world example.

Following Coccinelle script was used to automate most of this patch:

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)
)

---

Christoph also nack about these so I CC him.

---
 fs/ntfs3/attrib.c   |   6 +-
 fs/ntfs3/attrlist.c |  10 +--
 fs/ntfs3/bitmap.c   |   8 +--
 fs/ntfs3/debug.h    |   7 --
 fs/ntfs3/file.c     |   4 +-
 fs/ntfs3/frecord.c  |  29 ++++----
 fs/ntfs3/fslog.c    | 172 ++++++++++++++++++++++----------------------
 fs/ntfs3/fsntfs.c   |   8 +--
 fs/ntfs3/index.c    |  54 +++++++-------
 fs/ntfs3/inode.c    |  10 +--
 fs/ntfs3/lznt.c     |   4 +-
 fs/ntfs3/ntfs_fs.h  |  18 ++---
 fs/ntfs3/record.c   |   8 +--
 fs/ntfs3/run.c      |   8 +--
 fs/ntfs3/super.c    |  20 +++---
 fs/ntfs3/xattr.c    |  18 ++---
 16 files changed, 189 insertions(+), 195 deletions(-)
fs/ntfs3/attrib.c +3 -3
index 046dc57f75f2..e917a90b9e55 100644
@@ -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;
fs/ntfs3/attrlist.c +5 -5
index ea561361b576..348bfb54db09 100644
@@ -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);
fs/ntfs3/bitmap.c +4 -4
index 32aab0031221..d502bba323d0 100644
@@ -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;
 	}
 
fs/ntfs3/debug.h +0 -7
index dfaa4c79dc6d..b4103c16d4e9 100644
@@ -54,11 +54,4 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
 	ntfs_inode_printk(inode, KERN_ERR fmt, ##__VA_ARGS__)
 #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)
 // clang-format on
fs/ntfs3/file.c +2 -2
index 59344985c2e8..8d27c520bec5 100644
@@ -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;
 
fs/ntfs3/frecord.c +15 -14
index c3121bf9c62f..234668a4fd9b 100644
@@ -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;
 
@@ -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;
 
@@ -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;
@@ -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;
 
@@ -1784,7 +1784,7 @@ enum REPARSE_SIGN ni_parse_reparse(struct ntfs_inode *ni, struct ATTRIB *attr,
 		/*
 		 * WOF - Windows Overlay Filter - used to compress files with lzx/xpress
 		 * Unlike native NTFS file compression, the Windows Overlay Filter supports
-		 * only read operations. This means that it doesn�t need to sector-align each
+		 * only read operations. This means that it doesn�t need to sector-align each
 		 * compressed chunk, so the compressed data can be packed more tightly together.
 		 * If you open the file for writing, the Windows Overlay Filter just decompresses
 		 * the entire file, turning it back into a plain file.
@@ -2050,7 +2050,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;
@@ -2088,7 +2088,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;
@@ -2133,7 +2133,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;
@@ -2294,7 +2294,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);
@@ -2560,7 +2560,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;
@@ -2629,7 +2629,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
@@ -2705,7 +2705,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;
@@ -2765,7 +2766,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 */
@@ -2814,7 +2815,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;
 }
fs/ntfs3/fslog.c +86 -86

546 lines not on this page · raw message

fs/ntfs3/fsntfs.c +4 -4
index 92140050fb6c..5478b79181af 100644
@@ -2038,7 +2038,7 @@ int ntfs_get_security_by_id(struct ntfs_sb_info *sbi, __le32 security_id,
 
 	*size = t32 - SIZEOF_SECURITY_HDR;
 
-	p = ntfs_malloc(*size);
+	p = kmalloc(*size, GFP_NOFS);
 	if (!p) {
 		err = -ENOMEM;
 		goto out;
@@ -2066,7 +2066,7 @@ int ntfs_get_security_by_id(struct ntfs_sb_info *sbi, __le32 security_id,
 	p = NULL;
 
 out:
-	ntfs_free(p);
+	kfree(p);
 	fnd_put(fnd_sii);
 	ni_unlock(ni);
 
@@ -2118,7 +2118,7 @@ int ntfs_insert_security(struct ntfs_sb_info *sbi,
 	*security_id = SECURITY_ID_INVALID;
 
 	/* Allocate a temporal buffer*/
-	d_security = ntfs_zalloc(aligned_sec_size);
+	d_security = kzalloc(aligned_sec_size, GFP_NOFS);
 	if (!d_security)
 		return -ENOMEM;
 
@@ -2282,7 +2282,7 @@ int ntfs_insert_security(struct ntfs_sb_info *sbi,
 	fnd_put(fnd_sdh);
 	mark_inode_dirty(&ni->vfs_inode);
 	ni_unlock(ni);
-	ntfs_free(d_security);
+	kfree(d_security);
 
 	return err;
 }
fs/ntfs3/index.c +27 -27

193 lines not on this page · raw message

fs/ntfs3/inode.c +5 -5
index bf51e294432e..ba8e59920587 100644
@@ -1097,7 +1097,7 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
 	__le16 *rp_name;
 	typeof(rp->SymbolicLinkReparseBuffer) *rs;
 
-	rp = ntfs_zalloc(ntfs_reparse_bytes(2 * size + 2));
+	rp = kzalloc(ntfs_reparse_bytes(2 * size + 2), GFP_NOFS);
 	if (!rp)
 		return ERR_PTR(-ENOMEM);
 
@@ -1152,7 +1152,7 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
 
 	return rp;
 out:
-	ntfs_free(rp);
+	kfree(rp);
 	return ERR_PTR(err);
 }
 
@@ -1620,7 +1620,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,
 
 out2:
 	__putname(new_de);
-	ntfs_free(rp);
+	kfree(rp);
 
 out1:
 	if (err)
@@ -1862,7 +1862,7 @@ static noinline int ntfs_readlink_hlp(struct inode *inode, char *buffer,
 			goto out;
 		}
 	} else {
-		rp = ntfs_malloc(i_size);
+		rp = kmalloc(i_size, GFP_NOFS);
 		if (!rp) {
 			err = -ENOMEM;
 			goto out;
@@ -1972,7 +1972,7 @@ static noinline int ntfs_readlink_hlp(struct inode *inode, char *buffer,
 	/* Always set last zero */
 	buffer[err] = 0;
 out:
-	ntfs_free(to_free);
+	kfree(to_free);
 	return err;
 }
 
fs/ntfs3/lznt.c +2 -2
index ead9ab7d69b3..eb43b9f5149b 100644
@@ -294,8 +294,8 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,
  */
 struct lznt *get_lznt_ctx(int level)
 {
-	struct lznt *r = ntfs_zalloc(level ? offsetof(struct lznt, hash)
-					   : sizeof(struct lznt));
+	struct lznt *r = kzalloc(level ? offsetof(struct lznt, hash) :
+					 sizeof(struct lznt), GFP_NOFS);
 
 	if (r)
 		r->std = !level;
fs/ntfs3/ntfs_fs.h +9 -9
index 0c3ac89c3115..ca76cd4b59ad 100644
@@ -600,13 +600,13 @@ int indx_used_bit(struct ntfs_index *indx, struct ntfs_inode *ni, size_t *bit);
 void fnd_clear(struct ntfs_fnd *fnd);
 static inline struct ntfs_fnd *fnd_get(void)
 {
-	return ntfs_zalloc(sizeof(struct ntfs_fnd));
+	return kzalloc(sizeof(struct ntfs_fnd), GFP_NOFS);
 }
 static inline void fnd_put(struct ntfs_fnd *fnd)
 {
 	if (fnd) {
 		fnd_clear(fnd);
-		ntfs_free(fnd);
+		kfree(fnd);
 	}
 }
 void indx_clear(struct ntfs_index *idx);
@@ -872,20 +872,20 @@ static inline void run_init(struct runs_tree *run)
 
 static inline struct runs_tree *run_alloc(void)
 {
-	return ntfs_zalloc(sizeof(struct runs_tree));
+	return kzalloc(sizeof(struct runs_tree), GFP_NOFS);
 }
 
 static inline void run_close(struct runs_tree *run)
 {
-	ntfs_vfree(run->runs);
+	kvfree(run->runs);
 	memset(run, 0, sizeof(*run));
 }
 
 static inline void run_free(struct runs_tree *run)
 {
 	if (run) {
-		ntfs_vfree(run->runs);
-		ntfs_free(run);
+		kvfree(run->runs);
+		kfree(run);
 	}
 }
 
@@ -1046,15 +1046,15 @@ static inline void put_indx_node(struct indx_node *in)
 	if (!in)
 		return;
 
-	ntfs_free(in->index);
+	kfree(in->index);
 	nb_put(&in->nb);
-	ntfs_free(in);
+	kfree(in);
 }
 
 static inline void mi_clear(struct mft_inode *mi)
 {
 	nb_put(&mi->nb);
-	ntfs_free(mi->mrec);
+	kfree(mi->mrec);
 	mi->mrec = NULL;
 }
 
fs/ntfs3/record.c +4 -4
index 0d4a6251bddc..3a7b5dfddd53 100644
@@ -76,14 +76,14 @@ static __le16 mi_new_attt_id(struct mft_inode *mi)
 int mi_get(struct ntfs_sb_info *sbi, CLST rno, struct mft_inode **mi)
 {
 	int err;
-	struct mft_inode *m = ntfs_zalloc(sizeof(struct mft_inode));
+	struct mft_inode *m = kzalloc(sizeof(struct mft_inode), GFP_NOFS);
 
 	if (!m)
 		return -ENOMEM;
 
 	err = mi_init(m, sbi, rno);
 	if (err) {
-		ntfs_free(m);
+		kfree(m);
 		return err;
 	}
 
@@ -100,14 +100,14 @@ int mi_get(struct ntfs_sb_info *sbi, CLST rno, struct mft_inode **mi)
 void mi_put(struct mft_inode *mi)
 {
 	mi_clear(mi);
-	ntfs_free(mi);
+	kfree(mi);
 }
 
 int mi_init(struct mft_inode *mi, struct ntfs_sb_info *sbi, CLST rno)
 {
 	mi->sbi = sbi;
 	mi->rno = rno;
-	mi->mrec = ntfs_malloc(sbi->record_size);
+	mi->mrec = kmalloc(sbi->record_size, GFP_NOFS);
 	if (!mi->mrec)
 		return -ENOMEM;
 
fs/ntfs3/run.c +4 -4
index 5cdf6efe67e0..e743791da65c 100644
@@ -253,7 +253,7 @@ void run_truncate_head(struct runs_tree *run, CLST vcn)
 	run->count -= index;
 
 	if (!run->count) {
-		ntfs_vfree(run->runs);
+		kvfree(run->runs);
 		run->runs = NULL;
 		run->allocated = 0;
 	}
@@ -292,7 +292,7 @@ void run_truncate(struct runs_tree *run, CLST vcn)
 
 	/* Do not reallocate array 'runs'. Only free if possible */
 	if (!index) {
-		ntfs_vfree(run->runs);
+		kvfree(run->runs);
 		run->runs = NULL;
 		run->allocated = 0;
 	}
@@ -387,7 +387,7 @@ bool run_add_entry(struct runs_tree *run, CLST vcn, CLST lcn, CLST len,
 
 			WARN_ON(!is_mft && bytes > NTFS3_RUN_MAX_BYTES);
 
-			new_ptr = ntfs_vmalloc(bytes);
+			new_ptr = kvmalloc(bytes, GFP_KERNEL);
 
 			if (!new_ptr)
 				return false;
@@ -398,7 +398,7 @@ bool run_add_entry(struct runs_tree *run, CLST vcn, CLST lcn, CLST len,
 			memcpy(r + 1, run->runs + index,
 			       sizeof(struct ntfs_run) * (run->count - index));
 
-			ntfs_vfree(run->runs);
+			kvfree(run->runs);
 			run->runs = new_ptr;
 			run->allocated = bytes;
 
fs/ntfs3/super.c +10 -10
index 6be13e256c1a..6ef21da91edc 100644
@@ -467,9 +467,9 @@ static void init_once(void *foo)
 /* noinline to reduce binary size*/
 static noinline void put_ntfs(struct ntfs_sb_info *sbi)
 {
-	ntfs_free(sbi->new_rec);
-	ntfs_vfree(ntfs_put_shared(sbi->upcase));
-	ntfs_free(sbi->def_table);
+	kfree(sbi->new_rec);
+	kvfree(ntfs_put_shared(sbi->upcase));
+	kfree(sbi->def_table);
 
 	wnd_close(&sbi->mft.bitmap);
 	wnd_close(&sbi->used.bitmap);
@@ -495,14 +495,14 @@ static noinline void put_ntfs(struct ntfs_sb_info *sbi)
 	indx_clear(&sbi->security.index_sdh);
 	indx_clear(&sbi->reparse.index_r);
 	indx_clear(&sbi->objid.index_o);
-	ntfs_free(sbi->compress.lznt);
+	kfree(sbi->compress.lznt);
 #ifdef CONFIG_NTFS3_LZX_XPRESS
 	xpress_free_decompressor(sbi->compress.xpress);
 	lzx_free_decompressor(sbi->compress.lzx);
 #endif
 	clear_mount_options(&sbi->options);
 
-	ntfs_free(sbi);
+	kfree(sbi);
 }
 
 static void ntfs_put_super(struct super_block *sb)
@@ -847,7 +847,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
 
 	sbi->used.bitmap.nbits = clusters;
 
-	rec = ntfs_zalloc(record_size);
+	rec = kzalloc(record_size, GFP_NOFS);
 	if (!rec) {
 		err = -ENOMEM;
 		goto out;
@@ -914,7 +914,7 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 
 	ref.high = 0;
 
-	sbi = ntfs_zalloc(sizeof(struct ntfs_sb_info));
+	sbi = kzalloc(sizeof(struct ntfs_sb_info), GFP_NOFS);
 	if (!sbi)
 		return -ENOMEM;
 
@@ -1180,7 +1180,7 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 		goto out;
 	}
 	bytes = inode->i_size;
-	sbi->def_table = t = ntfs_malloc(bytes);
+	sbi->def_table = t = kmalloc(bytes, GFP_NOFS);
 	if (!t) {
 		err = -ENOMEM;
 		goto out;
@@ -1246,7 +1246,7 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 		goto out;
 	}
 
-	sbi->upcase = upcase = ntfs_vmalloc(0x10000 * sizeof(short));
+	sbi->upcase = upcase = kvmalloc(0x10000 * sizeof(short), GFP_KERNEL);
 	if (!upcase) {
 		err = -ENOMEM;
 		goto out;
@@ -1276,7 +1276,7 @@ static int ntfs_fill_super(struct super_block *sb, void *data, int silent)
 	shared = ntfs_set_shared(upcase, 0x10000 * sizeof(short));
 	if (shared && upcase != shared) {
 		sbi->upcase = shared;
-		ntfs_vfree(upcase);
+		kvfree(upcase);
 	}
 
 	iput(inode);
fs/ntfs3/xattr.c +9 -9
index 98871c895e77..97975d92d297 100644
@@ -110,7 +110,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
 		return -EFBIG;
 
 	/* Allocate memory for packed Ea */
-	ea_p = ntfs_malloc(size + add_bytes);
+	ea_p = kmalloc(size + add_bytes, GFP_NOFS);
 	if (!ea_p)
 		return -ENOMEM;
 
@@ -142,7 +142,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
 	return 0;
 
 out:
-	ntfs_free(ea_p);
+	kfree(ea_p);
 	*ea = NULL;
 	return err;
 }
@@ -193,7 +193,7 @@ static ssize_t ntfs_list_ea(struct ntfs_inode *ni, char *buffer,
 	}
 
 out:
-	ntfs_free(ea_all);
+	kfree(ea_all);
 	return err ? err : ret;
 }
 
@@ -251,7 +251,7 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len,
 	err = 0;
 
 out:
-	ntfs_free(ea_all);
+	kfree(ea_all);
 	if (!required)
 		ni_unlock(ni);
 
@@ -352,7 +352,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,
 		}
 
 		if (!ea_all) {
-			ea_all = ntfs_zalloc(add);
+			ea_all = kzalloc(add, GFP_NOFS);
 			if (!ea_all) {
 				err = -ENOMEM;
 				goto out;
@@ -474,7 +474,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,
 		ni_unlock(ni);
 
 	run_close(&ea_run);
-	ntfs_free(ea_all);
+	kfree(ea_all);
 
 	return err;
 }
@@ -599,7 +599,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,
 		value = NULL;
 	} else {
 		size = posix_acl_xattr_size(acl->a_count);
-		value = ntfs_malloc(size);
+		value = kmalloc(size, GFP_NOFS);
 		if (!value)
 			return -ENOMEM;
 
@@ -614,7 +614,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,
 		set_cached_acl(inode, type, acl);
 
 out:
-	ntfs_free(value);
+	kfree(value);
 
 	return err;
 }
@@ -880,7 +880,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
 			err = sd_size;
 			memcpy(buffer, sd, sd_size);
 		}
-		ntfs_free(sd);
+		kfree(sd);
 		goto out;
 	}
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 9 lines · Kari Argillander

Ntfs3 driver contains self made alloc wrappers. Problem with these wrappers 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 wierd. People should be most familiar with kernel wrappers so let's just use those ones.

Driver specific alloc wrapper might also confuse some static analyzing tools, but I do not have real world example.

Actually I do. checkpatch.pl will now give following warnings so checkpatch was triggered with self made wrappers.

WARNING: Prefer kcalloc over kzalloc with multiply #170: FILE: fs/ntfs3/bitmap.c:686:
+ wnd->free_bits = kzalloc(wnd->nwnd * sizeof(u16), GFP_NOFS);

WARNING: Prefer kmalloc_array over kmalloc with multiply #179: FILE: fs/ntfs3/bitmap.c:1357:
+ new_free = kmalloc(new_wnd * sizeof(u16), GFP_NOFS);

WARNING: Prefer kcalloc over kzalloc with multiply #284: FILE: fs/ntfs3/frecord.c:2053:
+ pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS);

WARNING: Prefer kcalloc over kzalloc with multiply #302: FILE: fs/ntfs3/frecord.c:2136:
+ pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS);

WARNING: Prefer kmalloc_array over kmalloc with multiply #1016: FILE: fs/ntfs3/index.c:684:
+ offs = kmalloc(sizeof(u16) * nslots, GFP_NOFS);

WARNING: Prefer kmalloc_array over kmalloc with multiply #1025: FILE: fs/ntfs3/index.c:706:
+ ptr = kmalloc(sizeof(u16) * new_slots, GFP_NOFS);

Quoted 32 lines

Following Coccinelle script was used to automate most of this patch:

virtual patch

@alloc depends on patch@
expression x;
expression y;
@@
(

(quoted diff) +1 -1
-	ntfs_malloc(x)
+	kmalloc(x, GFP_NOFS)

|

(quoted diff) +1 -1
-	ntfs_zalloc(x)
+	kzalloc(x, GFP_NOFS)

|

(quoted diff) +1 -1
-	ntfs_vmalloc(x)
+	kvmalloc(x, GFP_NOFS)

|

(quoted diff) +1 -1
-	ntfs_free(x)
+	kfree(x)

|

(quoted diff) +1 -1
-	ntfs_vfree(x)
+	kvfree(x)

|

(quoted diff) +1 -1
-	ntfs_memdup(x, y)
+	kmemdup(x, y, GFP_NOFS)

)

---

Christoph also nack about these so I CC him.