Skip to content

Commit b565683

Browse files
finikorgnashif
authored andcommitted
tests: ibecc: Fix using global device pointer
Removing global device pointer fixes issues with uninitialized device. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent 69ac4b2 commit b565683

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/subsys/edac/ibecc/src/ibecc.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#define DURATION 100
2323
#endif
2424

25-
const struct device *dev;
26-
2725
static void test_ibecc_initialized(void)
2826
{
27+
const struct device *dev;
28+
2929
dev = device_get_binding(DEVICE_NAME);
3030
zassert_not_null(dev, "Device not found");
3131

@@ -52,11 +52,15 @@ static void callback(const struct device *d, void *data)
5252

5353
static void test_ibecc_api(void)
5454
{
55+
const struct device *dev;
5556
uint64_t value;
5657
int ret;
5758

5859
/* Error log API */
5960

61+
dev = device_get_binding(DEVICE_NAME);
62+
zassert_not_null(dev, "Device not found");
63+
6064
ret = edac_ecc_error_log_get(dev, &value);
6165
zassert_equal(ret, -ENODATA, "edac_ecc_error_log_get failed");
6266

@@ -86,10 +90,14 @@ static void test_ibecc_api(void)
8690
#if defined(CONFIG_EDAC_ERROR_INJECT)
8791
static void test_ibecc_error_inject_api(void)
8892
{
93+
const struct device *dev;
8994
uint32_t test_value;
9095
uint64_t val;
9196
int ret;
9297

98+
dev = device_get_binding(DEVICE_NAME);
99+
zassert_not_null(dev, "Device not found");
100+
93101
/* Verify default parameters */
94102

95103
ret = edac_inject_get_error_type(dev, &test_value);
@@ -154,7 +162,8 @@ static void test_ibecc_error_inject_api(void)
154162
#endif
155163

156164
#if defined(CONFIG_EDAC_ERROR_INJECT)
157-
static void test_inject(uint64_t addr, uint64_t mask, uint8_t type)
165+
static void test_inject(const struct device *dev, uint64_t addr, uint64_t mask,
166+
uint8_t type)
158167
{
159168
unsigned int errors_cor, errors_uc;
160169
uint64_t test_addr;
@@ -258,13 +267,17 @@ static int check_values(void *p1, void *p2, void *p3)
258267

259268
static void ibecc_error_inject_test(uint64_t addr, uint64_t mask, uint64_t type)
260269
{
270+
const struct device *dev;
261271
int ret;
262272

273+
dev = device_get_binding(DEVICE_NAME);
274+
zassert_not_null(dev, "Device not found");
275+
263276
ret = edac_notify_callback_set(dev, callback);
264277
zassert_equal(ret, 0, "Error setting notification callback");
265278

266279
/* Test injecting correctable error at address TEST_ADDRESS1 */
267-
test_inject(addr, mask, type);
280+
test_inject(dev, addr, mask, type);
268281

269282
#if defined(CONFIG_USERSPACE)
270283
k_thread_user_mode_enter((k_thread_entry_t)check_values,

0 commit comments

Comments
 (0)