|
9 | 9 | * Cirrus Logic International Semiconductor Ltd. |
10 | 10 | */ |
11 | 11 |
|
| 12 | +#include <kunit/static_stub.h> |
12 | 13 | #include <kunit/visibility.h> |
13 | 14 | #include <linux/cleanup.h> |
14 | 15 | #include <linux/ctype.h> |
|
18 | 19 | #include <linux/minmax.h> |
19 | 20 | #include <linux/module.h> |
20 | 21 | #include <linux/moduleparam.h> |
| 22 | +#include <linux/ratelimit.h> |
21 | 23 | #include <linux/seq_file.h> |
22 | 24 | #include <linux/slab.h> |
23 | 25 | #include <linux/vmalloc.h> |
|
30 | 32 | /* |
31 | 33 | * When the KUnit test is running the error-case tests will cause a lot |
32 | 34 | * of messages. Rate-limit to prevent overflowing the kernel log buffer |
33 | | - * during KUnit test runs. |
| 35 | + * during KUnit test runs and allow the test to redirect this function. |
| 36 | + * In normal (not KUnit) builds this collapses to only return true. |
34 | 37 | */ |
35 | | -#if IS_ENABLED(CONFIG_FW_CS_DSP_KUNIT_TEST) |
36 | | -bool cs_dsp_suppress_err_messages; |
37 | | -EXPORT_SYMBOL_IF_KUNIT(cs_dsp_suppress_err_messages); |
| 38 | +VISIBLE_IF_KUNIT bool cs_dsp_can_emit_message(void) |
| 39 | +{ |
| 40 | + KUNIT_STATIC_STUB_REDIRECT(cs_dsp_can_emit_message); |
38 | 41 |
|
39 | | -bool cs_dsp_suppress_warn_messages; |
40 | | -EXPORT_SYMBOL_IF_KUNIT(cs_dsp_suppress_warn_messages); |
| 42 | + if (IS_ENABLED(CONFIG_FW_CS_DSP_KUNIT_TEST)) { |
| 43 | + static DEFINE_RATELIMIT_STATE(_rs, |
| 44 | + DEFAULT_RATELIMIT_INTERVAL, |
| 45 | + DEFAULT_RATELIMIT_BURST); |
| 46 | + return __ratelimit(&_rs); |
| 47 | + } |
41 | 48 |
|
42 | | -bool cs_dsp_suppress_info_messages; |
43 | | -EXPORT_SYMBOL_IF_KUNIT(cs_dsp_suppress_info_messages); |
| 49 | + return true; |
| 50 | +} |
| 51 | +EXPORT_SYMBOL_IF_KUNIT(cs_dsp_can_emit_message); |
44 | 52 |
|
45 | | -#define cs_dsp_err(_dsp, fmt, ...) \ |
46 | | - do { \ |
47 | | - if (!cs_dsp_suppress_err_messages) \ |
48 | | - dev_err_ratelimited(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
| 53 | +#define cs_dsp_err(_dsp, fmt, ...) \ |
| 54 | + do { \ |
| 55 | + if (cs_dsp_can_emit_message()) \ |
| 56 | + dev_err(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
49 | 57 | } while (false) |
50 | | -#define cs_dsp_warn(_dsp, fmt, ...) \ |
51 | | - do { \ |
52 | | - if (!cs_dsp_suppress_warn_messages) \ |
53 | | - dev_warn_ratelimited(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
| 58 | + |
| 59 | +#define cs_dsp_warn(_dsp, fmt, ...) \ |
| 60 | + do { \ |
| 61 | + if (cs_dsp_can_emit_message()) \ |
| 62 | + dev_warn(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
54 | 63 | } while (false) |
55 | | -#define cs_dsp_info(_dsp, fmt, ...) \ |
56 | | - do { \ |
57 | | - if (!cs_dsp_suppress_info_messages) \ |
58 | | - dev_info_ratelimited(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
| 64 | + |
| 65 | +#define cs_dsp_info(_dsp, fmt, ...) \ |
| 66 | + do { \ |
| 67 | + if (cs_dsp_can_emit_message()) \ |
| 68 | + dev_info(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
| 69 | + } while (false) |
| 70 | + |
| 71 | +#define cs_dsp_dbg(_dsp, fmt, ...) \ |
| 72 | + do { \ |
| 73 | + if (cs_dsp_can_emit_message()) \ |
| 74 | + dev_dbg(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__); \ |
59 | 75 | } while (false) |
60 | | -#define cs_dsp_dbg(_dsp, fmt, ...) \ |
61 | | - dev_dbg_ratelimited(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__) |
62 | | -#else |
63 | | -#define cs_dsp_err(_dsp, fmt, ...) \ |
64 | | - dev_err(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__) |
65 | | -#define cs_dsp_warn(_dsp, fmt, ...) \ |
66 | | - dev_warn(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__) |
67 | | -#define cs_dsp_info(_dsp, fmt, ...) \ |
68 | | - dev_info(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__) |
69 | | -#define cs_dsp_dbg(_dsp, fmt, ...) \ |
70 | | - dev_dbg(_dsp->dev, "%s: " fmt, _dsp->name, ##__VA_ARGS__) |
71 | | -#endif |
72 | 76 |
|
73 | 77 | #define ADSP1_CONTROL_1 0x00 |
74 | 78 | #define ADSP1_CONTROL_2 0x02 |
|
0 commit comments