.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note |
---|
2 | 2 | /* |
---|
3 | 3 | * |
---|
4 | | - * (C) COPYRIGHT 2014, 2017-2021 ARM Limited. All rights reserved. |
---|
| 4 | + * (C) COPYRIGHT 2014, 2017-2022 ARM Limited. All rights reserved. |
---|
5 | 5 | * |
---|
6 | 6 | * This program is free software and is provided to you under the terms of the |
---|
7 | 7 | * GNU General Public License version 2 as published by the Free Software |
---|
.. | .. |
---|
106 | 106 | enum kutf_result_status result; |
---|
107 | 107 | }; |
---|
108 | 108 | |
---|
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), |
---|
125 | 119 | }; |
---|
126 | 120 | |
---|
127 | 121 | #define UTF_CONVERT_SIZE (ARRAY_SIZE(kutf_convert)) |
---|
.. | .. |
---|
191 | 185 | * |
---|
192 | 186 | * Return: 1 if test result was successfully converted to string, 0 otherwise |
---|
193 | 187 | */ |
---|
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) |
---|
196 | 189 | { |
---|
197 | 190 | int i; |
---|
198 | 191 | int ret = 0; |
---|
.. | .. |
---|
319 | 312 | } |
---|
320 | 313 | |
---|
321 | 314 | /** |
---|
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 | + * |
---|
323 | 317 | * @inode: inode of the opened file |
---|
324 | 318 | * @file: Opened file to read from |
---|
325 | 319 | * |
---|
.. | .. |
---|
381 | 375 | struct kutf_result *res; |
---|
382 | 376 | unsigned long bytes_not_copied; |
---|
383 | 377 | ssize_t bytes_copied = 0; |
---|
384 | | - char *kutf_str_ptr = NULL; |
---|
| 378 | + const char *kutf_str_ptr = NULL; |
---|
385 | 379 | size_t kutf_str_len = 0; |
---|
386 | 380 | size_t message_len = 0; |
---|
387 | 381 | char separator = ':'; |
---|
.. | .. |
---|
493 | 487 | } |
---|
494 | 488 | |
---|
495 | 489 | /** |
---|
496 | | - * kutf_debugfs_run_write() Debugfs write callback for the "run" entry. |
---|
| 490 | + * kutf_debugfs_run_write() - Debugfs write callback for the "run" entry. |
---|
497 | 491 | * @file: Opened file to write to |
---|
498 | 492 | * @buf: User buffer to read the data from |
---|
499 | 493 | * @len: Amount of data to write |
---|
.. | .. |
---|
582 | 576 | |
---|
583 | 577 | snprintf(name, sizeof(name), "%d", fixture_index); |
---|
584 | 578 | test_fix->dir = debugfs_create_dir(name, test_func->dir); |
---|
585 | | - if (!test_func->dir) { |
---|
| 579 | + if (IS_ERR_OR_NULL(test_func->dir)) { |
---|
586 | 580 | pr_err("Failed to create debugfs directory when adding fixture\n"); |
---|
587 | 581 | /* Might not be the right error, we don't get it passed back to us */ |
---|
588 | 582 | err = -EEXIST; |
---|
589 | 583 | goto fail_dir; |
---|
590 | 584 | } |
---|
591 | 585 | |
---|
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", |
---|
593 | 587 | &kutf_debugfs_const_string_ops); |
---|
594 | | - if (!tmp) { |
---|
| 588 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
595 | 589 | pr_err("Failed to create debugfs file \"type\" when adding fixture\n"); |
---|
596 | 590 | /* Might not be the right error, we don't get it passed back to us */ |
---|
597 | 591 | err = -EEXIST; |
---|
598 | 592 | goto fail_file; |
---|
599 | 593 | } |
---|
600 | 594 | |
---|
601 | | -#if KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE |
---|
602 | 595 | tmp = debugfs_create_file_unsafe( |
---|
603 | | -#else |
---|
604 | | - tmp = debugfs_create_file( |
---|
605 | | -#endif |
---|
606 | 596 | "run", 0600, test_fix->dir, |
---|
607 | 597 | test_fix, |
---|
608 | 598 | &kutf_debugfs_run_ops); |
---|
609 | | - if (!tmp) { |
---|
| 599 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
610 | 600 | pr_err("Failed to create debugfs file \"run\" when adding fixture\n"); |
---|
611 | 601 | /* Might not be the right error, we don't get it passed back to us */ |
---|
612 | 602 | err = -EEXIST; |
---|
.. | .. |
---|
666 | 656 | INIT_LIST_HEAD(&test_func->variant_list); |
---|
667 | 657 | |
---|
668 | 658 | test_func->dir = debugfs_create_dir(name, suite->dir); |
---|
669 | | - if (!test_func->dir) { |
---|
| 659 | + if (IS_ERR_OR_NULL(test_func->dir)) { |
---|
670 | 660 | pr_err("Failed to create debugfs directory when adding test %s\n", name); |
---|
671 | 661 | goto fail_dir; |
---|
672 | 662 | } |
---|
673 | 663 | |
---|
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", |
---|
675 | 665 | &kutf_debugfs_const_string_ops); |
---|
676 | | - if (!tmp) { |
---|
| 666 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
677 | 667 | pr_err("Failed to create debugfs file \"type\" when adding test %s\n", name); |
---|
678 | 668 | goto fail_file; |
---|
679 | 669 | } |
---|
680 | 670 | |
---|
681 | 671 | test_func->filters = filters; |
---|
682 | 672 | #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, |
---|
684 | 674 | &test_func->filters, &kutfp_fops_x32_ro); |
---|
685 | 675 | #else |
---|
686 | | - tmp = debugfs_create_x32("filters", S_IROTH, test_func->dir, |
---|
| 676 | + tmp = debugfs_create_x32("filters", 0004, test_func->dir, |
---|
687 | 677 | &test_func->filters); |
---|
688 | 678 | #endif |
---|
689 | | - if (!tmp) { |
---|
| 679 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
690 | 680 | pr_err("Failed to create debugfs file \"filters\" when adding test %s\n", name); |
---|
691 | 681 | goto fail_file; |
---|
692 | 682 | } |
---|
693 | 683 | |
---|
694 | 684 | test_func->test_id = id; |
---|
695 | 685 | #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); |
---|
698 | 688 | #else |
---|
699 | | - tmp = debugfs_create_u32("test_id", S_IROTH, test_func->dir, |
---|
| 689 | + tmp = debugfs_create_u32("test_id", 0004, test_func->dir, |
---|
700 | 690 | &test_func->test_id); |
---|
701 | | - if (!tmp) { |
---|
| 691 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
702 | 692 | pr_err("Failed to create debugfs file \"test_id\" when adding test %s\n", name); |
---|
703 | 693 | goto fail_file; |
---|
704 | 694 | } |
---|
.. | .. |
---|
766 | 756 | EXPORT_SYMBOL(kutf_add_test); |
---|
767 | 757 | |
---|
768 | 758 | /** |
---|
769 | | - * kutf_remove_test(): Remove a previously added test function. |
---|
| 759 | + * kutf_remove_test() - Remove a previously added test function. |
---|
770 | 760 | * @test_func: Test function |
---|
771 | 761 | */ |
---|
772 | 762 | static void kutf_remove_test(struct kutf_test_function *test_func) |
---|
.. | .. |
---|
805 | 795 | } |
---|
806 | 796 | |
---|
807 | 797 | suite->dir = debugfs_create_dir(name, app->dir); |
---|
808 | | - if (!suite->dir) { |
---|
| 798 | + if (IS_ERR_OR_NULL(suite->dir)) { |
---|
809 | 799 | pr_err("Failed to create debugfs directory when adding test %s\n", name); |
---|
810 | 800 | goto fail_debugfs; |
---|
811 | 801 | } |
---|
812 | 802 | |
---|
813 | | - tmp = debugfs_create_file("type", S_IROTH, suite->dir, "suite\n", |
---|
| 803 | + tmp = debugfs_create_file("type", 0004, suite->dir, "suite\n", |
---|
814 | 804 | &kutf_debugfs_const_string_ops); |
---|
815 | | - if (!tmp) { |
---|
| 805 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
816 | 806 | pr_err("Failed to create debugfs file \"type\" when adding test %s\n", name); |
---|
817 | 807 | goto fail_file; |
---|
818 | 808 | } |
---|
.. | .. |
---|
913 | 903 | } |
---|
914 | 904 | |
---|
915 | 905 | app->dir = debugfs_create_dir(name, base_dir); |
---|
916 | | - if (!app->dir) { |
---|
| 906 | + if (IS_ERR_OR_NULL(app->dir)) { |
---|
917 | 907 | pr_err("Failed to create debugfs direcotry when creating application %s\n", name); |
---|
918 | 908 | goto fail_debugfs; |
---|
919 | 909 | } |
---|
920 | 910 | |
---|
921 | | - tmp = debugfs_create_file("type", S_IROTH, app->dir, "application\n", |
---|
| 911 | + tmp = debugfs_create_file("type", 0004, app->dir, "application\n", |
---|
922 | 912 | &kutf_debugfs_const_string_ops); |
---|
923 | | - if (!tmp) { |
---|
| 913 | + if (IS_ERR_OR_NULL(tmp)) { |
---|
924 | 914 | pr_err("Failed to create debugfs file \"type\" when creating application %s\n", name); |
---|
925 | 915 | goto fail_file; |
---|
926 | 916 | } |
---|
.. | .. |
---|
1162 | 1152 | |
---|
1163 | 1153 | /** |
---|
1164 | 1154 | * init_kutf_core() - Module entry point. |
---|
1165 | | - * |
---|
1166 | 1155 | * Create the base entry point in debugfs. |
---|
| 1156 | + * |
---|
| 1157 | + * Return: 0 on success, error code otherwise. |
---|
1167 | 1158 | */ |
---|
1168 | 1159 | static int __init init_kutf_core(void) |
---|
1169 | 1160 | { |
---|
.. | .. |
---|
1172 | 1163 | return -ENOMEM; |
---|
1173 | 1164 | |
---|
1174 | 1165 | base_dir = debugfs_create_dir("kutf_tests", NULL); |
---|
1175 | | - if (!base_dir) { |
---|
| 1166 | + if (IS_ERR_OR_NULL(base_dir)) { |
---|
1176 | 1167 | destroy_workqueue(kutf_workq); |
---|
1177 | 1168 | kutf_workq = NULL; |
---|
1178 | 1169 | return -ENOMEM; |
---|
.. | .. |
---|
1197 | 1188 | #else /* CONFIG_DEBUG_FS */ |
---|
1198 | 1189 | |
---|
1199 | 1190 | /** |
---|
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. |
---|
1201 | 1193 | * |
---|
1202 | | - * Stub for when build against a kernel without debugfs support |
---|
| 1194 | + * Return: -ENODEV |
---|
1203 | 1195 | */ |
---|
1204 | 1196 | static int __init init_kutf_core(void) |
---|
1205 | 1197 | { |
---|