diff options
author | Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> | 2022-02-22 10:41:20 +0100 |
---|---|---|
committer | Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> | 2022-02-22 15:50:50 +0100 |
commit | 5f3cfa485eb46902e55c6b96c80dc8c57ddf3b43 (patch) | |
tree | e8b9d7488332ff8ca589c6b33b59ecb9c4ec1eba /lib/igt_core.h | |
parent | 0696e8b9cd5f0e112f4d5459e03a1d4d6bb95d9a (diff) |
lib: Use safe wrappers around libpciaccess initialization functions
Multiple calls to igt functions using pci_system_init() provided by
libpciaccess result in memory leaking if not followed by its counterpart
pci_system_cleanup() before next use. On the other hand, calling
pci_system_cleanup() can affect other users which still depend on global
data initialized by pci_system_init().
Introduce safe IGT wrappers around those libpciaccess functions and use
those wrappers in IGT library and tests.
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
[jkrzyszt: shorten excessive long name of hidden variable (Chris)]
Reviewed-by: Chris Wilson <chris.p.wilson@intel.com>
Diffstat (limited to 'lib/igt_core.h')
-rw-r--r-- | lib/igt_core.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h index 0aad161d..78dc6202 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -1452,4 +1452,32 @@ void igt_kmsg(const char *format, ...); #define for_if(expr__) if (!(expr__)) {} else +/** + * igt_pci_system_init: + * IGT wrapper around pci_system_init() + * + * Runs pci_system_init() and installs pci_system_cleanup() as IGT exit handler when + * called first per thread, subsequent calls are noop. Tests should use this wrapper + * instead of pci_system_init() to avoid memory leaking which happens each time a call + * to pci_system_init() is repeated not preceded by pci_system_cleanup() (may easily + * happen in consequence of long jumps performed by IGT flow control functions). + * + * Return value: equal return value of pthread_once() (return value of pci_system_init() + * can't be passed through pthread_once()) + */ +int igt_pci_system_init(void); + +/** + * igt_pci_system_cleanup(): + * IGT replacement for pci_system_cleanup() + * + * For use in IGT library and tests to avoid destroying libpciaccess global data. + * Direct calls to pci_system_cleanup() should be either dropped or replaced with this + * wrapper (for code clarity), otherwise subsequent access to libpciaccess global data + * may be lost unless preceded by direct call to pci_system_init() (not recommended). + */ +static inline void igt_pci_system_cleanup(void) +{ +} + #endif /* IGT_CORE_H */ |