From patchwork Wed Jun 28 13:11:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cabiddu, Giovanni" X-Patchwork-Id: 13295780 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 289F0EB64D7 for ; Wed, 28 Jun 2023 13:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231136AbjF1NM2 (ORCPT ); Wed, 28 Jun 2023 09:12:28 -0400 Received: from mga07.intel.com ([134.134.136.100]:60590 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbjF1NM1 (ORCPT ); Wed, 28 Jun 2023 09:12:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687957946; x=1719493946; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=kUI2weqV3ohP9ChOhTxlq7GKxntGyGfiywP3meat0EU=; b=P0TihiW1dbvJPlgqMDDOt9jClMxwFYj2IdT6PmKTHsbzux72H00/gkYG GKn1DLkyZGM8vxcmyCD/27gQErx26CWqRVuVyMFnJ3JgRic1y2h6/BQ23 dcasZsYSgsfAO/mnvFi5CilHN38rnvJPJvjYPDLJ4+T6bPshKrE2H1vxM mi+akT8alWDDye5TOLK5WzoL0LxjxorB6xX+9/Sz54AakgnvyTvgQD+qf UKAz045knC/j7aXmrwhcY1cTCzRG1HMAJt7Td9WGfE1BJMuopJkBx38D/ eR6FkJNk/jcMhaMX420EqPL5jvZUbTGA3oMkh2oQJlG12N6bWKgXrXspC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="427846424" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="427846424" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 06:12:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="752252732" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="752252732" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP; 28 Jun 2023 06:12:25 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 28 Jun 2023 06:12:25 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Wed, 28 Jun 2023 06:12:25 -0700 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.43) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Wed, 28 Jun 2023 06:12:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eRz33y0m9qiqT/+HVUHjyFpFQAK/iOR0ZC0q2mw0ouwAcp1OMYl93ivNRfkw+P+SJkihn9thwHQGptI+Wv/YYdmwh8HtZZgUPTUATx9yvHx9vqAfASZSbcaQ7s1vaj9wG17nlSf4JXQqNo1kJ0WvK9MRjw2+pK/3pcL9gtRwzvyEbFCy5UNChXlMiR7vsTwHOROjJiw4o/c44Pk7o/2DSMLOfHI9DhMM9a0NqelzPqGK9M6ULadnAy+yNaASbdV2lQcP/Su9AdhKe6JmfnKNNhXRfMZowYnYxDKUg6a2Q4yrNh0PcJk3pVG1nNs2mbb2zwjCTThy+si4bzyQz4YqBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mfWTUTdYzxq8deeniVCVr75H0n8iVLlx13ITF9Yvfs0=; b=K9/IutXAV/Zw7QhhkEuXsw/XCQ+/vA0eZfBxF5pUPO9bvVed+Er1ob47d1pFo8criV2nmQ4J4vvOxwQZFqSXb2EvZhioDnD8FE0F2Bn0568+0ZFMM9lGoYU/OPAdqlujp4o1GrNzY2IQF86OJsws4LJQiqF9zMgYuPgZXexvzxMeskFshnP9U4rk/tNNCMNCg71HFGWMppy8mm2Mre4Rm/KYqR6TBRkGEk3MGHx+GRwk1avtWBBeZ05QifmCKDLzhvyjX73xuFXm3Um7WWLIIhSI+9wEZFX6nzRwQ2maC8eakpxGpyxazKXPnrI7pq3e+7qHBeQxHilylLger5lQkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from CY5PR11MB6366.namprd11.prod.outlook.com (2603:10b6:930:3a::8) by CYYPR11MB8430.namprd11.prod.outlook.com (2603:10b6:930:c6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Wed, 28 Jun 2023 13:12:23 +0000 Received: from CY5PR11MB6366.namprd11.prod.outlook.com ([fe80::955a:2397:1402:c329]) by CY5PR11MB6366.namprd11.prod.outlook.com ([fe80::955a:2397:1402:c329%3]) with mapi id 15.20.6521.024; Wed, 28 Jun 2023 13:12:23 +0000 Date: Wed, 28 Jun 2023 14:11:53 +0100 From: Giovanni Cabiddu To: Andy Shevchenko CC: You Kangren , Herbert Xu , "David S. Miller" , "Tom Zanussi" , Damian Muszynski , Srinivas Kerekare , "open list:QAT DRIVER" , "open list:CRYPTO API" , open list , Subject: [PATCH] crypto: qat - use min() in fw loader Message-ID: References: <20230627071726.20578-1-youkangren@vivo.com> Content-Disposition: inline In-Reply-To: Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland X-ClientProxiedBy: FR0P281CA0229.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b2::14) To CY5PR11MB6366.namprd11.prod.outlook.com (2603:10b6:930:3a::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR11MB6366:EE_|CYYPR11MB8430:EE_ X-MS-Office365-Filtering-Correlation-Id: 21cad47e-b77f-4eed-8120-08db77d94ef0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q+bXTqpwjkTBf8SyPtSxPiX4REydmRRHf6+75yWkXl8xVYzmAI30FGxmvbaC1GjUx6xb1hJmNn24GaCEZ+qj5dArePdSFRCluLUbnt4quoBMXdQhOVot1t/+pIK1QiEzubRfzdmVaPdOAZIQdzohb0AXi/wHHpvUKHaQ+Hmc842waZbLmA8fOudNq/Z6pK1wNnRh49LrYFdqYWbXnH8d2lycA/y5PiL5KQYwlAqxa+w/lmeGtlz5Y560ugdcFbVipAalBv1rAKQUsVCItpmQXVlSY6uGYQiWywQO8TITpvUoFG0Pbi/Yv8NM83VUt1mf4azWBqjz9BeqSTEk7EcQqIZ9fjhmzN8dGyDAtT0xNJjxsCG2D5m4grz68B28wfseg/3mRscHoVXW0/dXFIqjlTS5uFTG8oLL1cXxok0mV8CWwwO/69zca7jJ5b9yVgv/XziowLfslylyPKAzsJranhh3rpeX/6aGDZnoN3i5Tv7WH5gSP3o31xcwyZ8CONYuE3ZDIebUL8PwhqFMnUbCkBvOA3leYJ+Pzg7dZLpqT0zLqMNOYQIMOLk10XE2xlC2Uc/Z43od/9IcX2HiybhYT+ZLA4Pmx56km6blghOwxrU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR11MB6366.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(376002)(346002)(136003)(396003)(39860400002)(451199021)(2906002)(6486002)(36916002)(186003)(82960400001)(83380400001)(38100700002)(26005)(53546011)(6666004)(6512007)(41300700001)(86362001)(54906003)(6506007)(478600001)(316002)(66556008)(66946007)(66476007)(6916009)(4326008)(44832011)(5660300002)(8676002)(8936002)(67856001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N9E3D9FNUw+RKhEPx1LHXrMlcLFuXd/9vyxa2bXOOYznLaXjBbnaiRcUr9VsrMvGEsKA0IwMnijsNAPonj3xU4jChHety5QotKi7lHbF/IUElfvcgQVEBsm5/5kG7mF3XmO8zNZmT/cOL3rEuL1LFvYU2HyHptmJtY2rr1cTkx1naHysUl+iol5X7sFqC2AFxpATqD2qOvQubcvBVqm+/tTwSLASahLIwMYIadLRaTX4+17C7OYU0OKNL+1DeoMH2aF6afUO5Tz6vN9eqtOG5tqSvAa++XO/4onRvvm0nc1pTcT/A9KK5xrmCJz74A/XLuUbMSQAHA2Zl+PE/cQiYny9guVwtHbichqGAVJDbLDByiTQCVMxR49UUZLOEIoWXUr0pJoRSGhPRpE1x9tHt6bjpp4sOTxg47fcO3NwgBSaUGE03wVhfgTEMqYHcOrLFv5o9RdeGgvGBAVkP5hilXRja5adLSh/ynGS2ohLhIsNxePISLF6qng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U+Cq2Yqqu6FJq4Dmmao1Xu3KVX74ig== X-MS-Exchange-CrossTenant-Network-Message-Id: 21cad47e-b77f-4eed-8120-08db77d94ef0 X-MS-Exchange-CrossTenant-AuthSource: CY5PR11MB6366.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2023 13:12:22.8831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Lhckro4+GlJNriUOmhkHkGRCSyYeozTvlTo6oEi2E3atA3/cRJfcM1tIceNkXh8klmcKhIv2+NG2Z6dRJbywhUINsHCwgTriWukEkcBk7XA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR11MB8430 X-OriginatorOrg: intel.com Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jun 28, 2023 at 01:46:44PM +0300, Andy Shevchenko wrote: > On Tue, Jun 27, 2023 at 03:17:24PM +0800, You Kangren wrote: > > Replace the if statement with min_t() to simplify the code > > ... > > > - if (words_num < UWORD_CPYBUF_SIZE) > > - cpylen = words_num; > > - else > > - cpylen = UWORD_CPYBUF_SIZE; > > + cpylen = min_t(unsigned int, words_num, UWORD_CPYBUF_SIZE); > > min_t() can be dangerous some times. > > To make it robust I would suggest to use min() and mark UWORD_CPYBUF_SIZE > with U suffix to make the type the same. Thanks. I reworked it, added a missing include and ordered the includes in the file. ----8<---- From: Giovanni Cabiddu Date: Wed, 28 Jun 2023 13:32:09 +0100 Subject: [PATCH] crypto: qat - use min() in fw loader Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare - Ireland Use min() macro in firmware loaded instead of if statement. While at it, reorder the includes on this file in alphabetical order. Signed-off-by: Giovanni Cabiddu --- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c index ce837bcc1cab..6a52a853e2b1 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c @@ -1,17 +1,19 @@ // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) /* Copyright(c) 2014 - 2020 Intel Corporation */ -#include #include -#include #include +#include +#include #include +#include + #include "adf_accel_devices.h" #include "adf_common_drv.h" -#include "icp_qat_uclo.h" -#include "icp_qat_hal.h" #include "icp_qat_fw_loader_handle.h" +#include "icp_qat_hal.h" +#include "icp_qat_uclo.h" -#define UWORD_CPYBUF_SIZE 1024 +#define UWORD_CPYBUF_SIZE 1024U #define INVLD_UWORD 0xffffffffffull #define PID_MINOR_REV 0xf #define PID_MAJOR_REV (0xf << 4) @@ -1986,10 +1988,7 @@ static void qat_uclo_wr_uimage_raw_page(struct icp_qat_fw_loader_handle *handle, uw_relative_addr = 0; words_num = encap_page->micro_words_num; while (words_num) { - if (words_num < UWORD_CPYBUF_SIZE) - cpylen = words_num; - else - cpylen = UWORD_CPYBUF_SIZE; + cpylen = min(words_num, UWORD_CPYBUF_SIZE); /* load the buffer */ for (i = 0; i < cpylen; i++)