Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3671072rwb; Tue, 16 Aug 2022 07:04:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uhhbIZzKBWOhSP641N/1TZ02s4nLVEHPI7gCvLhK0Vdb8hyeZSACS6e9ZnuTlo3ybSKV3 X-Received: by 2002:a63:8048:0:b0:41c:6ab8:8d9f with SMTP id j69-20020a638048000000b0041c6ab88d9fmr18701300pgd.93.1660658663532; Tue, 16 Aug 2022 07:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660658663; cv=none; d=google.com; s=arc-20160816; b=q+JRmfyxtPUdEu3UnmDsEoysGiiUn9li6oq21JF/dv3FWEf324YnCNltMZJsCQpbcd G4qMB5W+qPrryNncpdIWdnuERi/x1HMW6vCqxqj2t/fhh3l2czBm66tgotJafrZwRpjr if4UO/aSCWAEPE5JOtvlog3Hmz+14+KnHq8m7DPii/QvczKlso1gnj5iwkwXBv3G5q9x y3vIaghLA9Q6mjLUYwEN/HLF3KZn6pE7lFA1CyCegLPJoFA2JPsUP1W5Am1O0DUExBgi qICV7rp02Tt4IjsZjCZFBHetEvgG1prfUr5k2sLl1uSh8FF8/Twr9lQoJf2rt8mBRVp+ siow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bNKl0WqaDu3QbRj292AtPq5phFFaJ1mJK+ISPGQQtjg=; b=yNxWEkr85LAfEYgoByYMBDyQ26TlQxm4puMQcbmJ7jOhFc+TB1CKy3hkZ6bWGbaMQf ZNEgX83LbwBAGHxb0BhtvB2PI15+jaui2OTMQ4y7l4n8grmJ7YIMcCZOg+GfTo/8rfhe qSGnxUCEKepvOyw2kgcTE3Oz4FEDvrv3cdK/XtGfPyIAeSP/BH/z28bplzJZiuF8ZMkd 4yP7ALMDTxAMuH54ajAlOrwHvjRemNrJOm9GQg9bukAmaUSaIV/hZ7ECxrOlaodv6Uap pdsIMhTMkqTcd2V/A/CT67EQxeZMFLhwvO2hZsQQFHLclxUEAEWPrQxTM2/9aX+6RBnn BFnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NWxN02FM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a630414000000b0041c2c456491si14444065pge.682.2022.08.16.07.04.10; Tue, 16 Aug 2022 07:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NWxN02FM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235885AbiHPODm (ORCPT + 99 others); Tue, 16 Aug 2022 10:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235852AbiHPOD0 (ORCPT ); Tue, 16 Aug 2022 10:03:26 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD2E2ED7A for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id x10so10628290ljq.4 for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=bNKl0WqaDu3QbRj292AtPq5phFFaJ1mJK+ISPGQQtjg=; b=NWxN02FM48jW+daL9f2AZliag0Jn6d1w+rXbGPDPXcwvM1cXkH7dVdqPiMHQ8Og/tm EFX9SBKfPv3OhSvG9gBy3a+VfSbZeorLUX7I3n5ToARHj56DWJ3lhBNqAEwqT7XJgKyF Rvxy51yWlTBMB3R9Ey+nqKGqzof/01x+iXss8pGkIG0UdHgVE7V0eh4zMo1HMEVQoEVD YB2fyOx22dbPK2eCTEqZB1iD9NO2R3K5ptkwDw1PqEONYPlXR/6uLghYfoAmiiZX09BS OwEDEmB2FXQT/wSFlCOPXTHQEfjzICZJWyyRmOzH6pkExWnXBJoXgMNAQF18nXu13UPL lP8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bNKl0WqaDu3QbRj292AtPq5phFFaJ1mJK+ISPGQQtjg=; b=3A0cVBHQWdpbjqwL21HM0ZbO73u8Rryy+Hzs+ga3ybnybfKNBSmM3QnWFwwSEwbofe 1Mep7+0Js4OhnN/FzBOf2t4SZbeMOWY9WWvKWvpiB/gUAmzAAFlSa6ql2HtGDnlYFqgC 0cgwaf4ezpY2YpAuMZevxYbuxLZdkRDArgVaQ+FPHFkUx23W9l9ZP8scEnL74B6LsJWK 3Fkakw3Ugao3RvbjUcIqce9oLxGnFRqVW3vLKOOHqcFp/ih3PIzg1tVTn6nODp4Wm856 fzWO7JzY7tyS/LMQ9kDH31DaYa+qrUqSZ7pv6QdwJ9E+9s/iPQRK6xuFkORaPP8QGQju Hu6g== X-Gm-Message-State: ACgBeo3FknCt0cRa68LQrV7ikApT5IVRbzmwceORLcuvmx5qoIZuS9jK h9eWHgXUMf96z4a4LBIWd1ZGsb5fPqxVIA== X-Received: by 2002:a2e:a236:0:b0:260:8ac:9182 with SMTP id i22-20020a2ea236000000b0026008ac9182mr6429203ljm.71.1660658599337; Tue, 16 Aug 2022 07:03:19 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:18 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 06/16] crypto: ux500/hash: Break while/do instead of if/else Date: Tue, 16 Aug 2022 16:00:39 +0200 Message-Id: <20220816140049.102306-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of a deeply nested if/else inside the while/do loop, just break the loop as we know the termination requirement was just established (msg_length == 0). Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_core.c | 115 +++++++++++++------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 65d328d438d2..b559c53dc703 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -671,69 +671,70 @@ static int hash_process_data(struct hash_device_data *device_data, } *index += msg_length; msg_length = 0; - } else { - if (req_ctx->updated) { - ret = hash_resume_state(device_data, - &device_data->state); - memmove(req_ctx->state.buffer, - device_data->state.buffer, - HASH_BLOCK_SIZE); - if (ret) { - dev_err(device_data->dev, - "%s: hash_resume_state() failed!\n", - __func__); - goto out; - } - } else { - ret = init_hash_hw(device_data, ctx); - if (ret) { - dev_err(device_data->dev, - "%s: init_hash_hw() failed!\n", - __func__); - goto out; - } - req_ctx->updated = 1; - } - /* - * If 'data_buffer' is four byte aligned and - * local buffer does not have any data, we can - * write data directly from 'data_buffer' to - * HW peripheral, otherwise we first copy data - * to a local buffer - */ - if (IS_ALIGNED((unsigned long)data_buffer, 4) && - (0 == *index)) - hash_processblock(device_data, - (const u32 *)data_buffer, - HASH_BLOCK_SIZE); - else { - for (count = 0; - count < (u32)(HASH_BLOCK_SIZE - *index); - count++) { - buffer[*index + count] = - *(data_buffer + count); - } - hash_processblock(device_data, - (const u32 *)buffer, - HASH_BLOCK_SIZE); - } - hash_incrementlength(req_ctx, HASH_BLOCK_SIZE); - data_buffer += (HASH_BLOCK_SIZE - *index); - - msg_length -= (HASH_BLOCK_SIZE - *index); - *index = 0; - - ret = hash_save_state(device_data, - &device_data->state); + break; + } - memmove(device_data->state.buffer, - req_ctx->state.buffer, + if (req_ctx->updated) { + ret = hash_resume_state(device_data, + &device_data->state); + memmove(req_ctx->state.buffer, + device_data->state.buffer, HASH_BLOCK_SIZE); if (ret) { - dev_err(device_data->dev, "%s: hash_save_state() failed!\n", + dev_err(device_data->dev, + "%s: hash_resume_state() failed!\n", __func__); goto out; } + } else { + ret = init_hash_hw(device_data, ctx); + if (ret) { + dev_err(device_data->dev, + "%s: init_hash_hw() failed!\n", + __func__); + goto out; + } + req_ctx->updated = 1; + } + /* + * If 'data_buffer' is four byte aligned and + * local buffer does not have any data, we can + * write data directly from 'data_buffer' to + * HW peripheral, otherwise we first copy data + * to a local buffer + */ + if (IS_ALIGNED((unsigned long)data_buffer, 4) && + (*index == 0)) + hash_processblock(device_data, + (const u32 *)data_buffer, + HASH_BLOCK_SIZE); + else { + for (count = 0; + count < (u32)(HASH_BLOCK_SIZE - *index); + count++) { + buffer[*index + count] = + *(data_buffer + count); + } + hash_processblock(device_data, + (const u32 *)buffer, + HASH_BLOCK_SIZE); + } + hash_incrementlength(req_ctx, HASH_BLOCK_SIZE); + data_buffer += (HASH_BLOCK_SIZE - *index); + + msg_length -= (HASH_BLOCK_SIZE - *index); + *index = 0; + + ret = hash_save_state(device_data, + &device_data->state); + + memmove(device_data->state.buffer, + req_ctx->state.buffer, + HASH_BLOCK_SIZE); + if (ret) { + dev_err(device_data->dev, "%s: hash_save_state() failed!\n", + __func__); + goto out; } } while (msg_length != 0); out: -- 2.37.2