Skip to content

Conversation

@jishengruofou
Copy link

@jishengruofou jishengruofou commented Jan 8, 2026

修改ppp_netdev_add中先使用ppp_device->pppif.name,后才赋值的问题

Summary by CodeRabbit

  • Bug Fixes
    • PPP network device initialization adjusted so the interface name is established before registration, improving interface identification and registration consistency and removing an earlier default-route handling path.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Walkthrough

Reordered the ppp_netdev_add() invocation in src/ppp_device.c::ppp_device_open() so it is called after the network interface name is assigned; removed the prior early return/logging block that handled pppapi_set_default failure and explicit default-route handling in that path.

Changes

Cohort / File(s) Summary
PPP device initialization reordering
src/ppp_device.c
Moved ppp_netdev_add(&ppp_device->pppif) to occur after netif name assignment in ppp_device_open(); removed the previous conditional log/early-return block related to pppapi_set_default and explicit default-route handling so netdev registration is now unconditional after name setup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the order of operations where pppif.name is now assigned before being used in ppp_netdev_add.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ppp_device.c (1)

381-387: Update the error message to reflect the actual operation.

The error message references "pppapi_set_default execute failed" but this block checks the result of ppp_netdev_add (or previously an unrelated operation). The message should accurately describe the failure.

📝 Proposed fix
     if (result != RT_EOK)
     {
-        LOG_E("pppapi_set_default execute failed.");
+        LOG_E("ppp_netdev_add failed.");
         result = -RT_ERROR;
         goto __exit;
     }
-    LOG_D("pppapi_set_default has set a default route.");
+    LOG_D("ppp netdev registered successfully.");
🤖 Fix all issues with AI agents
In @src/ppp_device.c:
- Line 379: ppp_netdev_add's return value must be captured and checked so
failures don't go unnoticed; modify the call where
ppp_netdev_add(&ppp_device->pppif) is invoked to store the returned int, test
for non-zero/failure, log a descriptive error (including the returned
errno/code) and perform appropriate cleanup/return (e.g., free ppp_device, undo
prior allocations, or goto an error label) instead of proceeding as if
registration succeeded.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0309505 and ec1d866.

📒 Files selected for processing (1)
  • src/ppp_device.c
🧰 Additional context used
🧬 Code graph analysis (1)
src/ppp_device.c (1)
src/ppp_netif.c (1)
  • ppp_netdev_add (31-76)
🔇 Additional comments (1)
src/ppp_device.c (1)

374-380: Excellent fix for use-before-initialization bug!

The reordering correctly ensures ppp_device->pppif.name is assigned (lines 376-377) before ppp_netdev_add reads it. Previously, ppp_netdev_add would have read uninitialized memory since it calls rt_strncpy(name, ppp_netif->name, LWIP_NETIF_NAME_LEN) internally.

ppp_device->pppif.name[0] = ppp_device->parent.parent.name[0];
ppp_device->pppif.name[1] = ppp_device->parent.parent.name[1];

ppp_netdev_add(&ppp_device->pppif);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Capture and check the return value of ppp_netdev_add.

The return value of ppp_netdev_add is not being captured or checked. If registration fails, the function continues without detecting the error.

🔧 Proposed fix
-    ppp_netdev_add(&ppp_device->pppif);
+    result = ppp_netdev_add(&ppp_device->pppif);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ppp_netdev_add(&ppp_device->pppif);
result = ppp_netdev_add(&ppp_device->pppif);
🤖 Prompt for AI Agents
In @src/ppp_device.c at line 379, ppp_netdev_add's return value must be captured
and checked so failures don't go unnoticed; modify the call where
ppp_netdev_add(&ppp_device->pppif) is invoked to store the returned int, test
for non-zero/failure, log a descriptive error (including the returned
errno/code) and perform appropriate cleanup/return (e.g., free ppp_device, undo
prior allocations, or goto an error label) instead of proceeding as if
registration succeeded.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/ppp_device.c (1)

379-379: Consider checking the return value of ppp_netdev_add().

The function ppp_netdev_add() can fail if memory allocation for the netdev structure fails (returns -ERR_IF) or if netdev_register() fails. While the PPP connection might still function at the protocol level, netdev subsystem integration would be incomplete.

♻️ Proposed error handling
-    ppp_netdev_add(&ppp_device->pppif);
+    result = ppp_netdev_add(&ppp_device->pppif);
+    if (result != RT_EOK)
+    {
+        LOG_W("ppp_netdev_add failed, netdev integration unavailable.");
+    }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec1d866 and 44e9f86.

📒 Files selected for processing (1)
  • src/ppp_device.c
🧰 Additional context used
🧬 Code graph analysis (1)
src/ppp_device.c (1)
src/ppp_netif.c (1)
  • ppp_netdev_add (31-76)
🔇 Additional comments (1)
src/ppp_device.c (1)

374-377: LGTM! Use-before-assign issue correctly fixed.

The network interface name is now assigned before calling ppp_netdev_add(), which prevents the use-before-assign bug. The function ppp_netdev_add() reads ppp_netif->name (line 54 in ppp_netif.c), so this ordering is essential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant