Tomasz Bursztyka | 72d9e8c | 2020-06-30 15:08:06 +0200 | [diff] [blame] | 1 | // Copyright (c) 2020 Intel Corporation |
Nazar Kazakov | f483b1b | 2022-03-16 21:07:43 +0000 | [diff] [blame] | 2 | // SPDX-License-Identifier: Apache-2.0 |
Tomasz Bursztyka | 72d9e8c | 2020-06-30 15:08:06 +0200 | [diff] [blame] | 3 | |
| 4 | // Uses a python database (a dict) to find where const struct device |
| 5 | // variable are being used in zephyr functions and, if it's being in place |
| 6 | // of a void*, it will print an ERROR for loosing the const qualifier. |
| 7 | // If it's being used on an unknown functions from an external module such |
| 8 | // as a HAL, it will print a WARNING in order to check if the const qualifier |
| 9 | // is not lost. |
| 10 | |
| 11 | virtual report |
| 12 | |
| 13 | //////////////////// |
| 14 | // Initialization // |
| 15 | //////////////////// |
| 16 | |
| 17 | @initialize:python |
| 18 | depends on report |
| 19 | @ |
| 20 | @@ |
| 21 | import pickle |
| 22 | |
| 23 | def check_and_report(F, f, D, nb_args, p): |
| 24 | if f in f_void and int(nb_args) in f_void[f]: |
| 25 | msg = "ERROR: in {} calling {} param with {}, \ |
| 26 | loosing const qualifier, please wrap".format(F, f, D) |
| 27 | coccilib.report.print_report(p[0], msg) |
| 28 | elif f not in f_void and f not in f_other and not f.isupper(): |
| 29 | msg = "WARNING: in {} calling {} param with {}, \ |
| 30 | check if const qualifier is not lost".format(F, f, D) |
| 31 | coccilib.report.print_report(p[0], msg) |
| 32 | |
| 33 | // Loading function data base |
| 34 | with open("function_names.pickle", "rb") as f: |
| 35 | data = pickle.load(f) |
| 36 | f_void = data["f_void"] |
| 37 | f_other = data["f_other"] |
| 38 | |
| 39 | |
| 40 | /////////// |
| 41 | // Rules // |
| 42 | /////////// |
| 43 | |
| 44 | // Find usage of a device instance |
| 45 | @r_find_dev_usage |
| 46 | depends on report |
| 47 | @ |
| 48 | local idexpression struct device *D; |
| 49 | expression list[nb_args] args; |
| 50 | identifier f; |
| 51 | position p; |
| 52 | @@ |
| 53 | f(args, D@p, ...) |
| 54 | |
| 55 | |
| 56 | @script:python |
| 57 | depends on r_find_dev_usage |
| 58 | @ |
| 59 | f << r_find_dev_usage.f; |
| 60 | D << r_find_dev_usage.D; |
| 61 | nb_args << r_find_dev_usage.nb_args; |
| 62 | p << r_find_dev_usage.p; |
| 63 | @@ |
| 64 | check_and_report(p[0].current_element, f, D, nb_args, p) |