Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752297AbbLKSYh (ORCPT ); Fri, 11 Dec 2015 13:24:37 -0500 Received: from mout.web.de ([212.227.17.11]:51216 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751054AbbLKSYf (ORCPT ); Fri, 11 Dec 2015 13:24:35 -0500 Subject: [PATCH 1/2] zram: Less checks in zram_bvec_write() after error detection To: LKML , Minchan Kim , Nitin Gupta , Sergey Senozhatsky References: <566ABCD9.1060404@users.sourceforge.net> <566B13C1.50907@users.sourceforge.net> Cc: kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <566B14DA.1080709@users.sourceforge.net> Date: Fri, 11 Dec 2015 19:24:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <566B13C1.50907@users.sourceforge.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:PItsI4rF7DpSlDDM7yYeLJScGmblhVjR5QRbaUUiyAPE0038QgT X79+e9nj61lhDRQmvmMfGTmlQaHsgxKedXKYTbBZqYicYpCZSlrQazwn2nWAbLtDQgt0JEJ 8QN4XxY1gcqdQG0a2HICDMRsVLZPpGhp5mWzb+ppAVG558wyEUV6hVOsTPey56m5cM+V4rY GKjpKZDKE+ObT62r6hCcQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:Cpodp+/1KEA=:Kt1sfmDjDKSYUxsR6n9TgX Dg5pa46ngFru2XXPrQFq33EzWAj/xVYOEJv7hbHuWU2NUgkRllepU9qUiUMqpPlXrCLesj0jV j27DbgnlGrjzzl58fwiGGCT89Acykjax3h4ZgiwbjCPvIlub8OzJuuU4kLW15mclWKGR0MT34 c/uLHW48YZxQvriHcQFeQSMqk2nbaXYxdS2ch5V6ePMg1s0/spivaM5e2LnrfPwqVXXKbeCBL jPtb26uJf+P4rd3EOP9ov0SeiHgdj5TyGxuUbJSIQat6pz3NxU0WbuTwE4yQvOp2K/UnM7EKc tOU+K1vf909+P9vpVP/VfFLLSenunyX+zCYH9vNigciSsUYfrloZ7kblZizD3eZb1u4QoowHG odv6rZsr4TMPhumaLZ/Nkii844MVQCP2sKnrd/VjWjh4WIzgtgqLYVACeS299ETkW7gm+1q27 OdNFovbH8f7/KNMX3P1TZ/YIBUy3V+y6mhSPcjiu4u1HJ78gWWm3V0GkRKiWmKlKlDIxHf9xb KYXC3XamZiYGR3LinAZ6Y7kLKfvDt9FlsXT5dzxb7RmFxsemVCSC3kH6zYTdIQ2+T6obkeVCm LhtJklRfRdVMPeRSWDUr8wUuXq5pFEy+5T/ypx02ym36NdmA3rQm8+BLpIb+9TSQXeK+8+4QA U2XFDFliq+DU3SuERwwFQv20UleAPUznXX07WWzppZ7YbH6rHpWInCFFyDYTz7SVuXJlBk6Ce S56L+v77IDXHiHuCFRUtSfKWxhgNeZETFganKE8Q/MIndfNoe+ThfpgRjet9NIuJvHbQrLByM ukoYB4u Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3557 Lines: 114 From: Markus Elfring Date: Fri, 11 Dec 2015 18:20:59 +0100 This issue was detected by using the Coccinelle software. A few checks could be repeated by the zram_bvec_write() function at two places even if the passed variables contained a null pointer. * This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention. * Let us return directly if a memory allocation failed. * Drop unnecessary initialisations for the variables "uncmem" and "zstrm" then. Signed-off-by: Markus Elfring --- drivers/block/zram/zram_drv.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 47915d7..69d7fcd 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -652,9 +652,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, size_t clen; unsigned long handle; struct page *page; - unsigned char *user_mem, *cmem, *src, *uncmem = NULL; + unsigned char *user_mem, *cmem, *src, *uncmem; struct zram_meta *meta = zram->meta; - struct zcomp_strm *zstrm = NULL; + struct zcomp_strm *zstrm; unsigned long alloced_pages; page = bvec->bv_page; @@ -664,13 +664,11 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, * before to write the changes. */ uncmem = kmalloc(PAGE_SIZE, GFP_NOIO); - if (!uncmem) { - ret = -ENOMEM; - goto out; - } + if (!uncmem) + return -ENOMEM; ret = zram_decompress_page(zram, uncmem, index); if (ret) - goto out; + goto free_uncmem; } zstrm = zcomp_strm_find(zram->comp); @@ -696,7 +694,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, atomic64_inc(&zram->stats.zero_pages); ret = 0; - goto out; + goto check_strm; } ret = zcomp_compress(zram->comp, zstrm, uncmem, &clen); @@ -708,7 +706,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, if (unlikely(ret)) { pr_err("Compression failed! err=%d\n", ret); - goto out; + goto check_strm; } src = zstrm->buffer; if (unlikely(clen > max_zpage_size)) { @@ -722,7 +720,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, pr_err("Error allocating memory for compressed page: %u, size=%zu\n", index, clen); ret = -ENOMEM; - goto out; + goto check_strm; } alloced_pages = zs_get_total_pages(meta->mem_pool); @@ -731,7 +729,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, if (zram->limit_pages && alloced_pages > zram->limit_pages) { zs_free(meta->mem_pool, handle); ret = -ENOMEM; - goto out; + goto check_strm; } cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO); @@ -762,11 +760,13 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, /* Update stats */ atomic64_add(clen, &zram->stats.compr_data_size); atomic64_inc(&zram->stats.pages_stored); -out: +check_strm: if (zstrm) zcomp_strm_release(zram->comp, zstrm); - if (is_partial_io(bvec)) + if (is_partial_io(bvec)) { +free_uncmem: kfree(uncmem); + } return ret; } -- 2.6.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/