From: Jianyun Gao <[email protected]>

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 <[email protected]>
---
 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


Reply via email to