selftests:tdx:Use min macro
Subsystems (2)
PATCH 1/1 selftests:tdx:Use min macro
Using the min macro is usually more intuitive and readable.
--- tools/testing/selftests/tdx/tdx_guest_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tdx/tdx_guest_test.c +1 -1
@@ -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]);
Signature · 1 line
2.34.1
Shuah Khan
maintainerQuoted 1 line · Yan Zhen
Using the min macro is usually more intuitive and readable.
How did you find this problem?
Quoted 11 lines
Signed-off-by Yan Zhen <[email protected]>--- tools/testing/selftests/tdx/tdx_guest_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/tdx/tdx_guest_test.c +0
-0
tools/testing/selftests/tdx/tdx_guest_test.c static void print_array_hex(const char *title, const char *prefix_str, · line 124
Quoted 8 lines
tools/testing/selftests/tdx/tdx_guest_test.c +1
-1@@ -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]);
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
kernel test robot
build botkernel test robot noticed the following build errors:
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-min-macro/20240822-125041 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/[email protected]/reproduce)
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 <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
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 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki