From patchwork Thu Feb 9 16:51:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrille Pitchen X-Patchwork-Id: 9565151 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 8BB6C6020C for ; Thu, 9 Feb 2017 16:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 779B82851A for ; Thu, 9 Feb 2017 16:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68C5B284D1; Thu, 9 Feb 2017 16:51:51 +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=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFC01284D1 for ; Thu, 9 Feb 2017 16:51:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cbrwg-0004rC-Cf; Thu, 09 Feb 2017 16:51:46 +0000 Received: from exsmtp01.microchip.com ([198.175.253.37] helo=email.microchip.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cbrwG-0004KK-CT for linux-arm-kernel@lists.infradead.org; Thu, 09 Feb 2017 16:51:22 +0000 Received: from tenerife.corp.atmel.com (10.10.76.4) by CHN-SV-EXCH01.mchp-main.com (10.10.76.37) with Microsoft SMTP Server id 14.3.181.6; Thu, 9 Feb 2017 09:50:59 -0700 From: Cyrille Pitchen To: , , Subject: [PATCH next 2/2] crypto: atmel-sha: fix error management in atmel_sha_start() Date: Thu, 9 Feb 2017 17:51:21 +0100 Message-ID: <3852cb16370171988f6669b3bac98b06477bacb6.1486655562.git.cyrille.pitchen@atmel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAC+NgFjrEKsWRWlGSWpSXmKPExsXCxeXDovt57pwIg+UXH3dwWdz7fp7Z4vW/6SwWc863sFh0v5Kx2PT4GqvF/Xs/mSwu75rDZvHtcjO7A4fHgl9bWTy2rLzJ5LHtgKrH5iX1Hh+f3mLx+LxJLoAtijUzLym/IoE1Y/nbL4wFDSIV/2fuZm1gvMHfxcjJISSwllHizB81EJtNwFDi7YOjrCC2iECgxMKWV4xdjFwczAKbGSW2/XvHBpIQFgiTuLy1nQnEZhFQkfjXvJwdxOYViJdondgF1iwhICdx81wnM4jNKWAr8frUATaIZTYSa55eZYaoF5Q4OfMJC4jNLCAhcfDFC2aIGjWgxSuYIeYESnx838gOYTtJvDz6kg3CtpM4PP0iVNxe4uyazXA1P3ftgLpBW2L7q31Qto7EtoP9LBC2rcSeGROZIGx3iQePlkPZvhKzHjZA1URJNCw4wTSBUWIWklNnITl1ASPTKkZpZw8/3eAwXdcIZw8DQ73c5IwC3dzEzDy95PzcTYyQCFXdwXjrX/ghRkkOJiVRXtmCORFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHjPzgbKCRalpqdWpGXmAFMFTJqJg/MQowQHj5IIrz9IDW9xQWJucWY6RP4Uo6SUOG8jSEIAJJFRmgfXe4lRVEqYtwMkx1OQWpSbWQIRv8UozPGQSYglLz8vVQroTgYg0GB8xSjOwagkzLsBrD4zrwRuxyug9UxA66+fngWyviQRISXVwMjwy644LnPbocw5CpuTH2X4Bchuy+UuZ314YIv88kW7OW/uMVyd4iltycnyrv75lu2zLj4+eY37sITS7/tcPw89juU+z1tRyHWq7MVdW5GS4PKPVl28G5nVJUwcHlqnNGSrrigp5Rdf8ELdv9q+6ZPA22PnnSJf7w/+8GbT2ZbrF0+EbMifJKDEUpyRaKjFXFSc CACZ7aJVVQMAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170209_085120_565227_88CA74E7 X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cyrille Pitchen , dan.carpenter@oracle.com, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch clarifies and fixes how errors should be handled by atmel_sha_start(). For update operations, the previous code wrongly assumed that (err != -EINPROGRESS) implies (err == 0). It's wrong because that doesn't take the error cases (err < 0) into account. This patch also adds many comments to detail all the possible returned values and what should be done in each case. Especially, when an error occurs, since atmel_sha_complete() has already been called, hence releasing the hardware, atmel_sha_start() must not call atmel_sha_finish_req() later otherwise atmel_sha_complete() would be called a second time. Signed-off-by: Cyrille Pitchen --- drivers/crypto/atmel-sha.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index d6c3d9529d36..0d207dac9aa2 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c @@ -1106,22 +1106,39 @@ static int atmel_sha_start(struct atmel_sha_dev *dd) ctx->op, req->nbytes); err = atmel_sha_hw_init(dd); - if (err) - goto err1; + return atmel_sha_complete(dd, err); + + /* + * atmel_sha_update_req() and atmel_sha_final_req() can return either: + * -EINPROGRESS: the hardware is busy and the SHA driver will resume + * its job later in the done_task. + * This is the main path. + * + * 0: the SHA driver can continue its job then release the hardware + * later, if needed, with atmel_sha_finish_req(). + * This is the alternate path. + * + * < 0: an error has occurred so atmel_sha_complete(dd, err) has already + * been called, hence the hardware has been released. + * The SHA driver must stop its job without calling + * atmel_sha_finish_req(), otherwise atmel_sha_complete() would be + * called a second time. + * + * Please note that currently, atmel_sha_final_req() never returns 0. + */ dd->resume = atmel_sha_done; if (ctx->op == SHA_OP_UPDATE) { err = atmel_sha_update_req(dd); - if (err != -EINPROGRESS && (ctx->flags & SHA_FLAGS_FINUP)) + if (!err && (ctx->flags & SHA_FLAGS_FINUP)) /* no final() after finup() */ err = atmel_sha_final_req(dd); } else if (ctx->op == SHA_OP_FINAL) { err = atmel_sha_final_req(dd); } -err1: - if (err != -EINPROGRESS) + if (!err) /* done_task will not finish it, so do it here */ atmel_sha_finish_req(req, err);