|WARNING| bus/dpaa: defer bus initialization to probe

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Thu Aug 27 09:50:04 CEST 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/168432

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-27

# DPDK Patch Review

## Summary
This patch refactors DPAA bus initialization, moving most initialization logic from `scan` to `probe` to avoid dependencies on DPDK heap/memzone which are not available during scan.

---

## Errors

### 1. Resource leak on error path in rte_dpaa_bus_probe

**File:** drivers/bus/dpaa/dpaa_bus.c  
**Function:** rte_dpaa_bus_probe  
**Lines:** ~825-843

After `qman_global_init()` succeeds at line 831, if `bman_global_init()` fails at line 836, the function returns without calling a corresponding `qman_global_cleanup()`.

```c
/* Current code */
ret = qman_global_init();
if (ret) {
    DPAA_BUS_ERR("QMAN global init failed (%d)", ret);
    return ret;
}
ret = bman_global_init();
if (ret) {
    DPAA_BUS_ERR("BMAN global init failed (%d)", ret);
    return ret;  /* ERROR: qman not cleaned up */
}
```

**Suggested fix:**
```c
ret = qman_global_init();
if (ret) {
    DPAA_BUS_ERR("QMAN global init failed (%d)", ret);
    return ret;
}
ret = bman_global_init();
if (ret) {
    DPAA_BUS_ERR("BMAN global init failed (%d)", ret);
    qman_global_cleanup();  /* Clean up qman on bman failure */
    return ret;
}
```

### 2. Missing error check on rte_dpaa_bus_dev_build() (original code)

**File:** drivers/bus/dpaa/dpaa_bus.c  
**Function:** rte_dpaa_bus_scan (removed code)  
**Lines:** Original scan function (pre-patch)

The original code called `rte_dpaa_bus_dev_build()` without checking its return value. While the patch fixes this by adding the check in `probe`, this confirms the original code had a bug.

**Good:** The patch correctly adds error checking for `rte_dpaa_bus_dev_build()` in the new location.

---

## Warnings

### 1. Potential race condition on process_once flag

**File:** drivers/bus/dpaa/dpaa_bus.c  
**Function:** rte_dpaa_bus_probe  
**Line:** ~815, ~843

The `process_once` static variable is checked and set without synchronization. If `rte_dpaa_bus_probe()` could be called concurrently (unlikely but possible in a multi-threaded EAL scenario), two threads could both see `process_once == 0` and both execute the initialization block.

**Suggested fix (if concurrent probe is possible):**
```c
static rte_spinlock_t init_lock = RTE_SPINLOCK_INITIALIZER;
static int process_once;

/* In rte_dpaa_bus_probe(): */
rte_spinlock_lock(&init_lock);
if (!process_once) {
    /* ... initialization ... */
    process_once = 1;
}
rte_spinlock_unlock(&init_lock);
```

However, if the DPDK bus framework guarantees single-threaded probe, this is acceptable. The original code had the same pattern, suggesting it's intentional.

### 2. dpaa_bus.detected flag not set anywhere in visible code

**File:** drivers/bus/dpaa/dpaa_bus.c  
**Function:** rte_dpaa_bus_probe  
**Line:** ~817

The code checks `if (!dpaa_bus.detected) return 0;` but the patch context doesn't show where `dpaa_bus.detected` is set. If scan doesn't set this flag, probe will always return 0.

**Verification needed:** Ensure that `rte_dpaa_bus_scan()` sets `dpaa_bus.detected = true` when the hardware is found (likely happens at line ~804 area based on the svr_ver logic, but not visible in the patch context).

### 3. Missing corresponding cleanup for dpaa_bus_global_init flag

**File:** drivers/bus/dpaa/dpaa_bus.c  
**Line:** ~866

The `dpaa_bus_global_init` flag is set to 1 but there's no visible error path in this function that would reset it if `rte_bus_generic_probe()` fails on line 868. If probe fails after setting this flag, a retry would skip initialization.

**Suggested fix:**
```c
dpaa_bus_global_init = 1;

ret = rte_bus_generic_probe(bus);
if (ret != 0) {
    dpaa_bus_global_init = 0;  /* Reset on probe failure */
    return ret;
}
return 0;
```

---

## Info

### 1. Consider adding release notes entry

Since this changes the initialization order significantly, consider adding a note to `doc/guides/rel_notes/release_XX_YY.rst` explaining the behavioral change.

### 2. Improved error message clarity

The error message at line ~827 could include more context:

```c
DPAA_BUS_ERR("Unable to build device list. (%d)", ret);
```

Could be:
```c
DPAA_BUS_ERR("Failed to build DPAA device list during probe: %d", ret);
```

This distinguishes it from other initialization failures and makes logs clearer.

---

## Positive Observations

1. **Good:** The patch correctly adds error checking for `rte_dpaa_bus_dev_build()` that was missing in the original code
2. **Good:** The separation of scan vs probe responsibilities aligns with DPDK bus model (scan for detection, probe for initialization)
3. **Good:** The commit message clearly explains the motivation (heap/memzone dependency)

---

## Summary

**Critical issues:** 1 error (resource leak on bman_global_init failure)  
**Recommended fixes:** 2 warnings (process_once race if concurrent probe possible, dpaa_bus_global_init not reset on failure)  
**Suggestions:** 2 info items (release notes, error message clarity)

The most important fix is adding cleanup for qman when bman initialization fails.


More information about the test-report mailing list