Using the min macro is usually more intuitive and readable.
Signed-off-by: Yan Zhen yanzhen@vivo.com --- tools/testing/selftests/tdx/tdx_guest_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/tdx/tdx_guest_test.c b/tools/testing/selftests/tdx/tdx_guest_test.c index 81d8cb88e..d7ddf5307 100644 --- a/tools/testing/selftests/tdx/tdx_guest_test.c +++ b/tools/testing/selftests/tdx/tdx_guest_test.c @@ -118,7 +118,7 @@ static void print_array_hex(const char *title, const char *prefix_str, printf("\t\t%s", title);
for (j = 0; j < len; j += rowsize) { - line_len = rowsize < (len - j) ? rowsize : (len - j); + line_len = min((len - j), rowsize); printf("%s%.8x:", prefix_str, j); for (i = 0; i < line_len; i++) printf(" %.2x", ptr[j + i]);
On 8/21/24 22:46, Yan Zhen wrote:
Using the min macro is usually more intuitive and readable.
How did you find this problem?
Signed-off-by: Yan Zhen yanzhen@vivo.com
tools/testing/selftests/tdx/tdx_guest_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/tdx/tdx_guest_test.c b/tools/testing/selftests/tdx/tdx_guest_test.c index 81d8cb88e..d7ddf5307 100644 --- a/tools/testing/selftests/tdx/tdx_guest_test.c +++ b/tools/testing/selftests/tdx/tdx_guest_test.c @@ -118,7 +118,7 @@ static void print_array_hex(const char *title, const char *prefix_str, printf("\t\t%s", title); for (j = 0; j < len; j += rowsize) {
line_len = rowsize < (len - j) ? rowsize : (len - j);
printf("%s%.8x:", prefix_str, j); for (i = 0; i < line_len; i++) printf(" %.2x", ptr[j + i]);line_len = min((len - j), rowsize);
Did you compile this patch and test it? I am seeing warnings during build.
tdx_guest_test.c:121:28: warning: implicit declaration of function ‘min’ [-Wimplicit-function-declaration] 121 | line_len = min((len - j), rowsize); | ^~~
thanks, -- Shuah
Hi Yan,
kernel test robot noticed the following build errors:
[auto build test ERROR on shuah-kselftest/next] [also build test ERROR on shuah-kselftest/fixes linus/master v6.11-rc5 next-20240826] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yan-Zhen/selftests-tdx-Use-mi... base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next patch link: https://lore.kernel.org/r/20240822044630.1267500-1-yanzhen%40vivo.com patch subject: [PATCH v1] selftests:tdx:Use min macro :::::: branch date: 5 days ago :::::: commit date: 5 days ago compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240827/202408271330.HMq39DWo-lkp@i...)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/r/202408271330.HMq39DWo-lkp@intel.com/
All errors (new ones prefixed by >>):
tdx_guest_test.c:121:14: error: call to undeclared function 'min'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
121 | line_len = min((len - j), rowsize); | ^ 1 error generated.
vim +/min +121 tools/testing/selftests/tdx/tdx_guest_test.c
00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 111 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 112 static void print_array_hex(const char *title, const char *prefix_str, 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 113 const void *buf, int len) 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 114 { 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 115 int i, j, line_len, rowsize = HEX_DUMP_SIZE; 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 116 const __u8 *ptr = buf; 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 117 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 118 printf("\t\t%s", title); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 119 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 120 for (j = 0; j < len; j += rowsize) { 712bf3fd186eaf Yan Zhen 2024-08-22 @121 line_len = min((len - j), rowsize); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 122 printf("%s%.8x:", prefix_str, j); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 123 for (i = 0; i < line_len; i++) 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 124 printf(" %.2x", ptr[j + i]); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 125 printf("\n"); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 126 } 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 127 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 128 printf("\n"); 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 129 } 00e07cfbdf0b23 Kuppuswamy Sathyanarayanan 2022-11-16 130
linux-kselftest-mirror@lists.linaro.org