Re: [bug report] zram: unlock slot during recompression
From: Sergey Senozhatsky <senozhatsky@chromium.org>
Date: 2025-01-30 08:07:24
On (25/01/30 09:08), Dan Carpenter wrote:
Commit 7ec2cb65ef0d ("zram: unlock slot during recompression") from
Jan 27, 2025 (linux-next), leads to the following Smatch static
checker warning:
drivers/block/zram/zram_drv.c:1960 recompress_slot()
warn: passing freed memory 'zstrm' (line 1943)Hi Dan, Thank you for the report. [..]
1923 for (; prio < prio_max; prio++) {
1924 if (!zram->comps[prio])
1925 continue;
1926
1927 num_recomps++;
1928 zstrm = zcomp_stream_get(zram->comps[prio]);
1929 src = kmap_local_page(page);
1930 ret = zcomp_compress(zram->comps[prio], zstrm,
1931 src, &comp_len_new);
1932 kunmap_local(src);
1933
1934 if (ret)
1935 break;
1936
1937 class_index_new = zs_lookup_class_index(zram->mem_pool,
1938 comp_len_new);
1939
1940 /* Continue until we make progress */
1941 if (class_index_new >= class_index_old ||
1942 (threshold && comp_len_new >= threshold)) {
1943 zcomp_stream_put(zram->comps[prio], zstrm);
Imagine we hit this continue path. The right thing is probably to set
zstrm = NULL before the continue or it might be to set ret = -EINVAL.We still need to make sure that ZRAM_INCOMPRESSIBLE is set appropriately, so zstrm = NULL won't do the trick. Let me take a look.