From patchwork Sat Aug 20 15:06:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 9291723 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 E274F607FF for ; Sat, 20 Aug 2016 15:07:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C795C28C01 for ; Sat, 20 Aug 2016 15:07:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB3D528C17; Sat, 20 Aug 2016 15:07:04 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 34CE628C01 for ; Sat, 20 Aug 2016 15:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbcHTPG6 (ORCPT ); Sat, 20 Aug 2016 11:06:58 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36773 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752765AbcHTPG5 (ORCPT ); Sat, 20 Aug 2016 11:06:57 -0400 Received: by mail-pf0-f196.google.com with SMTP id y134so3173653pfg.3 for ; Sat, 20 Aug 2016 08:06:57 -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:mime-version :content-transfer-encoding; bh=4m9N9GED979e5or7pPbILkDDI+K+fsgXhfyDwge41Fw=; b=B9a+/5buNOVYFsE4fPpxGEdiE8ZgDQzMhamAeV7s5gg4FjLEQy/RbXJPQ31aYYkof4 ITBwncMC3jbW+fVoKE/vHm9QhgmC/x+0Sx98PVB1kK4gjyDodFC/YjgdOZuxDP1/LT4p +MhCUrLs6moDOjpCSFzsZiUoFh6mCT8Cj0JANF4pKvyYjZivKYnArHgOyIpKg5UphtlJ L/OtRcxnbOK4Rc553E0/DVfKqQgdgp2QW2O9/iX4hLjkcY6aTOxVRnM/7EhbyTR1aBJG kqB+7mJmuuLlZBS1k6pGUjQAK+W+z/UEwAoUOLUbf6Gbt70vMz5unAK8P5GLk8ohZUdj Da/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4m9N9GED979e5or7pPbILkDDI+K+fsgXhfyDwge41Fw=; b=KjMXQTLp8fv/akZ7WSBNQdbEDVIrF4wG+5SQJhoEZDnUDoOnmXEC8GqYVyWzvVkYA/ lgEWYvZtsctqiVMxPNoJONlzqsL6lby5ejT1unjCDXzou6cqs0jsxexxEVDqXEalSVYu OIoiDmguXJA8NpF/P9lqSRReQfxwZytM68hs7nbHExYCYKAyC9BOM5rBALXHK8bXdW3l KnZRBhB7fXZ0mfKsK9ZN7pfQ9cwd/ToBXRqWrab/mAPKOZTDuToiYm2Si7tnzEBiFyjZ UZXYaZKWjsoYvBPxRT+OLVDuEkSqmqhKY4K5l1S5ImIQTyxANVE5K5r4WErzdFCfVWIO z2ug== X-Gm-Message-State: AEkoousu6MNp9vri9+PKs1hVeHotlogFFaUTmLtNot8DqOYxF0zEu/FqHw2oxa8+lmboIQ== X-Received: by 10.98.17.152 with SMTP id 24mr24973852pfr.13.1471705617175; Sat, 20 Aug 2016 08:06:57 -0700 (PDT) Received: from localhost.localdomain.localdomain (ec2-52-192-197-227.ap-northeast-1.compute.amazonaws.com. [52.192.197.227]) by smtp.gmail.com with ESMTPSA id r10sm14701070pfk.84.2016.08.20.08.06.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Aug 2016 08:06:56 -0700 (PDT) From: Wei Yongjun To: Herbert Xu , Stephan Mueller Cc: Wei Yongjun , linux-crypto@vger.kernel.org Subject: [PATCH -next] crypto: drbg - fix error return code Date: Sat, 20 Aug 2016 15:06:51 +0000 Message-Id: <1471705611-19309-1-git-send-email-weiyj.lk@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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 Fix to return a negative error code from the error handling case instead of 0. Signed-off-by: Wei Yongjun Acked-by: Stephan Mueller --- crypto/drbg.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/crypto/drbg.c b/crypto/drbg.c index edf3ce0..fb33f7d 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1178,12 +1178,16 @@ static inline int drbg_alloc_state(struct drbg_state *drbg) goto err; drbg->Vbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL); - if (!drbg->Vbuf) + if (!drbg->Vbuf) { + ret = -ENOMEM; goto fini; + } drbg->V = PTR_ALIGN(drbg->Vbuf, ret + 1); drbg->Cbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL); - if (!drbg->Cbuf) + if (!drbg->Cbuf) { + ret = -ENOMEM; goto fini; + } drbg->C = PTR_ALIGN(drbg->Cbuf, ret + 1); /* scratchpad is only generated for CTR and Hash */ if (drbg->core->flags & DRBG_HMAC) @@ -1199,8 +1203,10 @@ static inline int drbg_alloc_state(struct drbg_state *drbg) if (0 < sb_size) { drbg->scratchpadbuf = kzalloc(sb_size + ret, GFP_KERNEL); - if (!drbg->scratchpadbuf) + if (!drbg->scratchpadbuf) { + ret = -ENOMEM; goto fini; + } drbg->scratchpad = PTR_ALIGN(drbg->scratchpadbuf, ret + 1); } @@ -1999,7 +2005,7 @@ static int __init drbg_init(void) { unsigned int i = 0; /* pointer to drbg_algs */ unsigned int j = 0; /* pointer to drbg_cores */ - int ret = -EFAULT; + int ret; ret = drbg_healthcheck_sanity(); if (ret) @@ -2009,7 +2015,7 @@ static int __init drbg_init(void) pr_info("DRBG: Cannot register all DRBG types" "(slots needed: %zu, slots available: %zu)\n", ARRAY_SIZE(drbg_cores) * 2, ARRAY_SIZE(drbg_algs)); - return ret; + return -EFAULT; } /*