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=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 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 6B1D8C433E0 for ; Mon, 22 Jun 2020 18:28:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29DE820732 for ; Mon, 22 Jun 2020 18:28:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="wFQ7tZQ7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29DE820732 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A84346B000C; Mon, 22 Jun 2020 14:28:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A34DD6B000D; Mon, 22 Jun 2020 14:28:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94AC26B000E; Mon, 22 Jun 2020 14:28:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 7A76D6B000C for ; Mon, 22 Jun 2020 14:28:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BE1781C38E4 for ; Mon, 22 Jun 2020 18:28:51 +0000 (UTC) X-FDA: 76957684062.15.tooth34_2c07b2626e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 6B87E1814B0CA for ; Mon, 22 Jun 2020 18:28:51 +0000 (UTC) X-HE-Tag: tooth34_2c07b2626e35 X-Filterd-Recvd-Size: 5801 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 18:28:50 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 05MILc9B144111; Mon, 22 Jun 2020 18:28:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=sgW/H7+7InoJElD4DUBdt2N3zRFgiP2cpkGrzmHIfyM=; b=wFQ7tZQ7zt1gIo71K2Pd18f1G1G4rON3C4PWBUge478EnZpRC4V5FIPMGmwLKmqe3oOF pS+1Wuf5QAlr3D6u65cwJuq/jYBkpmuA0Bd1Bqq/Ncc3XmTxVd8l67pD0y/EgvwNe6IA fDxlpFLE2BPjfEmfJo3BuGRzgirRYYsS06eyJ+h8eBJR3xDGe9TeIRVLXQgOCVRD5MOs ABTH0TfTPg0ozuGmddO3xLGmbp//X6Cuqzd6SSSsTJRVNbI/vKsOSz/3vpIC/C+hJxln YmDLbMvQT+zhqBHKlu82/ebTjI1vxhAB6sUTvtTsG3zJ9SNCVvVPymZ2sSjFZEHTj5eP bw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 31sebb9197-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Jun 2020 18:28:30 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 05MII5BJ099672; Mon, 22 Jun 2020 18:28:30 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 31sv7qhqkp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 18:28:30 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05MISPIO005978; Mon, 22 Jun 2020 18:28:25 GMT Received: from kadam (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Jun 2020 18:28:24 +0000 Date: Mon, 22 Jun 2020 21:28:17 +0300 From: Dan Carpenter To: Colin King Cc: Seth Jennings , Dan Streetman , Vitaly Wool , Andrew Morton , 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 Message-ID: <20200622182816.GF4151@kadam> References: <20200622153546.49880-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200622153546.49880-1-colin.king@canonical.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9660 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=2 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220123 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9660 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 cotscore=-2147483648 lowpriorityscore=0 phishscore=0 bulkscore=0 clxscore=1011 impostorscore=0 malwarescore=0 priorityscore=1501 spamscore=0 mlxscore=0 adultscore=0 suspectscore=2 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220123 X-Rspamd-Queue-Id: 6B87E1814B0CA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: 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 > --- > 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 = 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 = crypto_alloc_acomp(pool->tfm_name, 0, 0); > - if (IS_ERR_OR_NULL(acomp)) { > + if (!acomp) { This should be IS_ERR(acomp). Please preserve the error code. > 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 = acomp; > > req = 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 = 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) = acomp_ctx; > > return 0; > + > +free_acomp: > + kfree(acomp); The kfree() isn't correct. It needs to be: crypto_free_acomp(acomp); > +free_acomp_ctx: > + kfree(acomp_ctx); > + return -ENOMEM; regards, dan carpenter