diff mbox series

fs/UBIFS: make 'sum' definition closer to where it is used

Message ID 1519785723-105686-1-git-send-email-liu.song11@zte.com.cn
State Changes Requested
Delegated to: Richard Weinberger
Headers show
Series fs/UBIFS: make 'sum' definition closer to where it is used | expand

Commit Message

Liu Song Feb. 28, 2018, 2:42 a.m. UTC
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(-)

Comments

Richard Weinberger March 1, 2018, 4:26 p.m. UTC | #1
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
diff mbox series

Patch

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;
 		/*