From patchwork Tue Sep 6 10:18:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 9316331 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19C5060752 for ; Tue, 6 Sep 2016 10:19:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A18528C36 for ; Tue, 6 Sep 2016 10:19:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2E7A28C3A; Tue, 6 Sep 2016 10:19:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B6F028C36 for ; Tue, 6 Sep 2016 10:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934479AbcIFKTI (ORCPT ); Tue, 6 Sep 2016 06:19:08 -0400 Received: from mga05.intel.com ([192.55.52.43]:60583 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934463AbcIFKTE (ORCPT ); Tue, 6 Sep 2016 06:19:04 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP; 06 Sep 2016 03:18:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,291,1470726000"; d="scan'208";a="757588248" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by FMSMGA003.fm.intel.com with ESMTP; 06 Sep 2016 03:18:53 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u86AIqSp032434; Tue, 6 Sep 2016 11:18:52 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id u86AIp0V001366; Tue, 6 Sep 2016 11:18:51 +0100 Received: (from gcabiddu@localhost) by sivswdev01.ir.intel.com with id u86AIpxn001362; Tue, 6 Sep 2016 11:18:51 +0100 Date: Tue, 6 Sep 2016 11:18:51 +0100 From: Giovanni Cabiddu To: Quentin Lambert Cc: Salvatore Benedetto , Herbert Xu , "David S. Miller" , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, giovanni.cabiddu@gmail.com, giovanni.cabiddu@intel.com Subject: Re: [PATCH v2 2/2] crypto: qat - fix resource release omissions Message-ID: <20160906101851.GA27032@sivswdev01.ir.intel.com> References: <20160902144753.31334-1-lambert.quentin@gmail.com> <20160902144753.31334-3-lambert.quentin@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160902144753.31334-3-lambert.quentin@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Lambert, On Fri, Sep 02, 2016 at 04:47:53PM +0200, Quentin Lambert wrote: > In certain cases qat_uclo_parse_uof_obj used to return with an error code > before releasing all resources. This patch add a jump to the appropriate label > ensuring that the resources are properly released before returning. > > This issue was found with Hector. Thanks for the patches. This can be easily fixed by moving the kcalloc after the compatibility check function. What do you think? ---8<--- Subject: [PATCH] crypto: qat - fix leak on error path Fix a memory leak in an error path in uc loader. Signed-off-by: Giovanni Cabiddu --- drivers/crypto/qat/qat_common/qat_uclo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c b/drivers/crypto/qat/qat_common/qat_uclo.c index 9b961b3..e2454d9 100644 --- a/drivers/crypto/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/qat/qat_common/qat_uclo.c @@ -967,10 +967,6 @@ static int qat_uclo_parse_uof_obj(struct icp_qat_fw_loader_handle *handle) struct icp_qat_uclo_objhandle *obj_handle = handle->obj_handle; unsigned int ae; - obj_handle->uword_buf = kcalloc(UWORD_CPYBUF_SIZE, sizeof(uint64_t), - GFP_KERNEL); - if (!obj_handle->uword_buf) - return -ENOMEM; obj_handle->encap_uof_obj.beg_uof = obj_handle->obj_hdr->file_buff; obj_handle->encap_uof_obj.obj_hdr = (struct icp_qat_uof_objhdr *) obj_handle->obj_hdr->file_buff; @@ -982,6 +978,10 @@ static int qat_uclo_parse_uof_obj(struct icp_qat_fw_loader_handle *handle) pr_err("QAT: UOF incompatible\n"); return -EINVAL; } + obj_handle->uword_buf = kcalloc(UWORD_CPYBUF_SIZE, sizeof(uint64_t), + GFP_KERNEL); + if (!obj_handle->uword_buf) + return -ENOMEM; obj_handle->ustore_phy_size = ICP_QAT_UCLO_MAX_USTORE; if (!obj_handle->obj_hdr->file_buff || !qat_uclo_map_str_table(obj_handle->obj_hdr, ICP_QAT_UOF_STRT,