Skip to contentSkip to conversation

dm thin metadata: Remove unused local variable when create thin and snap

PATCH New Huaisheng Ye 1 participant 1 message Sep 15, 2020 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm thin metadata: Remove unused local variable when create thin and snap

From: Huaisheng Ye <[email protected]>

The local variable disk details is not used during the creating of thin & snap devices. Remove them from dm-thin-metadata, and add pointer validity check for pointer value in btree_lookup_raw. Skip memory copy when the caller doesn't need the value.

---
 drivers/md/dm-thin-metadata.c         | 6 ++----
 drivers/md/persistent-data/dm-btree.c | 3 ++-
 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/md/dm-thin-metadata.c +2 -4
index b461836..6ebb212 100644
@@ -1051,12 +1051,11 @@ static int __create_thin(struct dm_pool_metadata *pmd,
 	int r;
 	dm_block_t dev_root;
 	uint64_t key = dev;
-	struct disk_device_details details_le;
 	struct dm_thin_device *td;
 	__le64 value;
 
 	r = dm_btree_lookup(&pmd->details_info, pmd->details_root,
-			    &key, &details_le);
+			    &key, NULL);
 	if (!r)
 		return -EEXIST;
 
@@ -1129,12 +1128,11 @@ static int __create_snap(struct dm_pool_metadata *pmd,
 	dm_block_t origin_root;
 	uint64_t key = origin, dev_key = dev;
 	struct dm_thin_device *td;
-	struct disk_device_details details_le;
 	__le64 value;
 
 	/* check this device is unused */
 	r = dm_btree_lookup(&pmd->details_info, pmd->details_root,
-			    &dev_key, &details_le);
+			    &dev_key, NULL);
 	if (!r)
 		return -EEXIST;
 
drivers/md/persistent-data/dm-btree.c +2 -1
index 8aae062..ef6e78d 100644
@@ -366,7 +366,8 @@ static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
 	} while (!(flags & LEAF_NODE));
 
 	*result_key = le64_to_cpu(ro_node(s)->keys[i]);
-	memcpy(v, value_ptr(ro_node(s), i), value_size);
+	if (v)
+		memcpy(v, value_ptr(ro_node(s), i), value_size);
 
 	return 0;
 }
Signature · 1 line
1.8.3.1