forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/arm/bifrost/tests/kutf/kutf_suite.c
....@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
22 /*
33 *
4
- * (C) COPYRIGHT 2014, 2017-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2014, 2017-2022 ARM Limited. All rights reserved.
55 *
66 * This program is free software and is provided to you under the terms of the
77 * GNU General Public License version 2 as published by the Free Software
....@@ -106,22 +106,16 @@
106106 enum kutf_result_status result;
107107 };
108108
109
-struct kutf_convert_table kutf_convert[] = {
110
-#define ADD_UTF_RESULT(_name) \
111
-{ \
112
- #_name, \
113
- _name, \
114
-},
115
-ADD_UTF_RESULT(KUTF_RESULT_BENCHMARK)
116
-ADD_UTF_RESULT(KUTF_RESULT_SKIP)
117
-ADD_UTF_RESULT(KUTF_RESULT_UNKNOWN)
118
-ADD_UTF_RESULT(KUTF_RESULT_PASS)
119
-ADD_UTF_RESULT(KUTF_RESULT_DEBUG)
120
-ADD_UTF_RESULT(KUTF_RESULT_INFO)
121
-ADD_UTF_RESULT(KUTF_RESULT_WARN)
122
-ADD_UTF_RESULT(KUTF_RESULT_FAIL)
123
-ADD_UTF_RESULT(KUTF_RESULT_FATAL)
124
-ADD_UTF_RESULT(KUTF_RESULT_ABORT)
109
+static const struct kutf_convert_table kutf_convert[] = {
110
+#define ADD_UTF_RESULT(_name) \
111
+ { \
112
+#_name, _name, \
113
+ }
114
+ ADD_UTF_RESULT(KUTF_RESULT_BENCHMARK), ADD_UTF_RESULT(KUTF_RESULT_SKIP),
115
+ ADD_UTF_RESULT(KUTF_RESULT_UNKNOWN), ADD_UTF_RESULT(KUTF_RESULT_PASS),
116
+ ADD_UTF_RESULT(KUTF_RESULT_DEBUG), ADD_UTF_RESULT(KUTF_RESULT_INFO),
117
+ ADD_UTF_RESULT(KUTF_RESULT_WARN), ADD_UTF_RESULT(KUTF_RESULT_FAIL),
118
+ ADD_UTF_RESULT(KUTF_RESULT_FATAL), ADD_UTF_RESULT(KUTF_RESULT_ABORT),
125119 };
126120
127121 #define UTF_CONVERT_SIZE (ARRAY_SIZE(kutf_convert))
....@@ -191,8 +185,7 @@
191185 *
192186 * Return: 1 if test result was successfully converted to string, 0 otherwise
193187 */
194
-static int kutf_result_to_string(char **result_str,
195
- enum kutf_result_status result)
188
+static int kutf_result_to_string(const char **result_str, enum kutf_result_status result)
196189 {
197190 int i;
198191 int ret = 0;
....@@ -319,7 +312,8 @@
319312 }
320313
321314 /**
322
- * kutf_debugfs_run_open() Debugfs open callback for the "run" entry.
315
+ * kutf_debugfs_run_open() - Debugfs open callback for the "run" entry.
316
+ *
323317 * @inode: inode of the opened file
324318 * @file: Opened file to read from
325319 *
....@@ -381,7 +375,7 @@
381375 struct kutf_result *res;
382376 unsigned long bytes_not_copied;
383377 ssize_t bytes_copied = 0;
384
- char *kutf_str_ptr = NULL;
378
+ const char *kutf_str_ptr = NULL;
385379 size_t kutf_str_len = 0;
386380 size_t message_len = 0;
387381 char separator = ':';
....@@ -493,7 +487,7 @@
493487 }
494488
495489 /**
496
- * kutf_debugfs_run_write() Debugfs write callback for the "run" entry.
490
+ * kutf_debugfs_run_write() - Debugfs write callback for the "run" entry.
497491 * @file: Opened file to write to
498492 * @buf: User buffer to read the data from
499493 * @len: Amount of data to write
....@@ -582,31 +576,27 @@
582576
583577 snprintf(name, sizeof(name), "%d", fixture_index);
584578 test_fix->dir = debugfs_create_dir(name, test_func->dir);
585
- if (!test_func->dir) {
579
+ if (IS_ERR_OR_NULL(test_func->dir)) {
586580 pr_err("Failed to create debugfs directory when adding fixture\n");
587581 /* Might not be the right error, we don't get it passed back to us */
588582 err = -EEXIST;
589583 goto fail_dir;
590584 }
591585
592
- tmp = debugfs_create_file("type", S_IROTH, test_fix->dir, "fixture\n",
586
+ tmp = debugfs_create_file("type", 0004, test_fix->dir, "fixture\n",
593587 &kutf_debugfs_const_string_ops);
594
- if (!tmp) {
588
+ if (IS_ERR_OR_NULL(tmp)) {
595589 pr_err("Failed to create debugfs file \"type\" when adding fixture\n");
596590 /* Might not be the right error, we don't get it passed back to us */
597591 err = -EEXIST;
598592 goto fail_file;
599593 }
600594
601
-#if KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE
602595 tmp = debugfs_create_file_unsafe(
603
-#else
604
- tmp = debugfs_create_file(
605
-#endif
606596 "run", 0600, test_fix->dir,
607597 test_fix,
608598 &kutf_debugfs_run_ops);
609
- if (!tmp) {
599
+ if (IS_ERR_OR_NULL(tmp)) {
610600 pr_err("Failed to create debugfs file \"run\" when adding fixture\n");
611601 /* Might not be the right error, we don't get it passed back to us */
612602 err = -EEXIST;
....@@ -666,39 +656,39 @@
666656 INIT_LIST_HEAD(&test_func->variant_list);
667657
668658 test_func->dir = debugfs_create_dir(name, suite->dir);
669
- if (!test_func->dir) {
659
+ if (IS_ERR_OR_NULL(test_func->dir)) {
670660 pr_err("Failed to create debugfs directory when adding test %s\n", name);
671661 goto fail_dir;
672662 }
673663
674
- tmp = debugfs_create_file("type", S_IROTH, test_func->dir, "test\n",
664
+ tmp = debugfs_create_file("type", 0004, test_func->dir, "test\n",
675665 &kutf_debugfs_const_string_ops);
676
- if (!tmp) {
666
+ if (IS_ERR_OR_NULL(tmp)) {
677667 pr_err("Failed to create debugfs file \"type\" when adding test %s\n", name);
678668 goto fail_file;
679669 }
680670
681671 test_func->filters = filters;
682672 #if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE
683
- tmp = debugfs_create_file_unsafe("filters", S_IROTH, test_func->dir,
673
+ tmp = debugfs_create_file_unsafe("filters", 0004, test_func->dir,
684674 &test_func->filters, &kutfp_fops_x32_ro);
685675 #else
686
- tmp = debugfs_create_x32("filters", S_IROTH, test_func->dir,
676
+ tmp = debugfs_create_x32("filters", 0004, test_func->dir,
687677 &test_func->filters);
688678 #endif
689
- if (!tmp) {
679
+ if (IS_ERR_OR_NULL(tmp)) {
690680 pr_err("Failed to create debugfs file \"filters\" when adding test %s\n", name);
691681 goto fail_file;
692682 }
693683
694684 test_func->test_id = id;
695685 #if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE
696
- debugfs_create_u32("test_id", S_IROTH, test_func->dir,
697
- &test_func->test_id);
686
+ debugfs_create_u32("test_id", 0004, test_func->dir,
687
+ &test_func->test_id);
698688 #else
699
- tmp = debugfs_create_u32("test_id", S_IROTH, test_func->dir,
689
+ tmp = debugfs_create_u32("test_id", 0004, test_func->dir,
700690 &test_func->test_id);
701
- if (!tmp) {
691
+ if (IS_ERR_OR_NULL(tmp)) {
702692 pr_err("Failed to create debugfs file \"test_id\" when adding test %s\n", name);
703693 goto fail_file;
704694 }
....@@ -766,7 +756,7 @@
766756 EXPORT_SYMBOL(kutf_add_test);
767757
768758 /**
769
- * kutf_remove_test(): Remove a previously added test function.
759
+ * kutf_remove_test() - Remove a previously added test function.
770760 * @test_func: Test function
771761 */
772762 static void kutf_remove_test(struct kutf_test_function *test_func)
....@@ -805,14 +795,14 @@
805795 }
806796
807797 suite->dir = debugfs_create_dir(name, app->dir);
808
- if (!suite->dir) {
798
+ if (IS_ERR_OR_NULL(suite->dir)) {
809799 pr_err("Failed to create debugfs directory when adding test %s\n", name);
810800 goto fail_debugfs;
811801 }
812802
813
- tmp = debugfs_create_file("type", S_IROTH, suite->dir, "suite\n",
803
+ tmp = debugfs_create_file("type", 0004, suite->dir, "suite\n",
814804 &kutf_debugfs_const_string_ops);
815
- if (!tmp) {
805
+ if (IS_ERR_OR_NULL(tmp)) {
816806 pr_err("Failed to create debugfs file \"type\" when adding test %s\n", name);
817807 goto fail_file;
818808 }
....@@ -913,14 +903,14 @@
913903 }
914904
915905 app->dir = debugfs_create_dir(name, base_dir);
916
- if (!app->dir) {
906
+ if (IS_ERR_OR_NULL(app->dir)) {
917907 pr_err("Failed to create debugfs direcotry when creating application %s\n", name);
918908 goto fail_debugfs;
919909 }
920910
921
- tmp = debugfs_create_file("type", S_IROTH, app->dir, "application\n",
911
+ tmp = debugfs_create_file("type", 0004, app->dir, "application\n",
922912 &kutf_debugfs_const_string_ops);
923
- if (!tmp) {
913
+ if (IS_ERR_OR_NULL(tmp)) {
924914 pr_err("Failed to create debugfs file \"type\" when creating application %s\n", name);
925915 goto fail_file;
926916 }
....@@ -1162,8 +1152,9 @@
11621152
11631153 /**
11641154 * init_kutf_core() - Module entry point.
1165
- *
11661155 * Create the base entry point in debugfs.
1156
+ *
1157
+ * Return: 0 on success, error code otherwise.
11671158 */
11681159 static int __init init_kutf_core(void)
11691160 {
....@@ -1172,7 +1163,7 @@
11721163 return -ENOMEM;
11731164
11741165 base_dir = debugfs_create_dir("kutf_tests", NULL);
1175
- if (!base_dir) {
1166
+ if (IS_ERR_OR_NULL(base_dir)) {
11761167 destroy_workqueue(kutf_workq);
11771168 kutf_workq = NULL;
11781169 return -ENOMEM;
....@@ -1197,9 +1188,10 @@
11971188 #else /* CONFIG_DEBUG_FS */
11981189
11991190 /**
1200
- * init_kutf_core() - Module entry point.
1191
+ * init_kutf_core - Module entry point
1192
+ * Stub for when build against a kernel without debugfs support.
12011193 *
1202
- * Stub for when build against a kernel without debugfs support
1194
+ * Return: -ENODEV
12031195 */
12041196 static int __init init_kutf_core(void)
12051197 {