fs/coda: get rid of CODA_ALLOC()
Subsystems (2)
PATCH 1/1 fs/coda: get rid of CODA_ALLOC()
These days we have kvzalloc() so we can delete CODA_ALLOC().
I made a couple related changes in coda_psdev_write(). First, I added some error handling to avoid a NULL dereference if the allocation failed. Second, I used kvmalloc() instead of kvzalloc() because we copy over the memory on the next line so there is no need to zero it first.
--- fs/coda/coda_linux.h | 10 ---------- fs/coda/psdev.c | 6 +++++- fs/coda/upcall.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-)
fs/coda/coda_linux.h +0 -10
@@ -63,16 +63,6 @@ unsigned short coda_flags_to_cflags(unsigned short);void coda_sysctl_init (void );void coda_sysctl_clean (void ); -#define CODA_ALLOC (ptr, cast, size) do { \ - if (size < PAGE_SIZE) \ - ptr = kzalloc((unsigned long) size, GFP_KERNEL); \ - else \ - ptr = (cast)vzalloc((unsigned long) size); \ - if (!ptr) \ - pr_warn("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \ -} while (0) - -#define CODA_FREE (ptr, size) kvfree((ptr))/* inode to cnode access functions */
fs/coda/psdev.c +5 -1
@@ -124,7 +124,11 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, hdr.opcode, hdr.unique); nbytes = size; } - CODA_ALLOC(dcbuf, union outputArgs *, nbytes); + dcbuf =kvmalloc (nbytes,GFP_KERNEL ); +if (!dcbuf) { + retval = -ENOMEM ; + goto out; + }if (copy_from_user (dcbuf, buf, nbytes)) {CODA_FREE (dcbuf, nbytes); retval = -EFAULT ;
fs/coda/upcall.c +2 -2
@@ -46,7 +46,7 @@ static void *alloc_upcall(int opcode, int size) {union inputArgs *inp; - CODA_ALLOC(inp, union inputArgs *, size); + inp =kvzalloc (size,GFP_KERNEL );if (!inp)return ERR_PTR (-ENOMEM );
@@ -743,7 +743,7 @@ static int coda_upcall(struct venus_comm *vcp, sig_req =kmalloc (sizeof (struct upc_req ),GFP_KERNEL );if (!sig_req) goto exit; - CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); + sig_req->uc_data =kvzalloc (sizeof (struct coda_in_hdr ),GFP_KERNEL );if (!sig_req->uc_data) {kfree (sig_req); goto exit;
Signature · 1 line
2.17.1
Quoted 1 line · Dan Carpenter
These days we have
kvzalloc()so we can deleteCODA_ALLOC().
Maybe it would be better to get rid fo CODA_FREE as well?
julia
Quoted 78 lines
I made a couple related changes in
coda_psdev_write(). First, I added some error handling to avoid a NULL dereference if the allocation failed. Second, I usedkvmalloc()instead ofkvzalloc()because we copy over the memory on the next line so there is no need to zero it first.Signed-off-by Dan Carpenter <[email protected]>--- fs/coda/coda_linux.h | 10 ---------- fs/coda/psdev.c | 6 +++++- fs/coda/upcall.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-)fs/coda/coda_linux.h +0
-10@@ -63,16 +63,6 @@ unsigned short coda_flags_to_cflags(unsigned short);void coda_sysctl_init (void );void coda_sysctl_clean (void ); -#define CODA_ALLOC (ptr, cast, size) do { \ - if (size < PAGE_SIZE) \ - ptr = kzalloc((unsigned long) size, GFP_KERNEL); \ - else \ - ptr = (cast)vzalloc((unsigned long) size); \ - if (!ptr) \ - pr_warn("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \ -} while (0) - -#define CODA_FREE (ptr, size) kvfree((ptr))/* inode to cnode access functions */ fs/coda/psdev.c +5
-1@@ -124,7 +124,11 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, hdr.opcode, hdr.unique); nbytes = size; } - CODA_ALLOC(dcbuf, union outputArgs *, nbytes); + dcbuf =kvmalloc (nbytes,GFP_KERNEL ); +if (!dcbuf) { + retval = -ENOMEM ; + goto out; + }if (copy_from_user (dcbuf, buf, nbytes)) {CODA_FREE (dcbuf, nbytes); retval = -EFAULT ;fs/coda/upcall.c +2
-3@@ -46,7 +46,7 @@ static void *alloc_upcall(int opcode, int size) {union inputArgs *inp; - CODA_ALLOC(inp, union inputArgs *, size); + inp =kvzalloc (size,GFP_KERNEL );if (!inp)return ERR_PTR (-ENOMEM );@@ -743,7 +743,7 @@ static int coda_upcall(struct venus_comm *vcp, sig_req =kmalloc (sizeof (struct upc_req ),GFP_KERNEL );if (!sig_req) goto exit; - CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); + sig_req->uc_data =kvzalloc (sizeof (struct coda_in_hdr ),GFP_KERNEL );if (!sig_req->uc_data) {kfree (sig_req); goto exit; --2.17.1
Quoted 7 lines · Julia Lawall
Quoted 1 line · Dan Carpenter
These days we have
kvzalloc()so we can deleteCODA_ALLOC().Maybe it would be better to get rid fo
CODA_FREEas well?
I feel like that's a separate issue. The CODA_FREE() macro already uses kvfree() so it doesn't bother me as much as the CODA_ALLOC() macro.
regards,
dan carpenter
Quoted 8 lines · Julia Lawall
Quoted 1 line · Dan Carpenter
These days we have
kvzalloc()so we can deleteCODA_ALLOC().Maybe it would be better to get rid fo
CODA_FREEas well?
Actually, you're right. CODA_FREE() is especially weird without a CODA_ALLOC(). But let me send that as a second patch.
regards,
dan carpenter
PATCH 1/1 coda: get rid of CODA_FREE()
In reply to Julia LawallThe CODA_FREE() macro just calls kvfree(). We can call that directly instead.
--- fs/coda/coda_linux.h | 2 -- fs/coda/psdev.c | 8 ++++---- fs/coda/upcall.c | 36 ++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 24 deletions(-)
fs/coda/coda_linux.h +0 -2
@@ -63,8 +63,6 @@ unsigned short coda_flags_to_cflags(unsigned short);void coda_sysctl_init (void );void coda_sysctl_clean (void ); -#define CODA_FREE (ptr, size) kvfree((ptr)) -/* inode to cnode access functions */ static inline struct coda_inode_info *ITOC (struct inode *inode)
fs/coda/psdev.c +4 -4
@@ -130,7 +130,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, goto out; }if (copy_from_user (dcbuf, buf, nbytes)) { -CODA_FREE (dcbuf, nbytes); +kvfree (dcbuf); retval = -EFAULT ; goto out; }
@@ -138,7 +138,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,/* what downcall errors does Venus handle ? */ error =coda_downcall (vcp, hdr.opcode, dcbuf); -CODA_FREE (dcbuf, nbytes); +kvfree (dcbuf);if (error) {pr_warn ("%s: coda_downcall error: %d\n" , __func__, error);
@@ -261,7 +261,7 @@ static ssize_t coda_psdev_read(struct file * file, char __user * buf, goto out; } -CODA_FREE (req->uc_data,sizeof (struct coda_in_hdr )); +kvfree (req->uc_data);kfree (req); out:mutex_unlock (&vcp->vc_mutex);
@@ -323,7 +323,7 @@ static int coda_psdev_release(struct inode * inode, struct file * file)/* Async requests need to be freed here */ if (req->uc_flags &CODA_REQ_ASYNC ) { -CODA_FREE (req->uc_data,sizeof (struct coda_in_hdr )); +kvfree (req->uc_data);kfree (req);continue ; }
fs/coda/upcall.c +18 -18
@@ -85,7 +85,7 @@ int venus_rootfid(struct super_block *sb, struct CodaFid *fidp)if (!error) *fidp = outp->coda_root.VFid; -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -104,7 +104,7 @@ int venus_getattr(struct super_block *sb, struct CodaFid *fid,if (!error) *attr = outp->coda_getattr.attr; -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -123,7 +123,7 @@ int venus_setattr(struct super_block *sb, struct CodaFid *fid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -153,7 +153,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid, *type = outp->coda_lookup.vtype; } -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -173,7 +173,7 @@ int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -194,7 +194,7 @@ int venus_open(struct super_block *sb, struct CodaFid *fid,if (!error) *fh = outp->coda_open_by_fd.fh; -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -224,7 +224,7 @@ int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid, *newfid = outp->coda_mkdir.VFid; } -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -262,7 +262,7 @@ int venus_rename(struct super_block *sb, struct CodaFid *old_fid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -295,7 +295,7 @@ int venus_create(struct super_block *sb, struct CodaFid *dirfid, *newfid = outp->coda_create.VFid; } -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -318,7 +318,7 @@ int venus_rmdir(struct super_block *sb, struct CodaFid *dirfid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -340,7 +340,7 @@ int venus_remove(struct super_block *sb, struct CodaFid *dirfid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -370,7 +370,7 @@ int venus_readlink(struct super_block *sb, struct CodaFid *fid, *(buffer + retlen) ='\0' ; } -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -398,7 +398,7 @@ int venus_link(struct super_block *sb, struct CodaFid *fid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -433,7 +433,7 @@ int venus_symlink(struct super_block *sb, struct CodaFid *fid, error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -449,7 +449,7 @@ int venus_fsync(struct super_block *sb, struct CodaFid *fid) inp->coda_fsync.VFid = *fid; error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -467,7 +467,7 @@ int venus_access(struct super_block *sb, struct CodaFid *fid, int mask) error =coda_upcall (coda_vcp (sb), insize, &outsize, inp); -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -543,7 +543,7 @@ int venus_pioctl(struct super_block *sb, struct CodaFid *fid, } exit: -CODA_FREE (inp, insize); +kvfree (inp);return error; }
@@ -565,7 +565,7 @@ int venus_statfs(struct dentry *dentry, struct kstatfs *sfs) sfs->f_ffree = outp->coda_statfs.stat.f_ffree; } -CODA_FREE (inp, insize); +kvfree (inp);return error; }
Signature · 1 line
2.17.1
Jan Harkes
maintainerRe: [PATCH 2] coda: get rid of CODA_FREE()
Quoted 2 lines · Dan Carpenter
The
CODA_FREE()macro just callskvfree(). We can call that directly instead.
Added these to my (getting long) list of things that I really should get upstreamed sometime soon now.
Jan