Skip to contentSkip to conversation

dm: add missing unlock on in dm_keyslot_evict()

PATCH In review Dan Carpenter 4 participants 6 messages Apr 30, 2025 – May 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: add missing unlock on in dm_keyslot_evict()

We need to call dm_put_live_table() even if dm_get_live_table() returns NULL.

Fixes 9355a9eb21a5 ("dm: support key eviction from keyslot managers of underlying devices")
---
 drivers/md/dm-table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-table.c +2 -1
index 933e01f3fab4..1a7e2623069b 100644
@@ -1177,7 +1177,7 @@ static int dm_keyslot_evict(struct blk_crypto_profile *profile,
 
 	t = dm_get_live_table(md, &srcu_idx);
 	if (!t)
-		return 0;
+		goto put_live_table;
 
 	for (unsigned int i = 0; i < t->num_targets; i++) {
 		struct dm_target *ti = dm_table_get_target(t, i);
@@ -1188,6 +1188,7 @@ static int dm_keyslot_evict(struct blk_crypto_profile *profile,
 					  (void *)key);
 	}
 
+put_live_table:
 	dm_put_live_table(md, srcu_idx);
 	return 0;
 }
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

We need to call dm_put_live_table() even if dm_get_live_table() returns NULL.

Fixes 9355a9eb21a5 ("dm: support key eviction from keyslot managers of underlying devices")
---
 drivers/md/dm-table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

But that's an awfully error-prone API.

dm_blk_report_zones() gets this wrong too.

- Eric

#2 lore raw
Quoted 11 lines · Eric Biggers
Quoted 9 lines · Dan Carpenter

We need to call dm_put_live_table() even if dm_get_live_table() returns NULL.

Fixes 9355a9eb21a5 ("dm: support key eviction from keyslot managers of underlying devices")
---
 drivers/md/dm-table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 3 lines

But that's an awfully error-prone API.

Yep.

Quoted 2 lines

dm_blk_report_zones() gets this wrong too.

Ugh... dm_blk_report_zones() is too weird for my static checker tool. The checker is looking very specifically for error paths with missing unlocks.

regards,
dan carpenter

maintainer
#3 lore raw
Quoted 16 lines · Dan Carpenter
Quoted 11 lines · Eric Biggers
Quoted 9 lines · Dan Carpenter

We need to call dm_put_live_table() even if dm_get_live_table() returns NULL.

Fixes 9355a9eb21a5 ("dm: support key eviction from keyslot managers of underlying devices")
---
 drivers/md/dm-table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 3 lines

But that's an awfully error-prone API.

Quoted 8 lines

Yep.

Quoted 2 lines

dm_blk_report_zones() gets this wrong too.

Ugh... dm_blk_report_zones() is too weird for my static checker tool. The checker is looking very specifically for error paths with missing unlocks.

Ben already tried to fix it in dm_blk_report_zones (see the linux-dm git, for-next branch) - but his fix is incorrect because the "if" condition for dm_get_live_table and dm_put_live_table differs. I'll update his patch to fix this mismatch.

Mikulas

Quoted 3 lines

regards,
dan carpenter

maintainer
#4 lore raw
Quoted 6 lines · Mikulas Patocka

Ben already tried to fix it in dm_blk_report_zones (see the linux-dm git, for-next branch) - but his fix is incorrect because the "if" condition for dm_get_live_table and dm_put_live_table differs. I'll update his patch to fix this mismatch.

Mikulas

I fixed it in the Ben's patch "dm: fix dm_blk_report_zones". Ben, please review it - it's the patch 37f53a2c60d03743e0eacf7a0c01c279776fef4e in the linux-dm repository, for-next branch.

Mikulas

#5 lore raw
Quoted 9 lines · Mikulas Patocka
Quoted 5 lines · Mikulas Patocka

Ben already tried to fix it in dm_blk_report_zones (see the linux-dm git, for-next branch) - but his fix is incorrect because the "if" condition for dm_get_live_table and dm_put_live_table differs. I'll update his patch to fix this mismatch.

Quoted 5 lines
Quoted 1 line

Mikulas

I fixed it in the Ben's patch "dm: fix dm_blk_report_zones". Ben, please review it - it's the patch 37f53a2c60d03743e0eacf7a0c01c279776fef4e in the linux-dm repository, for-next branch.

Your changes look good. Thanks for catching that.
-Ben

Quoted 2 lines

Mikulas