* [PATCH v2] crypto: qat - Replace the if statement with min() @ 2023-06-27 7:17 You Kangren 2023-06-28 10:46 ` Andy Shevchenko 0 siblings, 1 reply; 4+ messages in thread From: You Kangren @ 2023-06-27 7:17 UTC (permalink / raw) To: Giovanni Cabiddu, Herbert Xu, David S. Miller, You Kangren, Andy Shevchenko, Tom Zanussi, Damian Muszynski, Srinivas Kerekare, open list:QAT DRIVER, open list:CRYPTO API, open list Cc: opensource.kernel Replace the if statement with min_t() to simplify the code Signed-off-by: You Kangren <youkangren@vivo.com> --- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 5 +---- 1 file changed, 1 insertion(+), 4 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..b42a4d22b9d2 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c @@ -1986,10 +1986,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_t(unsigned int, words_num, UWORD_CPYBUF_SIZE); /* load the buffer */ for (i = 0; i < cpylen; i++) -- 2.39.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] crypto: qat - Replace the if statement with min() 2023-06-27 7:17 [PATCH v2] crypto: qat - Replace the if statement with min() You Kangren @ 2023-06-28 10:46 ` Andy Shevchenko 2023-06-28 13:11 ` [PATCH] crypto: qat - use min() in fw loader Giovanni Cabiddu 0 siblings, 1 reply; 4+ messages in thread From: Andy Shevchenko @ 2023-06-28 10:46 UTC (permalink / raw) To: You Kangren Cc: Giovanni Cabiddu, Herbert Xu, David S. Miller, Tom Zanussi, Damian Muszynski, Srinivas Kerekare, open list:QAT DRIVER, open list:CRYPTO API, open list, opensource.kernel 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. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] crypto: qat - use min() in fw loader 2023-06-28 10:46 ` Andy Shevchenko @ 2023-06-28 13:11 ` Giovanni Cabiddu 2023-06-28 14:38 ` Andy Shevchenko 0 siblings, 1 reply; 4+ messages in thread From: Giovanni Cabiddu @ 2023-06-28 13:11 UTC (permalink / raw) 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, opensource.kernel 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 <giovanni.cabiddu@intel.com> 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 <giovanni.cabiddu@intel.com> --- 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 <linux/slab.h> #include <linux/ctype.h> -#include <linux/kernel.h> #include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/minmax.h> #include <linux/pci_ids.h> +#include <linux/slab.h> + #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++) -- 2.40.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] crypto: qat - use min() in fw loader 2023-06-28 13:11 ` [PATCH] crypto: qat - use min() in fw loader Giovanni Cabiddu @ 2023-06-28 14:38 ` Andy Shevchenko 0 siblings, 0 replies; 4+ messages in thread From: Andy Shevchenko @ 2023-06-28 14:38 UTC (permalink / raw) To: Giovanni Cabiddu Cc: You Kangren, Herbert Xu, David S. Miller, Tom Zanussi, Damian Muszynski, Srinivas Kerekare, open list:QAT DRIVER, open list:CRYPTO API, open list, opensource.kernel On Wed, Jun 28, 2023 at 02:11:53PM +0100, Giovanni Cabiddu wrote: > 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: ... > > 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. I think it should be two patches then, but it's up to you and subsystem maintainer. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-28 14:39 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-27 7:17 [PATCH v2] crypto: qat - Replace the if statement with min() You Kangren 2023-06-28 10:46 ` Andy Shevchenko 2023-06-28 13:11 ` [PATCH] crypto: qat - use min() in fw loader Giovanni Cabiddu 2023-06-28 14:38 ` Andy Shevchenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox