From patchwork Wed Aug 12 14:48:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 7002311 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CB5F3C05AC for ; Wed, 12 Aug 2015 14:49:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE96320667 for ; Wed, 12 Aug 2015 14:49:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF9C720660 for ; Wed, 12 Aug 2015 14:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754946AbbHLOtG (ORCPT ); Wed, 12 Aug 2015 10:49:06 -0400 Received: from mail-yk0-f174.google.com ([209.85.160.174]:35494 "EHLO mail-yk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754707AbbHLOtF (ORCPT ); Wed, 12 Aug 2015 10:49:05 -0400 Received: by ykdz80 with SMTP id z80so15749545ykd.2 for ; Wed, 12 Aug 2015 07:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=07IYX4UADxnvPR7B6Du/vgWzKtLBKM4++P3uJ8078zY=; b=T8XDSYyN8Y7P9TVfXavfb447Tw6trr5VczHabZe2vQ8tQhk7poAX18Mfc1PIfbvHUF laIEu8/IoVSoX2rM7a1ICu9RCRzzSCbVfIgNRxGDi5SzuxLi1sstJ3kn9k+AR8a99UrA jM0fP0T2Xgbfon4w5U57G0KhhVEY8ht2LYQk2J5EYRX2FHVZXo4rbR6zhhpcVBv1U8zG glfbVlgLcxEObsyXG9XxjcbUHbdoZXwOQxpAjnzyb4x/mfGeYSpojbFPtrttT/DYj+Un wrp2xHD4NS6xCd2RB+g22MEpZBF4rdYobT5RyNsf3xjWSPS3gwfZegYbYdcdi7JC+aI3 OyzQ== X-Received: by 10.170.135.138 with SMTP id b132mr32370805ykc.16.1439390944090; Wed, 12 Aug 2015 07:49:04 -0700 (PDT) Received: from localhost.localdomain ([187.64.233.140]) by smtp.gmail.com with ESMTPSA id v84sm4806983ywa.25.2015.08.12.07.49.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Aug 2015 07:49:03 -0700 (PDT) From: Fabio Estevam To: herbert@gondor.apana.org.au Cc: vicki.milhoan@freescale.com, steve.cornelius@freescale.com, horia.geanta@freescale.com, linux-crypto@vger.kernel.org, Fabio Estevam Subject: [PATCH] crypto: caam - Fix error handling in caam_rng_init() Date: Wed, 12 Aug 2015 11:48:42 -0300 Message-Id: <1439390922-25091-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam In the error paths we should free the resources that were previously acquired, so fix it accordingly. Signed-off-by: Fabio Estevam Reviewed-by: Horia Geant? --- drivers/crypto/caam/caamrng.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 345024c..fb0cc54 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -352,14 +352,22 @@ static int __init caam_rng_init(void) return PTR_ERR(dev); } rng_ctx = kmalloc(sizeof(struct caam_rng_ctx), GFP_DMA); - if (!rng_ctx) - return -ENOMEM; + if (!rng_ctx) { + err = -ENOMEM; + goto free_caam_alloc; + } err = caam_init_rng(rng_ctx, dev); if (err) - return err; + goto free_rng_ctx; dev_info(dev, "registering rng-caam\n"); return hwrng_register(&caam_rng); + +free_rng_ctx: + kfree(rng_ctx); +free_caam_alloc: + caam_jr_free(dev); + return err; } module_init(caam_rng_init);