From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38B50C433DF for ; Mon, 22 Jun 2020 19:55:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D5B192076E for ; Mon, 22 Jun 2020 19:55:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5B192076E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 693406B0006; Mon, 22 Jun 2020 15:55:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 643906B000E; Mon, 22 Jun 2020 15:55:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50C036B0030; Mon, 22 Jun 2020 15:55:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id 382446B0006 for ; Mon, 22 Jun 2020 15:55:23 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B299084D51 for ; Mon, 22 Jun 2020 19:55:22 +0000 (UTC) X-FDA: 76957902084.06.prose72_1b08ef026e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 81102100D0BE6 for ; Mon, 22 Jun 2020 19:55:22 +0000 (UTC) X-HE-Tag: prose72_1b08ef026e35 X-Filterd-Recvd-Size: 4941 Received: from huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 19:55:21 +0000 (UTC) Received: from dggemi401-hub.china.huawei.com (unknown [172.30.72.54]) by Forcepoint Email with ESMTP id 2A294B9ADE7E2F007BED; Tue, 23 Jun 2020 03:55:18 +0800 (CST) Received: from DGGEMI525-MBS.china.huawei.com ([169.254.6.126]) by dggemi401-hub.china.huawei.com ([10.3.17.134]) with mapi id 14.03.0487.000; Tue, 23 Jun 2020 03:55:14 +0800 From: "Song Bao Hua (Barry Song)" To: Dan Carpenter , Colin King CC: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , Stephen Rothwell , "linux-mm@kvack.org" , "kernel-janitors@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH][next] mm/zswap: fix a couple of memory leaks and rework kzalloc failure check Thread-Topic: [PATCH][next] mm/zswap: fix a couple of memory leaks and rework kzalloc failure check Thread-Index: AQHWSKrZL+ewyBWBGU2y0eVQs72K+KjkblmAgACdXuA= Date: Mon, 22 Jun 2020 19:55:14 +0000 Message-ID: References: <20200622153546.49880-1-colin.king@canonical.com> <20200622182816.GF4151@kadam> In-Reply-To: <20200622182816.GF4151@kadam> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.126.202.192] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 81102100D0BE6 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > -----Original Message----- > From: Dan Carpenter [mailto:dan.carpenter@oracle.com] > Sent: Tuesday, June 23, 2020 6:28 AM > To: Colin King > Cc: Seth Jennings ; Dan Streetman > ; Vitaly Wool ; Andrew > Morton ; Song Bao Hua (Barry Song) > ; Stephen Rothwell ; > linux-mm@kvack.org; kernel-janitors@vger.kernel.org; > linux-kernel@vger.kernel.org > Subject: Re: [PATCH][next] mm/zswap: fix a couple of memory leaks and > rework kzalloc failure check >=20 > On Mon, Jun 22, 2020 at 04:35:46PM +0100, Colin King wrote: > > From: Colin Ian King > > > > kzalloc failures return NULL on out of memory errors, so replace the > > IS_ERR_OR_NULL check with the usual null pointer check. Fix two memory > > leaks with on acomp and acomp_ctx by ensuring these objects are free'd > > on the error return path. > > > > Addresses-Coverity: ("Resource leak") > > Fixes: d4f86abd6e35 ("mm/zswap: move to use crypto_acomp API for > hardware acceleration") > > Signed-off-by: Colin Ian King Colin, thanks for your patch. I am sorry I did the same thing with you here= : https://lkml.org/lkml/2020/6/22/347 > > --- > > mm/zswap.c | 16 +++++++++++----- > > 1 file changed, 11 insertions(+), 5 deletions(-) > > > > diff --git a/mm/zswap.c b/mm/zswap.c > > index 0d914ba6b4a0..14839cbac7ff 100644 > > --- a/mm/zswap.c > > +++ b/mm/zswap.c > > @@ -433,23 +433,23 @@ static int zswap_cpu_comp_prepare(unsigned int > cpu, struct hlist_node *node) > > return 0; > > > > acomp_ctx =3D kzalloc(sizeof(*acomp_ctx), GFP_KERNEL); > > - if (IS_ERR_OR_NULL(acomp_ctx)) { > > + if (!acomp_ctx) { > > pr_err("Could not initialize acomp_ctx\n"); > > return -ENOMEM; > > } > > acomp =3D crypto_alloc_acomp(pool->tfm_name, 0, 0); > > - if (IS_ERR_OR_NULL(acomp)) { > > + if (!acomp) { >=20 > This should be IS_ERR(acomp). Please preserve the error code. >=20 > > pr_err("could not alloc crypto acomp %s : %ld\n", > > pool->tfm_name, PTR_ERR(acomp)); > > - return -ENOMEM; > > + goto free_acomp_ctx; > > } > > acomp_ctx->acomp =3D acomp; > > > > req =3D acomp_request_alloc(acomp_ctx->acomp); > > - if (IS_ERR_OR_NULL(req)) { > > + if (!req) { > > pr_err("could not alloc crypto acomp %s : %ld\n", > > pool->tfm_name, PTR_ERR(acomp)); > > - return -ENOMEM; > > + goto free_acomp; > > } > > acomp_ctx->req =3D req; > > > > @@ -462,6 +462,12 @@ static int zswap_cpu_comp_prepare(unsigned int > cpu, struct hlist_node *node) > > *per_cpu_ptr(pool->acomp_ctx, cpu) =3D acomp_ctx; > > > > return 0; > > + > > +free_acomp: > > + kfree(acomp); >=20 > The kfree() isn't correct. It needs to be: >=20 > crypto_free_acomp(acomp); >=20 > > +free_acomp_ctx: > > + kfree(acomp_ctx); > > + return -ENOMEM; >=20 > regards, > dan carpenter