Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Test cases for printf facility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "../tools/testing/selftests/kselftest_module.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define BUF_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define PAD_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define FILL_CHAR '$'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) KSTM_MODULE_GLOBALS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static char *test_buffer __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static char *alloced_buffer __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) extern bool no_hash_pointers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int __printf(4, 0) __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) do_test(int bufsize, const char *expect, int elen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	const char *fmt, va_list ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	va_list aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int ret, written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	total_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	memset(alloced_buffer, FILL_CHAR, BUF_SIZE + 2*PAD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	va_copy(aq, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ret = vsnprintf(test_buffer, bufsize, fmt, aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	va_end(aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (ret != elen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			bufsize, fmt, ret, elen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (memchr_inv(alloced_buffer, FILL_CHAR, PAD_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote before buffer\n", bufsize, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (!bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		if (memchr_inv(test_buffer, FILL_CHAR, BUF_SIZE + PAD_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			pr_warn("vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	written = min(bufsize-1, elen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (test_buffer[written]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		pr_warn("vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			bufsize, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			bufsize, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (memcmp(test_buffer, expect, written)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			bufsize, fmt, test_buffer, written, expect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static void __printf(3, 4) __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) __test(const char *expect, int elen, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int rand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (elen >= BUF_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		pr_err("error in test suite: expected output length %d too long. Format was '%s'.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		       elen, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		failed_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 * Every fmt+args is subjected to four tests: Three where we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * tell vsnprintf varying buffer sizes (plenty, not quite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * enough and 0), and then we also test that kvasprintf would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * be able to print it as expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	failed_tests += do_test(BUF_SIZE, expect, elen, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	rand = 1 + prandom_u32_max(elen+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	failed_tests += do_test(rand, expect, elen, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	failed_tests += do_test(0, expect, elen, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	p = kvasprintf(GFP_KERNEL, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		total_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (memcmp(p, expect, elen+1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			pr_warn("kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				fmt, p, expect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			failed_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define test(expect, fmt, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	__test(expect, strlen(expect), fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) test_basic(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* Work around annoying "warning: zero-length gnu_printf format string". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	char nul = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	test("", &nul);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	test("100%", "100%%");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	test("xxx%yyy", "xxx%cyyy", '%');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	__test("xxx\0yyy", 7, "xxx%cyyy", '\0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) test_number(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	test("0x1234abcd  ", "%#-12x", 0x1234abcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	test("  0x1234abcd", "%#12x", 0x1234abcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * POSIX/C99: »The result of converting zero with an explicit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * precision of zero shall be no characters.« Hence the output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * from the below test should really be "00|0||| ". However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * the kernel's printf also produces a single 0 in that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * case. This test case simply documents the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * behaviour.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	test("00|0|0|0|0", "%.2d|%.1d|%.0d|%.*d|%1.0d", 0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #ifndef __CHAR_UNSIGNED__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		 * Passing a 'char' to a %02x specifier doesn't do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		 * what was presumably the intention when char is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		 * signed and the value is negative. One must either &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		 * with 0xff or cast to u8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		char val = -16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		test("0xfffffff0|0xf0|0xf0", "%#02x|%#02x|%#02x", val, val & 0xff, (u8)val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) test_string(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	test("", "%s%.0s", "", "123");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	test("ABCD|abc|123", "%s|%.3s|%.*s", "ABCD", "abcdef", 3, "123456");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	test("1  |  2|3  |  4|5  ", "%-3s|%3s|%-*s|%*s|%*s", "1", "2", 3, "3", 3, "4", -3, "5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	test("1234      ", "%-10.4s", "123456");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	test("      1234", "%10.4s", "123456");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * POSIX and C99 say that a negative precision (which is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 * possible to pass via a * argument) should be treated as if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 * the precision wasn't present, and that if the precision is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * omitted (as in %.s), the precision should be taken to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * 0. However, the kernel's printf behave exactly opposite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * treating a negative precision as 0 and treating an omitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * precision specifier as if no precision was given.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * These test cases document the current behaviour; should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * anyone ever feel the need to follow the standards more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * closely, this can be revisited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	test("    ", "%4.*s", -5, "123456");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	test("123456", "%.s", "123456");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	test("a||", "%.s|%.0s|%.*s", "a", "b", 0, "c");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	test("a  |   |   ", "%-3.s|%-3.0s|%-3.*s", "a", "b", 0, "c");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define PLAIN_BUF_SIZE 64	/* leave some space so we don't oops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define PTR_WIDTH 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define PTR ((void *)0xffff0123456789abUL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define PTR_STR "ffff0123456789ab"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define PTR_VAL_NO_CRNG "(____ptrval____)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define ZEROS "00000000"	/* hex 32 zero bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define ONES "ffffffff"		/* hex 32 one bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) plain_format(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	char buf[PLAIN_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	int nchars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (nchars != PTR_WIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			PTR_VAL_NO_CRNG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (strncmp(buf, ZEROS, strlen(ZEROS)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define PTR_WIDTH 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define PTR ((void *)0x456789ab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define PTR_STR "456789ab"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define PTR_VAL_NO_CRNG "(ptrval)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define ZEROS ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define ONES ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) plain_format(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* Format is implicitly tested for 32 bit machines by plain_hash() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif	/* BITS_PER_LONG == 64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) plain_hash_to_buffer(const void *p, char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	int nchars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	nchars = snprintf(buf, len, "%p", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (nchars != PTR_WIDTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			PTR_VAL_NO_CRNG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) plain_hash(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	char buf[PLAIN_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * We can't use test() to test %p because we don't know what output to expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * after an address is hashed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) plain(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (no_hash_pointers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		pr_warn("skipping plain 'p' tests");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		skipped_tests += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	err = plain_hash();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		pr_warn("plain 'p' does not appear to be hashed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		failed_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	err = plain_format();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		pr_warn("hashing plain 'p' has unexpected format\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		failed_tests++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) test_hashed(const char *fmt, const void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	char buf[PLAIN_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	 * No need to increase failed test counter since this is assumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	 * to be called after plain().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	test(buf, fmt, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * NULL pointers aren't hashed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) null_pointer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	test(ZEROS "00000000", "%p", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	test(ZEROS "00000000", "%px", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	test("(null)", "%pE", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * Error pointers aren't hashed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) error_pointer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	test(ONES "fffffff5", "%p", ERR_PTR(-11));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	test(ONES "fffffff5", "%px", ERR_PTR(-11));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	test("(efault)", "%pE", ERR_PTR(-11));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #define PTR_INVALID ((void *)0x000000ab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) invalid_pointer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	test_hashed("%p", PTR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	test(ZEROS "000000ab", "%px", PTR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	test("(efault)", "%pE", PTR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) symbol_ptr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) kernel_ptr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	/* We can't test this without access to kptr_restrict. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct_resource(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) addr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) escaped_str(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) hex_string(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	const char buf[3] = {0xc0, 0xff, 0xee};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	     "%3ph|%3phC|%3phD|%3phN", buf, buf, buf, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	     "%*ph|%*phC|%*phD|%*phN", 3, buf, 3, buf, 3, buf, 3, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) mac(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	const u8 addr[6] = {0x2d, 0x48, 0xd6, 0xfc, 0x7a, 0x05};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	test("2d:48:d6:fc:7a:05", "%pM", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	test("05:7a:fc:d6:48:2d", "%pMR", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	test("2d-48-d6-fc-7a-05", "%pMF", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	test("2d48d6fc7a05", "%pm", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	test("057afcd6482d", "%pmR", addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ip4(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	struct sockaddr_in sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	sa.sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	sa.sin_port = cpu_to_be16(12345);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	sa.sin_addr.s_addr = cpu_to_be32(0x7f000001);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	test("127.000.000.001|127.0.0.1", "%pi4|%pI4", &sa.sin_addr, &sa.sin_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	test("127.000.000.001|127.0.0.1", "%piS|%pIS", &sa, &sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	sa.sin_addr.s_addr = cpu_to_be32(0x01020304);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	test("001.002.003.004:12345|1.2.3.4:12345", "%piSp|%pISp", &sa, &sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ip6(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ip(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	ip4();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	ip6();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) uuid(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	const char uuid[16] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			       0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	test("00010203-0405-0607-0809-0a0b0c0d0e0f", "%pUb", uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	test("00010203-0405-0607-0809-0A0B0C0D0E0F", "%pUB", uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	test("03020100-0504-0706-0809-0a0b0c0d0e0f", "%pUl", uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	test("03020100-0504-0706-0809-0A0B0C0D0E0F", "%pUL", uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static struct dentry test_dentry[4] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	{ .d_parent = &test_dentry[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	  .d_name = QSTR_INIT(test_dentry[0].d_iname, 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	  .d_iname = "foo" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	{ .d_parent = &test_dentry[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	  .d_name = QSTR_INIT(test_dentry[1].d_iname, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	  .d_iname = "bravo" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	{ .d_parent = &test_dentry[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	  .d_name = QSTR_INIT(test_dentry[2].d_iname, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	  .d_iname = "alfa" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	{ .d_parent = &test_dentry[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	  .d_name = QSTR_INIT(test_dentry[3].d_iname, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	  .d_iname = "romeo" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) dentry(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	test("foo", "%pd", &test_dentry[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	test("foo", "%pd2", &test_dentry[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	test("(null)", "%pd", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	test("(efault)", "%pd", PTR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	test("(null)", "%pD", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	test("(efault)", "%pD", PTR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	test("romeo", "%pd", &test_dentry[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	test("alfa/romeo", "%pd2", &test_dentry[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	test("bravo/alfa/romeo", "%pd3", &test_dentry[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	test("/bravo/alfa/romeo", "%pd4", &test_dentry[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	test("/bravo/alfa", "%pd4", &test_dentry[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	test("bravo/alfa  |bravo/alfa  ", "%-12pd2|%*pd2", &test_dentry[2], -12, &test_dentry[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	test("  bravo/alfa|  bravo/alfa", "%12pd2|%*pd2", &test_dentry[2], 12, &test_dentry[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct_va_format(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) time_and_date(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	/* 1543210543 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	const struct rtc_time tm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		.tm_sec = 43,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		.tm_min = 35,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		.tm_hour = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		.tm_mday = 26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		.tm_mon = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		.tm_year = 118,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* 2019-01-04T15:32:23 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	time64_t t = 1546615943;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	test("(%pt?)", "%pt", &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	test("2018-11-26T05:35:43", "%ptR", &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	test("0118-10-26T05:35:43", "%ptRr", &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	test("2019-01-04T15:32:23", "%ptT", &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	test("0119-00-04T15:32:23", "%ptTr", &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	test("15:32:23|0119-00-04", "%ptTtr|%ptTdr", &t, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct_clk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) large_bitmap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	const int nbits = 1 << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	unsigned long *bits = bitmap_zalloc(nbits, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (!bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	bitmap_set(bits, 1, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	bitmap_set(bits, 60000, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	test("1-20,60000-60014", "%*pbl", nbits, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	bitmap_free(bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) bitmap(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	DECLARE_BITMAP(bits, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	const int primes[] = {2,3,5,7,11,13,17,19};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	bitmap_zero(bits, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	test("00000|00000", "%20pb|%*pb", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	test("|", "%20pbl|%*pbl", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	for (i = 0; i < ARRAY_SIZE(primes); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		set_bit(primes[i], bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	test("a28ac|a28ac", "%20pb|%*pb", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	test("2-3,5,7,11,13,17,19|2-3,5,7,11,13,17,19", "%20pbl|%*pbl", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	bitmap_fill(bits, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	test("fffff|fffff", "%20pb|%*pb", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	test("0-19|0-19", "%20pbl|%*pbl", bits, 20, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	large_bitmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) netdev_features(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) flags(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	gfp_t gfp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	char *cmp_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	test("", "%pGp", &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	/* Page flags should filter the zone id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	flags = 1UL << NR_PAGEFLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	test("", "%pGp", &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	flags |= 1UL << PG_uptodate | 1UL << PG_dirty | 1UL << PG_lru
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		| 1UL << PG_active | 1UL << PG_swapbacked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	test("uptodate|dirty|lru|active|swapbacked", "%pGp", &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			| VM_DENYWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	test("read|exec|mayread|maywrite|mayexec|denywrite", "%pGv", &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	gfp = GFP_TRANSHUGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	test("GFP_TRANSHUGE", "%pGg", &gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	gfp = GFP_ATOMIC|__GFP_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	test("GFP_ATOMIC|GFP_DMA", "%pGg", &gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	gfp = __GFP_ATOMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	test("__GFP_ATOMIC", "%pGg", &gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	cmp_buffer = kmalloc(BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	if (!cmp_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	/* Any flags not translated by the table should remain numeric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	gfp = ~__GFP_BITS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	snprintf(cmp_buffer, BUF_SIZE, "%#lx", (unsigned long) gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	test(cmp_buffer, "%pGg", &gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	snprintf(cmp_buffer, BUF_SIZE, "__GFP_ATOMIC|%#lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 							(unsigned long) gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	gfp |= __GFP_ATOMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	test(cmp_buffer, "%pGg", &gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	kfree(cmp_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static void __init fwnode_pointer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	const struct software_node softnodes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		{ .name = "first", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		{ .name = "second", .parent = &softnodes[0], },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		{ .name = "third", .parent = &softnodes[1], },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		{ NULL /* Guardian */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	const char * const full_name = "first/second/third";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	const char * const full_name_second = "first/second";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	const char * const second_name = "second";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	const char * const third_name = "third";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	int rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	rval = software_node_register_nodes(softnodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (rval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		pr_warn("cannot register softnodes; rval %d\n", rval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	test(full_name_second, "%pfw", software_node_fwnode(&softnodes[1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	test(full_name, "%pfw", software_node_fwnode(&softnodes[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	test(full_name, "%pfwf", software_node_fwnode(&softnodes[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	test(third_name, "%pfwP", software_node_fwnode(&softnodes[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	software_node_unregister(&softnodes[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	software_node_unregister(&softnodes[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	software_node_unregister(&softnodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) errptr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	test("-1234", "%pe", ERR_PTR(-1234));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	/* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	BUILD_BUG_ON(IS_ERR(PTR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	test_hashed("%pe", PTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) #ifdef CONFIG_SYMBOLIC_ERRNAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	test("(-ENOTSOCK)", "(%pe)", ERR_PTR(-ENOTSOCK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	test("(-EAGAIN)", "(%pe)", ERR_PTR(-EAGAIN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	BUILD_BUG_ON(EAGAIN != EWOULDBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	test("(-EAGAIN)", "(%pe)", ERR_PTR(-EWOULDBLOCK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	test("[-EIO    ]", "[%-8pe]", ERR_PTR(-EIO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	test("[    -EIO]", "[%8pe]", ERR_PTR(-EIO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	test("-EPROBE_DEFER", "%pe", ERR_PTR(-EPROBE_DEFER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) test_pointer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	plain();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	null_pointer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	error_pointer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	invalid_pointer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	symbol_ptr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	kernel_ptr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	struct_resource();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	addr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	escaped_str();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	hex_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	mac();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	ip();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	uuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	dentry();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	struct_va_format();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	time_and_date();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	struct_clk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	bitmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	netdev_features();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	flags();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	errptr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	fwnode_pointer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static void __init selftest(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	if (!alloced_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	test_buffer = alloced_buffer + PAD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	test_basic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	test_number();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	test_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	test_pointer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	kfree(alloced_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) KSTM_MODULE_LOADERS(test_printf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) MODULE_LICENSE("GPL");