[PATCH 3/3] dm-pcache: remove unused 'allocated' variable in cache_data_alloc()

From: jianyungao89

Date: Fri Jul 17 2026 - 04:44:51 EST


From: Jianyun Gao <jianyungao89@xxxxxxxxx>

The 'allocated' variable is never non-zero when its value is consumed.
'to_alloc' was always equal to key->len, so replace them with key->len
directly.

Signed-off-by: Jianyun Gao <jianyungao89@xxxxxxxxx>
---
drivers/md/dm-pcache/cache_req.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-pcache/cache_req.c b/drivers/md/dm-pcache/cache_req.c
index cc5747d472e9..b2cb3c7615d4 100644
--- a/drivers/md/dm-pcache/cache_req.c
+++ b/drivers/md/dm-pcache/cache_req.c
@@ -39,13 +39,11 @@ static int cache_data_alloc(struct pcache_cache *cache, struct pcache_cache_key
struct pcache_cache_pos *head_pos;
struct pcache_cache_segment *cache_seg;
u32 seg_remain;
- u32 allocated = 0, to_alloc;
int ret = 0;

preempt_disable();
data_head = get_data_head(cache);
again:
- to_alloc = key->len - allocated;
if (!data_head->head_pos.cache_seg) {
seg_remain = 0;
} else {
@@ -57,10 +55,9 @@ static int cache_data_alloc(struct pcache_cache *cache, struct pcache_cache_key
seg_remain = cache_seg_remain(head_pos);
}

- if (seg_remain > to_alloc) {
+ if (seg_remain > key->len) {
/* If remaining space in segment is sufficient for the cache key, allocate it. */
- cache_pos_advance(head_pos, to_alloc);
- allocated += to_alloc;
+ cache_pos_advance(head_pos, key->len);
cache_seg_get(cache_seg);
} else if (seg_remain) {
/* If remaining space is not enough, allocate the remaining space and adjust the cache key length. */
--
2.34.1