f2fs: add scope based f2fs_putname() cleanup
A message that is not in the archive (sent off-list or not yet received): CGME20240611234050epcas2p40bd72d91c6a7b67e411a5ebfcddbcb97@epcas2p4.samsung.com
PATCH 1/1 f2fs: add scope based f2fs_putname() cleanup
From: Jeongtae Park <[email protected]>
This patch adds a new scope based f2fs_putname() cleanup to reduce the chances of forgetting a f2fs_putname(). And doing so removes a goto statement for error handling.
--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-)
fs/f2fs/f2fs.h +2 -0
@@ -3402,6 +3402,8 @@ static inline void f2fs_putname(char *buf)__putname (buf); } +DEFINE_FREE(f2fs_putname, void *, if (_T) f2fs_putname(_T)) +static inline void *f2fs_kzalloc (struct f2fs_sb_info *sbi,size_t size,gfp_t flags) {
fs/f2fs/file.c +3 -5
@@ -4511,22 +4511,20 @@ static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, int rw) {struct inode *inode =file_inode (file); -char *buf, *path; + char *buf __free(f2fs_putname) = f2fs_getname(F2FS_I_SB(inode)); +char *path; - buf =f2fs_getname (F2FS_I_SB (inode));if (!buf)return ; path =dentry_path_raw (file_dentry (file), buf,PATH_MAX );if (IS_ERR (path)) - goto free_buf; +return ;if (rw ==WRITE )trace_f2fs_datawrite_start (inode, pos, count, current->pid, path, current->comm);else trace_f2fs_dataread_start (inode, pos, count, current->pid, path, current->comm); -free_buf: -f2fs_putname (buf); }static ssize_t f2fs_file_read_iter (struct kiocb *iocb,struct iov_iter *to)
Signature · 8 lines
2.25.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 4 lines · On 2024/6/12 7:39, [email protected] wrote:
From: Jeongtae Park <[email protected]>
This patch adds a new scope based
f2fs_putname()cleanup to reduce the chances of forgetting af2fs_putname(). And doing so removes
Actually, f2fs_trace_rw_file_path() won't change frequently, so the risk of forgetting f2fs_putname() here is very low.
Quoted 1 line
a goto statement for error handling.
The code logic is fine to me, but not sure whether we should apply this.
Jaegeuk, any comments?
Thanks,
Quoted 40 lines
Signed-off-by Jeongtae Park <[email protected]>--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-)fs/f2fs/f2fs.h +2
-0@@ -3402,6 +3402,8 @@ static inline void f2fs_putname(char *buf)__putname (buf); } +DEFINE_FREE(f2fs_putname, void *, if (_T) f2fs_putname(_T)) +static inline void *f2fs_kzalloc (struct f2fs_sb_info *sbi,size_t size,gfp_t flags) {fs/f2fs/file.c +3
-3@@ -4511,22 +4511,20 @@ static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, int rw) {struct inode *inode =file_inode (file); -char *buf, *path; + char *buf __free(f2fs_putname) = f2fs_getname(F2FS_I_SB(inode)); +char *path; - buf =f2fs_getname (F2FS_I_SB (inode));if (!buf)return ; path =dentry_path_raw (file_dentry (file), buf,PATH_MAX );if (IS_ERR (path)) - goto free_buf; +return ;if (rw ==WRITE )
fs/f2fs/file.c static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, · line 4530
Quoted 10 lines
fs/f2fs/file.c +0
-2trace_f2fs_datawrite_start (inode, pos, count, current->pid, path, current->comm); else trace_f2fs_dataread_start(inode, pos, count, current->pid, path, current->comm); -free_buf: -f2fs_putname (buf); } static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 6 lines · Chao Yu
Quoted 4 lines · On 2024/6/12 7:39, [email protected] wrote:
From: Jeongtae Park <[email protected]>
This patch adds a new scope based
f2fs_putname()cleanup to reduce the chances of forgetting af2fs_putname(). And doing so removes
Quoted 8 lines
Actually,
f2fs_trace_rw_file_path()won't change frequently, so the risk of forgettingf2fs_putname()here is very low.Quoted 1 line
a goto statement for error handling.
The code logic is fine to me, but not sure whether we should apply this.
Jaegeuk, any comments?
IMO, we don't need this since it's a very trivial path.
Quoted 42 lines
Thanks,
Quoted 39 lines
Signed-off-by Jeongtae Park <[email protected]>--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-)fs/f2fs/f2fs.h +2
-0@@ -3402,6 +3402,8 @@ static inline void f2fs_putname(char *buf)__putname (buf); } +DEFINE_FREE(f2fs_putname, void *, if (_T) f2fs_putname(_T)) +static inline void *f2fs_kzalloc (struct f2fs_sb_info *sbi,size_t size,gfp_t flags) {fs/f2fs/file.c +3
-3@@ -4511,22 +4511,20 @@ static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, int rw) {struct inode *inode =file_inode (file); -char *buf, *path; + char *buf __free(f2fs_putname) = f2fs_getname(F2FS_I_SB(inode)); +char *path; - buf =f2fs_getname (F2FS_I_SB (inode));if (!buf)return ; path =dentry_path_raw (file_dentry (file), buf,PATH_MAX );if (IS_ERR (path)) - goto free_buf; +return ;if (rw ==WRITE ) trace_f2fs_datawrite_start(inode, pos, count,
Quoted 8 lines
fs/f2fs/file.c static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count, · line 4530
Quoted 8 lines
fs/f2fs/file.c +0
-2current->pid, path, current->comm); else trace_f2fs_dataread_start(inode, pos, count, current->pid, path, current->comm); -free_buf: -f2fs_putname (buf); } static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel