Skip to contentSkip to conversation

fs: udf: avoid assignment in condition when selecting allocation goal

PATCH In review Adarsh Das 2 participants 2 messages Feb 6 UDF filesystem

lore
Share & tools
lore

Adarsh Das

author
#0 lore raw

PATCH 1/1 fs: udf: avoid assignment in condition when selecting allocation goal

Avoid assignment inside an if condition when choosing the block allocation goal in inode_getblk(), and make the priority order explicit. No functional change.

---
 fs/udf/inode.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
fs/udf/inode.c +5 -6
index 7fae8002344a..4a4cb42319af 100644
@@ -734,7 +734,7 @@ static int inode_getblk(struct inode *inode, struct udf_map_rq *map)
 	sector_t offset = 0;
 	int8_t etype, tmpetype;
 	struct udf_inode_info *iinfo = UDF_I(inode);
-	udf_pblk_t goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
+	udf_pblk_t goal = 0, pgoal = 0;
 	int lastblock = 0;
 	bool isBeyondEOF = false;
 	int ret = 0;
@@ -893,11 +893,10 @@ static int inode_getblk(struct inode *inode, struct udf_map_rq *map)
 	else { /* otherwise, allocate a new block */
 		if (iinfo->i_next_alloc_block == map->lblk)
 			goal = iinfo->i_next_alloc_goal;
-
-		if (!goal) {
-			if (!(goal = pgoal)) /* XXX: what was intended here? */
-				goal = iinfo->i_location.logicalBlockNum + 1;
-		}
+		else if (pgoal)
+			goal = pgoal;
+		else
+			goal = iinfo->i_location.logicalBlockNum + 1;
 
 		newblocknum = udf_new_block(inode->i_sb, inode,
 				iinfo->i_location.partitionReferenceNum,
Signature · 1 line
2.53.0
#1 lore raw
Quoted 8 lines · Adarsh Das

Avoid assignment inside an if condition when choosing the block allocation goal in inode_getblk(), and make the priority order explicit. No functional change.

---
 fs/udf/inode.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Thanks for the cleanup. I agree it is desirable. But:

fs/udf/inode.c static int inode_getblk(struct inode *inode, struct udf_map_rq *map) · line 896

Quoted 10 lines
fs/udf/inode.c +1 -5
@@ -893,11 +893,10 @@ static int inode_getblk(struct inode *inode, struct udf_map_rq *map)
 	else { /* otherwise, allocate a new block */
 		if (iinfo->i_next_alloc_block == map->lblk)
 			goal = iinfo->i_next_alloc_goal;
-
-		if (!goal) {
-			if (!(goal = pgoal)) /* XXX: what was intended here? */
-				goal = iinfo->i_location.logicalBlockNum + 1;
-		}
+		else if (pgoal)

I don't think the 'else' here is correct. When map->lblk is zero, it can happen that i_next_alloc_goal will be 0 as well. Previously we've used iinfo->i_location.logicalBlockNum + 1 for such cases but now we would leave 0 in 'goal'. Anyway, I'll fix this up on commit so this is just informational.

Honza

Quoted 9 lines
fs/udf/inode.c +3 -0
+			goal = pgoal;
+		else
+			goal = iinfo->i_location.logicalBlockNum + 1;
 
 		newblocknum = udf_new_block(inode->i_sb, inode,
 				iinfo->i_location.partitionReferenceNum,
Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR