[Cluster-devel] [PATCH] gfs2: Move a variable assignment behind a null pointer check in inode_go_dump()
Date: Thu, 13 Apr 2023 20:54:30 +0200 The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “inode_go_dump”. Thus avoid the risk for undefined behaviour by moving the assignment for the variable “inode” behind the null pointer check. This issue was detected by using the Coccinelle software. Fixes: 27a2660f1ef944724956d92e8a312b6da0936fae ("gfs2: Dump nrpages for inodes and their glocks") Signed-off-by: Markus Elfring --- fs/gfs2/glops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index b65950e76be5..6e33c8058059 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c @@ -535,12 +535,13 @@ static void inode_go_dump(struct seq_file *seq, struct gfs2_glock *gl, const char *fs_id_buf) { struct gfs2_inode *ip = gl->gl_object; - struct inode *inode = >i_inode; + struct inode *inode; unsigned long nrpages; if (ip == NULL) return; + inode = >i_inode; xa_lock_irq(>i_data.i_pages); nrpages = inode->i_data.nrpages; xa_unlock_irq(>i_data.i_pages); -- 2.40.0
Re: [Cluster-devel] gfs2: Delete an unnecessary check before brelse()
>> The brelse() function tests whether its argument is NULL >> and then returns immediately. >> Thus the test around the call is not needed. >> >> This issue was detected by using the Coccinelle software. > > The same applies to brelse() in gfs2_dir_no_add > (which Coccinelle apparently missed), Would you like to achieve that such source code analysis will be extended to corresponding header files? https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/fs/gfs2/dir.h?id=7dc4585e03786f84d6e9dc16caa3ba5b8b44d986#n33 > so let me fix that as well. Thanks for your positive feedback. Regards, Markus
[PATCH] gfs2: Delete an unnecessary check before brelse()
From: Markus Elfring Date: Tue, 3 Sep 2019 15:10:05 +0200 The brelse() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- fs/gfs2/dir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 6f35d19eec25..eb9c0578978f 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1463,8 +1463,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, sort_offset : entries, copied); out_free: for(i = 0; i < leaf; i++) - if (larr[i]) - brelse(larr[i]); + brelse(larr[i]); kvfree(larr); out: return error; -- 2.23.0
[PATCH] gfs2: Delete an unnecessary check before brelse()
From: Markus Elfring Date: Tue, 3 Sep 2019 15:10:05 +0200 The brelse() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- fs/gfs2/dir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 6f35d19eec25..eb9c0578978f 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c @@ -1463,8 +1463,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx, sort_offset : entries, copied); out_free: for(i = 0; i < leaf; i++) - if (larr[i]) - brelse(larr[i]); + brelse(larr[i]); kvfree(larr); out: return error; -- 2.23.0
[Cluster-devel] [PATCH 10/10] dlm: Delete an unnecessary variable initialisation in dlm_ls_start()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 09:56:55 +0200 The local variable "rv" is reassigned by a statement at the beginning. Thus omit the explicit initialisation. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/member.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 3e565034ff2e..3fda3832cf6a 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -670,7 +670,7 @@ int dlm_ls_stop(struct dlm_ls *ls) int dlm_ls_start(struct dlm_ls *ls) { - struct dlm_recover *rv = NULL, *rv_old; + struct dlm_recover *rv, *rv_old; struct dlm_config_node *nodes; int error, count; -- 2.12.2
[Cluster-devel] [PATCH 09/10] dlm: Improve a size determination in two functions
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 09:45:59 +0200 Replace the specification of two data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/member.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 92c601a11e38..3e565034ff2e 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -318,7 +318,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node) struct dlm_member *memb; int error; - memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS); + memb = kzalloc(sizeof(*memb), GFP_NOFS); if (!memb) return -ENOMEM; @@ -674,7 +674,7 @@ int dlm_ls_start(struct dlm_ls *ls) struct dlm_config_node *nodes; int error, count; - rv = kzalloc(sizeof(struct dlm_recover), GFP_NOFS); + rv = kzalloc(sizeof(*rv), GFP_NOFS); if (!rv) return -ENOMEM; -- 2.12.2
[Cluster-devel] [PATCH 08/10] dlm: Use kcalloc() in two functions
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 09:34:53 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus reuse the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. * Replace the specification of data structures by pointer dereferences to make the corresponding size determinations a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/member.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 89257699d4e4..92c601a11e38 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -217,8 +217,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size, } array_size = max + need; - - array = kzalloc(array_size * sizeof(struct dlm_slot), GFP_NOFS); + array = kcalloc(array_size, sizeof(*array), GFP_NOFS); if (!array) return -ENOMEM; @@ -491,8 +490,7 @@ void dlm_lsop_recover_done(struct dlm_ls *ls) return; num = ls->ls_num_nodes; - - slots = kzalloc(num * sizeof(struct dlm_slot), GFP_KERNEL); + slots = kcalloc(num, sizeof(*slots), GFP_KERNEL); if (!slots) return; -- 2.12.2
[Cluster-devel] [PATCH 07/10] dlm: Use kmalloc_array() in make_member_array()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 09:19:17 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/member.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 9c47f1c14a8b..89257699d4e4 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -405,8 +405,7 @@ static void make_member_array(struct dlm_ls *ls) } ls->ls_total_weight = total; - - array = kmalloc(sizeof(int) * total, GFP_NOFS); + array = kmalloc_array(total, sizeof(*array), GFP_NOFS); if (!array) return; -- 2.12.2
[Cluster-devel] [PATCH 06/10] dlm: Delete an error message for a failed memory allocation in dlm_recover_waiters_pre()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:55:43 +0200 Omit an extra message for a memory allocation failure in this function. Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/lock.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index ffadb817ad39..d4aaddec1b16 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -5120,10 +5120,8 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) int dir_nodeid; ms_stub = kmalloc(sizeof(*ms_stub), GFP_KERNEL); - if (!ms_stub) { - log_error(ls, "dlm_recover_waiters_pre no mem"); + if (!ms_stub) return; - } mutex_lock(>ls_waiters_mutex); -- 2.12.2
[Cluster-devel] [PATCH 05/10] dlm: Improve a size determination in dlm_recover_waiters_pre()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:48:29 +0200 Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index fd6fe55bedae..ffadb817ad39 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -5119,7 +5119,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) int wait_type, stub_unlock_result, stub_cancel_result; int dir_nodeid; - ms_stub = kmalloc(sizeof(struct dlm_message), GFP_KERNEL); + ms_stub = kmalloc(sizeof(*ms_stub), GFP_KERNEL); if (!ms_stub) { log_error(ls, "dlm_recover_waiters_pre no mem"); return; -- 2.12.2
[Cluster-devel] [PATCH 04/10] dlm: Use kcalloc() in dlm_scan_waiters()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:38:49 +0200 A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index 6df332296c66..fd6fe55bedae 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -1426,7 +1426,7 @@ void dlm_scan_waiters(struct dlm_ls *ls) if (!num_nodes) { num_nodes = ls->ls_num_nodes; - warned = kzalloc(num_nodes * sizeof(int), GFP_KERNEL); + warned = kcalloc(num_nodes, sizeof(int), GFP_KERNEL); } if (!warned) continue; -- 2.12.2
[Cluster-devel] [PATCH 03/10] dlm: Improve a size determination in table_seq_start()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:34:27 +0200 Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/debug_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 551e0f8dbe0d..fa08448e35dd 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -435,7 +435,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos) if (bucket >= ls->ls_rsbtbl_size) return NULL; - ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS); + ri = kzalloc(sizeof(*ri), GFP_NOFS); if (!ri) return NULL; if (n == 0) -- 2.12.2
[Cluster-devel] [PATCH 02/10] dlm: Add spaces for better code readability
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:22:35 +0200 The script "checkpatch.pl" pointed information out like the following. CHECK: spaces preferred around that '+' (ctx:VxV) Thus fix the affected source code places. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/debug_fs.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index 464218c6b502..551e0f8dbe0d 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -741,7 +741,7 @@ void dlm_delete_debug_file(struct dlm_ls *ls) int dlm_create_debug_file(struct dlm_ls *ls) { - char name[DLM_LOCKSPACE_LEN+8]; + char name[DLM_LOCKSPACE_LEN + 8]; /* format 1 */ @@ -756,7 +756,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) /* format 2 */ memset(name, 0, sizeof(name)); - snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name); + snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name); ls->ls_debug_locks_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, @@ -769,7 +769,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) /* format 3 */ memset(name, 0, sizeof(name)); - snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name); + snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_all", ls->ls_name); ls->ls_debug_all_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, @@ -782,7 +782,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) /* format 4 */ memset(name, 0, sizeof(name)); - snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_toss", ls->ls_name); + snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_toss", ls->ls_name); ls->ls_debug_toss_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, @@ -793,7 +793,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) goto fail; memset(name, 0, sizeof(name)); - snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name); + snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name); ls->ls_debug_waiters_dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, -- 2.12.2
[Cluster-devel] [PATCH 01/10] dlm: Replace six seq_puts() calls by seq_putc()
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 08:12:31 +0200 Six single characters (line breaks) should be put into a sequence. Thus use the corresponding function "seq_putc". This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/dlm/debug_fs.c | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c index ca7089aeadab..464218c6b502 100644 --- a/fs/dlm/debug_fs.c +++ b/fs/dlm/debug_fs.c @@ -68,7 +68,7 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb, if (lkb->lkb_wait_type) seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); - seq_puts(s, "\n"); + seq_putc(s, '\n'); } static void print_format1(struct dlm_rsb *res, struct seq_file *s) @@ -111,7 +111,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s) } if (rsb_flag(res, RSB_VALNOTVALID)) seq_puts(s, " (INVALID)"); - seq_puts(s, "\n"); + seq_putc(s, '\n'); if (seq_has_overflowed(s)) goto out; } @@ -156,7 +156,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s) lkb->lkb_id, print_lockmode(lkb->lkb_rqmode)); if (lkb->lkb_wait_type) seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); - seq_puts(s, "\n"); + seq_putc(s, '\n'); if (seq_has_overflowed(s)) goto out; } @@ -287,7 +287,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s) else seq_printf(s, " %02x", (unsigned char)r->res_name[i]); } - seq_puts(s, "\n"); + seq_putc(s, '\n'); if (seq_has_overflowed(s)) goto out; @@ -298,7 +298,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s) for (i = 0; i < lvblen; i++) seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]); - seq_puts(s, "\n"); + seq_putc(s, '\n'); if (seq_has_overflowed(s)) goto out; @@ -361,8 +361,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s) else seq_printf(s, " %02x", (unsigned char)r->res_name[i]); } - seq_puts(s, "\n"); - + seq_putc(s, '\n'); unlock_rsb(r); } -- 2.12.2
[Cluster-devel] [PATCH 00/10] fs-DLM: Fine-tuning for several function implementations
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Sat, 6 May 2017 10:15:25 +0200 Some update suggestions were taken into account from static source code analysis. Markus Elfring (10): Replace six seq_puts() calls by seq_putc() Add spaces for better code readability Improve a size determination in table_seq_start() Use kcalloc() in dlm_scan_waiters() Improve a size determination in dlm_recover_waiters_pre() Delete an error message for a failed memory allocation in dlm_recover_waiters_pre() Use kmalloc_array() in make_member_array() Use kcalloc() in two functions Improve a size determination in two functions Delete an unnecessary variable initialisation in dlm_ls_start() fs/dlm/debug_fs.c | 25 - fs/dlm/lock.c | 8 +++- fs/dlm/member.c | 15 ++- 3 files changed, 21 insertions(+), 27 deletions(-) -- 2.12.2
[Cluster-devel] [PATCH] GFS2: Delete an unnecessary check before the function call "iput"
From: Markus Elfring <elfr...@users.sourceforge.net> Date: Wed, 4 Nov 2015 21:23:43 +0100 The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net> --- fs/gfs2/ops_fstype.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index baab99b..1f9de17 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -910,8 +910,7 @@ fail_qc_i: fail_ut_i: iput(sdp->sd_sc_inode); fail: - if (pn) - iput(pn); + iput(pn); return error; } -- 2.6.2
Re: [Cluster-devel] [PATCH 00/39] drop null test before destroy functions
> Recent commits to kernel/git/torvalds/linux.git have made the following > functions able to tolerate NULL arguments: > > kmem_cache_destroy (commit 3942d29918522) > mempool_destroy (commit 4e3ca3e033d1) > dma_pool_destroy (commit 44d7175da6ea) How do you think about to extend an other SmPL script? Related topic: scripts/coccinelle/free: Delete NULL test before freeing functions https://systeme.lip6.fr/pipermail/cocci/2015-May/001960.html https://www.mail-archive.com/cocci@systeme.lip6.fr/msg01855.html > If these changes are OK, I will address the remainder later. Would anybody like to reuse my general SmPL approach for similar source code clean-up? Regards, Markus
[Cluster-devel] [PATCH] fs-DLM: Delete unnecessary checks before the function call kfree
From: Markus Elfring elfr...@users.sourceforge.net Date: Fri, 26 Jun 2015 14:00:06 +0200 The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring elfr...@users.sourceforge.net --- fs/dlm/lockspace.c | 6 ++ fs/dlm/memory.c| 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index f3e7278..41c53b3 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -673,10 +673,8 @@ static int new_lockspace(const char *name, const char *cluster, kfree(ls-ls_recover_buf); out_lkbidr: idr_destroy(ls-ls_lkbidr); - for (i = 0; i DLM_REMOVE_NAMES_MAX; i++) { - if (ls-ls_remove_names[i]) - kfree(ls-ls_remove_names[i]); - } + for (i = 0; i DLM_REMOVE_NAMES_MAX; i++) + kfree(ls-ls_remove_names[i]); out_rsbtbl: vfree(ls-ls_rsbtbl); out_lsfree: diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 7cd24bc..2d2eaa0 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb) struct dlm_user_args *ua; ua = lkb-lkb_ua; if (ua) { - if (ua-lksb.sb_lvbptr) - kfree(ua-lksb.sb_lvbptr); + kfree(ua-lksb.sb_lvbptr); kfree(ua); } } -- 2.4.4
Re: [Cluster-devel] [PATCH] fs: dlm: lockspace.c: removal of unnecessary check before calling kfree()
kfree() checks its argument. It is therefore unnecessary to do this twice. This issue was detected using Coccinelle. Would you like to integrate my update suggestion 'fs-DLM: Deletion of unnecessary checks before the function call kfree'? https://lkml.org/lkml/2014/11/29/88 http://article.gmane.org/gmane.linux.kernel/1840524 https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg778279.html Regards, Markus
Re: [Cluster-devel] [PATCH] fs: dlm: lockspace.c: removal of unnecessary check before calling kfree()
https://lkml.org/lkml/2014/11/29/88 http://article.gmane.org/gmane.linux.kernel/1840524 https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg778279.html I'll drop that too :) Would you like to add any tags to my update suggestion? Are you looking for more opportunities around clean-up of such safety checks in Linux source code? Regards, Markus
[Cluster-devel] [PATCH 1/1] fs-DLM: Deletion of unnecessary checks before the function call kfree
From: Markus Elfring elfr...@users.sourceforge.net Date: Sat, 29 Nov 2014 17:55:39 +0100 The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring elfr...@users.sourceforge.net --- fs/dlm/lockspace.c | 3 +-- fs/dlm/memory.c| 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index f3e7278..b660b93 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -674,8 +674,7 @@ static int new_lockspace(const char *name, const char *cluster, out_lkbidr: idr_destroy(ls-ls_lkbidr); for (i = 0; i DLM_REMOVE_NAMES_MAX; i++) { - if (ls-ls_remove_names[i]) - kfree(ls-ls_remove_names[i]); + kfree(ls-ls_remove_names[i]); } out_rsbtbl: vfree(ls-ls_rsbtbl); diff --git a/fs/dlm/memory.c b/fs/dlm/memory.c index 7cd24bc..2d2eaa0 100644 --- a/fs/dlm/memory.c +++ b/fs/dlm/memory.c @@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb) struct dlm_user_args *ua; ua = lkb-lkb_ua; if (ua) { - if (ua-lksb.sb_lvbptr) - kfree(ua-lksb.sb_lvbptr); + kfree(ua-lksb.sb_lvbptr); kfree(ua); } } -- 2.1.3
[Cluster-devel] [PATCH 1/1] GFS2: Deletion of unnecessary checks before two function calls
From: Markus Elfring elfr...@users.sourceforge.net Date: Tue, 18 Nov 2014 11:31:23 +0100 The functions iput() and put_pid() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring elfr...@users.sourceforge.net --- fs/gfs2/glock.c | 3 +-- fs/gfs2/ops_fstype.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 7f513b1..f4aa085 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -836,8 +836,7 @@ void gfs2_holder_reinit(unsigned int state, unsigned flags, struct gfs2_holder * gh-gh_flags = flags; gh-gh_iflags = 0; gh-gh_ip = (unsigned long)__builtin_return_address(0); - if (gh-gh_owner_pid) - put_pid(gh-gh_owner_pid); + put_pid(gh-gh_owner_pid); gh-gh_owner_pid = get_pid(task_pid(current)); } diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index d3eae24..272ff81 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -918,8 +918,7 @@ fail_qc_i: fail_ut_i: iput(sdp-sd_sc_inode); fail: - if (pn) - iput(pn); + iput(pn); return error; } -- 2.1.3