Use kernel alloc wrappers and fix wargings
PATCH v2 1/1 Use kernel alloc wrappers and fix wargings
In ntfs3 driver there is allocation made like this ntfs_malloc(). Patch 2/3 will converter these to kernel ones like kmalloc(). After I did this then checkpatch raise warnings about array allocations so I fix these in patch 3/3.
I also notice when I made patch that there is broken utf8 char so I wanted first fix that because it raised some warning in my editor and did not want to "break" patch 2/3. So patch 1/3 address that.
v2:
- Add patch 1/3 because I found broken utf8 char in source file
- Add another patch 2/2 which will fix allocation warnings
- Rewrite some of commit message from first patch
Kari Argillander (3):
fs/ntfs3: Fix one none utf8 char in source file fs/ntfs3: Do not use driver own alloc wrappers fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc
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 | 28 ++++---- 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, 188 insertions(+), 195 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/1 fs/ntfs3: Fix one none utf8 char in source file
In one source file there is for some reason non utf8 char. But hey this is fs development so this kind of thing might happen.
---
I tested this for my self and at least it apply. Hopefully will apply also there.
--- fs/ntfs3/frecord.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/frecord.c +1 -1
@@ -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.
Signature · 1 line
2.25.1
PATCH v2 1/1 fs/ntfs3: Do not use driver own alloc wrappers
In reply to Kari ArgillanderProblem 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)
)
--- 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 | 27 +++---- 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, 188 insertions(+), 194 deletions(-)
fs/ntfs3/attrib.c +3 -3
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +14 -13
@@ -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 ;
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.25.1
PATCH v2 1/1 fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc
In reply to Kari ArgillanderUse kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array. Checkpatch found these after we did not use our own defined allocation wrappers.
--- fs/ntfs3/bitmap.c | 2 +- fs/ntfs3/file.c | 2 +- fs/ntfs3/frecord.c | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-)
fs/ntfs3/bitmap.c +1 -1
@@ -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 =kzalloc (wnd->nwnd *sizeof (u16),GFP_NOFS ); + wnd->free_bits =kcalloc (wnd->nwnd,sizeof (u16),GFP_NOFS );if (!wnd->free_bits)return -ENOMEM ;
fs/ntfs3/file.c +1 -1
@@ -900,7 +900,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)return -EOPNOTSUPP ; } - pages =kmalloc (pages_per_frame *sizeof (struct page *),GFP_NOFS ); + pages =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );if (!pages)return -ENOMEM ;
fs/ntfs3/frecord.c +3 -4
@@ -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 =kzalloc (pages_per_frame *sizeof (struct page *),GFP_NOFS ); + pages =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );if (!pages) { err = -ENOMEM ; goto out;
@@ -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 =kzalloc (pages_per_frame *sizeof (struct page *),GFP_NOFS ); + pages =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );if (!pages) { err = -ENOMEM ; goto out;
@@ -2705,8 +2705,7 @@ int ni_write_frame(struct ntfs_inode *ni, struct page **pages, goto out; } - pages_disk =kzalloc (pages_per_frame *sizeof (struct page *), -GFP_NOFS ); + pages_disk =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );if (!pages_disk) { err = -ENOMEM ; goto out;
Signature · 1 line
2.25.1
Re: [PATCH v2] fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc
Quoted 3 lines · Kari Argillander
Use kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array. Checkpatch found these after we did not use our own defined allocation wrappers.
[]
fs/ntfs3/file.c
Quoted 1 line
fs/ntfs3/file.c +0
-0
[]
fs/ntfs3/file.c static ssize_t ntfs_compress_write(struct kiocb · line 904
Quoted 7 lines
fs/ntfs3/file.c +1
-1@@ -900,7 +900,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)return -EOPNOTSUPP ; } - pages =kmalloc (pages_per_frame *sizeof (struct page *),GFP_NOFS ); + pages =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );
This is not an exact transformation.
This allocates zeroed memory.
Use kmalloc_array here instead.
Re: [PATCH v2] fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc
Quoted 12 lines · Joe Perches
Quoted 3 lines · Kari Argillander
Use kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array. Checkpatch found these after we did not use our own defined allocation wrappers.
[]
fs/ntfs3/file.c
Quoted 1 line
fs/ntfs3/file.c +0
-0[]
Quoted 5 lines
fs/ntfs3/file.c +0
-0@@ -900,7 +900,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)return -EOPNOTSUPP ; }
Quoted 6 lines
fs/ntfs3/file.c static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from) · line 903
Quoted 2 lines
fs/ntfs3/file.c +1
-1- pages =kmalloc (pages_per_frame *sizeof (struct page *),GFP_NOFS ); + pages =kcalloc (pages_per_frame,sizeof (struct page *),GFP_NOFS );This is not an exact transformation.
This allocates zeroed memory.
Usekmalloc_arrayhere instead.
Yeah. Thank you so much. I actually use kmalloc_array, but mistakes were made and this was result. Thank you for reviewing.