[PATCH] dm-writecache: drop the lock on an 'impossible' path

From: Mikulas Patocka
Date: Mon Aug 08 2022 - 10:50:30 EST




On Fri, 5 Aug 2022, Dan Carpenter wrote:

> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: b44f2fd87919b5ae6e1756d4c7ba2cbba22238e1
> commit: df699cc16ea5ef93a917676dcdd4376e02860ad5 dm writecache: report invalid return from writecache_map helpers
> config: arc-randconfig-m041-20220804 (https://download.01.org/0day-ci/archive/20220805/202208050301.roHRxc6O-lkp@xxxxxxxxx/config)
> compiler: arc-elf-gcc (GCC) 12.1.0
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
>
> smatch warnings:
> drivers/md/dm-writecache.c:1554 writecache_map() warn: inconsistent returns '&wc->lock'.

Hi

Here I'm sending a patch for this warning.

Mikulas



From: Mikulas Patocka <mpatocka@xxxxxxxxxx>

There's a smatch warning "inconsistent returns '&wc->lock'" in
dm-writecache. The reason for the warning is that the function
writecache_map doesn't drop the lock on the impossible path. This patch
adds wc_unlock after the BUG statement (so that it will be compiled-away
anyway) to fix the warning.

Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

Index: linux-2.6/drivers/md/dm-writecache.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-writecache.c
+++ linux-2.6/drivers/md/dm-writecache.c
@@ -1598,7 +1598,8 @@ done:

default:
BUG();
- return -1;
+ wc_unlock(wc);
+ return DM_MAPIO_KILL;
}
}