linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/UBIFS: make 'sum' definition closer to where it is used
@ 2018-02-28  2:42 Liu Song
  2018-03-01 16:26 ` Richard Weinberger
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Song @ 2018-02-28  2:42 UTC (permalink / raw)
  To: richard, dedekind1, adrian.hunter
  Cc: linux-mtd, linux-kernel, jiang.biao2, zhong.weidong, liu.song11

Local var sum is only used in one branch, and it may be not used if 
it is defined outside the branch. Try to move the definition into 
the branch to make it closer to where it is actually used. 

Signed-off-by: Liu Song <liu.song11@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
---
 fs/ubifs/find.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/ubifs/find.c b/fs/ubifs/find.c
index 2dcf3d4..4eb11c1 100644
--- a/fs/ubifs/find.c
+++ b/fs/ubifs/find.c
@@ -233,7 +233,7 @@ static const struct ubifs_lprops *scan_for_dirty(struct ubifs_info *c,
 int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
 			 int min_space, int pick_free)
 {
-	int err = 0, sum, exclude_index = pick_free == 2 ? 1 : 0;
+	int err = 0, exclude_index = pick_free == 2 ? 1 : 0;
 	const struct ubifs_lprops *lp = NULL, *idx_lp = NULL;
 	struct ubifs_lpt_heap *heap, *idx_heap;
 
@@ -285,6 +285,7 @@ int ubifs_find_dirty_leb(struct ubifs_info *c, struct ubifs_lprops *ret_lp,
 	idx_heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1];
 
 	if (idx_heap->cnt && !exclude_index) {
+		int sum;
 		idx_lp = idx_heap->arr[0];
 		sum = idx_lp->free + idx_lp->dirty;
 		/*
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/UBIFS: make 'sum' definition closer to where it is used
  2018-02-28  2:42 [PATCH] fs/UBIFS: make 'sum' definition closer to where it is used Liu Song
@ 2018-03-01 16:26 ` Richard Weinberger
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2018-03-01 16:26 UTC (permalink / raw)
  To: Liu Song
  Cc: dedekind1, adrian.hunter, linux-mtd, linux-kernel, jiang.biao2,
	zhong.weidong

Am Mittwoch, 28. Februar 2018, 03:42:03 CET schrieb Liu Song:
> Local var sum is only used in one branch, and it may be not used if
> it is defined outside the branch. Try to move the definition into
> the branch to make it closer to where it is actually used.

Does this fix a problem?
I'm not a huge fan of defining variables in the middle of functions unless it 
makes the code really better.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-01 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28  2:42 [PATCH] fs/UBIFS: make 'sum' definition closer to where it is used Liu Song
2018-03-01 16:26 ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).