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: 9565161 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 0B0946020C for ; Thu, 9 Feb 2017 16:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED7C3284D1 for ; Thu, 9 Feb 2017 16:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E138F284FA; Thu, 9 Feb 2017 16:53:29 +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=unavailable 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 5BC6B284D1 for ; Thu, 9 Feb 2017 16:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932284AbdBIQxQ (ORCPT ); Thu, 9 Feb 2017 11:53:16 -0500 Received: from exsmtp01.microchip.com ([198.175.253.37]:38249 "EHLO email.microchip.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753558AbdBIQxL (ORCPT ); Thu, 9 Feb 2017 11:53:11 -0500 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: , , CC: , , , , Cyrille Pitchen 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== 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 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);