Skip to content

[PWCI] "[ovs-dev] checkpatch: Use the AI suggested group syntax."#5

Open
ovsrobot wants to merge 4 commits intomainfrom
series_471914
Open

[PWCI] "[ovs-dev] checkpatch: Use the AI suggested group syntax."#5
ovsrobot wants to merge 4 commits intomainfrom
series_471914

Conversation

@ovsrobot
Copy link
Owner

@ovsrobot ovsrobot commented Sep 3, 2025

NOTE: This is an auto submission for "[ovs-dev] checkpatch: Use the AI suggested group syntax.".

See "http://patchwork.ozlabs.org/project/openvswitch/list/?series=471914" for details.

Summary by Sourcery

Fix memory management and data retrieval bugs in the DPDK netdev offload code and update checkpatch script to use the new regex group syntax

Bug Fixes:

  • Free allocated spec and mask buffers on IPv4 and IPv6 frag parse errors to prevent memory leaks
  • Retrieve offload_data from physdev instead of netdev in flow destroy to fix incorrect hardware info access

Enhancements:

  • Switch checkpatch.py to use regex match group indexing (matched[1]) instead of group(1)

Summary by CodeRabbit

  • Bug Fixes

    • Resolved memory leaks in flow parsing for IPv4/IPv6 fragmentation errors.
    • Corrected flow teardown to update counters and logs on the proper device.
  • Documentation

    • Added Linda Wang to the Authors list.
  • Chores

    • Improved internal spell-check handling in the code quality checker.

Linda Wang and others added 4 commits September 1, 2025 16:52
For vport devices hardware offload counters were being incremented
on the physical device but decremented on the vport, causing
incorrect statistics that didn't return to zero when flows are
removed.

Fix by using physdev instead of netdev for counter decrements to match
the increment behavior.

Fixes: 0e6366c ("netdev-offload-dpdk: Implement hw-offload statistics read.")
Signed-off-by: Linda Wang <linda.wang@jaguarmicro.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
The error paths should release any allocated resources that are not
added to the patterns.

Found by Coverity.

Fixes: c1a5d0e ("netdev-offload-dpdk: Support IPv4 fragmentation types.")
Fixes: 1318929 ("netdev-offload-dpdk: Support IPv6 fragmentation types.")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Kevin Traynor <ktraynor@redhat.com>
Sourcery AI suggests:

  Replace m.group(x) with m[x] for re.Match objects

Suggested-by: SourceryAI <hello@sourcery.ai>
Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances error-path cleanup in DPDK flow parsing by freeing allocated buffers on failure, corrects the offload_data lookup target in flow destruction, and adopts AI-suggested regex group syntax in the checkpatch utility.

Sequence diagram for improved error cleanup in DPDK flow parsing

sequenceDiagram
participant Netdev as netdev
participant Parser as parse_flow_match
participant VLOG as VLOG_WARN_RL
participant Memory as Memory
Netdev->>Parser: parse_flow_match(...)
Parser->>Parser: Check IPv4/IPv6 frag
alt Unknown frag value
    Parser->>VLOG: VLOG_WARN_RL(...)
    Parser->>Memory: free(spec/frag_spec)
    Parser->>Memory: free(mask/frag_mask)
    Parser-->>Netdev: return -1
end
Loading

Class diagram for updated offload_data lookup in flow destruction

classDiagram
class netdev_offload_dpdk_flow_destroy {
  +unsigned int tid
  +data: netdev_offload_dpdk_data
  +physdev: netdev
  +rte_flow_counters[]
  +VLOG_DBG_RL(...)
}
class netdev {
  +hw_info: hw_info
}
class physdev {
  +hw_info: hw_info
}
class hw_info {
  +offload_data
}
class netdev_offload_dpdk_data {
  +rte_flow_counters[]
}
netdev_offload_dpdk_flow_destroy --> physdev : uses
physdev --> hw_info : has
hw_info --> netdev_offload_dpdk_data : offload_data
Loading

Class diagram for checkpatch.py spelling check group syntax update

classDiagram
class checkpatch {
  +check_spelling(line, comment_type)
}
checkpatch : check_spelling uses re.search
checkpatch : check_spelling uses matched[1] for group access
Loading

File-Level Changes

Change Details Files
Add memory cleanup on early exit in parse_flow_match for IPv4 and IPv6 fragments
  • Insert free(spec) and free(mask) before IPv4 error return
  • Insert free(frag_spec) and free(frag_mask) before IPv6 error return
lib/netdev-offload-dpdk.c
Fix offload_data retrieval in flow destroy
  • Replace ovsrcu_get using netdev->hw_info.offload_data with physdev->hw_info.offload_data
lib/netdev-offload-dpdk.c
Update regex group syntax in checkpatch utility
  • Change matched.group(1) to matched[1] in check_spelling function
utilities/checkpatch.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Updates include: adding an author entry; fixing memory leaks and correcting offload data lookup in DPDK offload flow handling; and a minor regex group access change in a Python check script. No public APIs changed.

Changes

Cohort / File(s) Summary
Documentation
AUTHORS.rst
Added author entry: Linda Wang linda.wang@jaguarmicro.com.
DPDK offload flow handling
lib/netdev-offload-dpdk.c
Free IPv4/IPv6 frag spec/mask on unknown fragmentation error in parse_flow_match; in netdev_offload_dpdk_flow_destroy, read offload data from physdev->hw_info.offload_data instead of netdev->hw_info.offload_data.
Utilities: check script
utilities/checkpatch.py
In check_spelling for PY_COMMENT, switched regex capture access from matched.group(1) to matched[1].

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant FlowMgr as Flow Manager
  participant PhysDev as physdev
  Note over FlowMgr,PhysDev: netdev_offload_dpdk_flow_destroy()

  Caller->>FlowMgr: destroy(flow)
  FlowMgr->>PhysDev: access hw_info.offload_data
  Note right of PhysDev: Use physdev->hw_info.offload_data<br/>(not netdev->hw_info.offload_data)
  FlowMgr->>FlowMgr: decrement counters, log
  FlowMgr-->>Caller: return
Loading
sequenceDiagram
  autonumber
  participant Parser as parse_flow_match
  participant Alloc as spec/mask alloc
  Note over Parser: Fragmentation parsing (IPv4/IPv6)

  Parser->>Alloc: allocate spec/mask (frag_spec/frag_mask)
  Parser->>Parser: detect unknown fragmentation
  alt Error: unknown fragmentation
    Parser->>Alloc: free allocated spec/mask
    Parser-->>Parser: return -1
  else Known/handled
    Parser-->>Parser: continue
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble bytes and hop through C,
Two leaks plugged—now memory’s free.
A pointer path set right at last,
Python regex, swift and fast.
New name inked in AUTHORS’ glade—
I thump approval: shipped and made! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch series_471914

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `utilities/checkpatch.py:407` </location>
<code_context>
         words = ""
         matched = re.search(r'#([^!].*)$', line)
         if matched:
-            words = matched.group(1)
+            words = matched[1]
         else:
             words = line.replace("'''", '').replace('"""', '').strip()
</code_context>

<issue_to_address>
Using 'matched[1]' instead of 'matched.group(1)' may cause issues if 'matched' is not a Match object.

'matched[1]' will raise a TypeError if 'matched' is a re.Match object. Use 'matched.group(1)' unless you are certain 'matched' is a tuple or similar.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

words = ""
matched = re.search(r'#([^!].*)$', line)
if matched:
words = matched.group(1)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Using 'matched[1]' instead of 'matched.group(1)' may cause issues if 'matched' is not a Match object.

'matched[1]' will raise a TypeError if 'matched' is a re.Match object. Use 'matched.group(1)' unless you are certain 'matched' is a tuple or similar.

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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e0ee785 and b8302d4.

📒 Files selected for processing (3)
  • AUTHORS.rst (1 hunks)
  • lib/netdev-offload-dpdk.c (3 hunks)
  • utilities/checkpatch.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
  • GitHub Check: linux clang address,undefined check-kernel -100
  • GitHub Check: linux clang dpdk-shared --enable-shared
  • GitHub Check: linux gcc dpdk --enable-shared
  • GitHub Check: linux clang check check-dpdk dpdk
  • GitHub Check: linux clang test --enable-shared
  • GitHub Check: linux gcc test --enable-shared
  • GitHub Check: linux gcc --disable-ssl
  • GitHub Check: linux clang test -ljemalloc
  • GitHub Check: linux clang c99
  • GitHub Check: linux gcc --enable-afxdp
  • GitHub Check: linux clang --disable-ssl
  • GitHub Check: linux gcc test -ljemalloc
  • GitHub Check: linux gcc test
  • GitHub Check: linux clang address,undefined test
  • GitHub Check: clang-analyze-cache
  • GitHub Check: freebsd_build COMPILER:gcc freebsd_instance:family/freebsd-14-3-snap
  • GitHub Check: freebsd_build COMPILER:clang freebsd_instance:family/freebsd-13-5-snap
  • GitHub Check: linux deb no dpdk
  • GitHub Check: osx clang --disable-ssl
  • GitHub Check: linux rpm fedora
  • GitHub Check: build oss-fuzz fuzzers
🔇 Additional comments (3)
AUTHORS.rst (1)

298-299: Add Linda Wang to AUTHORS – LGTM

Alphabetical placement under “Linda Sun” looks correct. No further action.

lib/netdev-offload-dpdk.c (2)

1527-1532: Good fix: free IPv4 spec/mask on unknown frag path

Prevents leaks when returning early before the pattern is added. No further issues spotted here.


1612-1617: Free IPv6 frag_spec/frag_mask on unknown frag – check ownership of base spec/mask

This correctly frees the frag ext allocations. Confirm that the base IPv6 spec/mask were already added to patterns before this branch (they are), so they’ll be freed by free_flow_patterns() on error. Avoid freeing them here to prevent double-free.

Comment on lines 2381 to 2384
data = (struct netdev_offload_dpdk_data *)
ovsrcu_get(void *, &netdev->hw_info.offload_data);
ovsrcu_get(void *, &physdev->hw_info.offload_data);
data->rte_flow_counters[tid]--;

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use physdev offload_data (correct) and guard against NULL to avoid crash

Switching to physdev->hw_info.offload_data matches where counters are maintained. Add a NULL check to avoid a rare NPE during teardown races.

-        data = (struct netdev_offload_dpdk_data *)
-            ovsrcu_get(void *, &physdev->hw_info.offload_data);
-        data->rte_flow_counters[tid]--;
+        data = (struct netdev_offload_dpdk_data *)
+            ovsrcu_get(void *, &physdev->hw_info.offload_data);
+        if (data) {
+            data->rte_flow_counters[tid]--;
+        } else {
+            VLOG_DBG_RL(&rl, "%s: offload_data missing on physdev while destroying flow 0x%"PRIxPTR,
+                        netdev_get_name(physdev), (intptr_t) rte_flow);
+        }
📝 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
data = (struct netdev_offload_dpdk_data *)
ovsrcu_get(void *, &netdev->hw_info.offload_data);
ovsrcu_get(void *, &physdev->hw_info.offload_data);
data->rte_flow_counters[tid]--;
data = (struct netdev_offload_dpdk_data *)
ovsrcu_get(void *, &physdev->hw_info.offload_data);
if (data) {
data->rte_flow_counters[tid]--;
} else {
VLOG_DBG_RL(&rl, "%s: offload_data missing on physdev while destroying flow 0x%"PRIxPTR,
netdev_get_name(physdev), (intptr_t) rte_flow);
}
🤖 Prompt for AI Agents
In lib/netdev-offload-dpdk.c around lines 2381-2384, the code reads
physdev->hw_info.offload_data via ovsrcu_get and then unconditionally
dereferences it to decrement a counter; add a NULL guard to avoid a potential
NULL-pointer crash during teardown races. Change the sequence to retrieve the
offload_data into a local pointer, check if that pointer is non-NULL, and only
then decrement data->rte_flow_counters[tid] (otherwise skip the decrement).

Comment on lines 405 to 409
matched = re.search(r'#([^!].*)$', line)
if matched:
words = matched.group(1)
words = matched[1]
else:
words = line.replace("'''", '').replace('"""', '').strip()
Copy link

@coderabbitai coderabbitai bot Sep 3, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use Match.group(1) instead of subscription for portability

matched[1] isn’t supported on older Python versions commonly used with OVS; the rest of this file already uses .group(n). This change can raise “'re.Match' object is not subscriptable”.

Apply:

-        if matched:
-            words = matched[1]
+        if matched:
+            words = matched.group(1)
📝 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
matched = re.search(r'#([^!].*)$', line)
if matched:
words = matched.group(1)
words = matched[1]
else:
words = line.replace("'''", '').replace('"""', '').strip()
matched = re.search(r'#([^!].*)$', line)
if matched:
words = matched.group(1)
else:
words = line.replace("'''", '').replace('"""', '').strip()
🤖 Prompt for AI Agents
In utilities/checkpatch.py around lines 405 to 409, the code uses matched[1] to
extract the regex capture which fails on older Python versions; replace that
subscription with matched.group(1) to match the rest of the file and avoid
"'re.Match' object is not subscriptable" errors—i.e., when matched is truthy
call matched.group(1) to assign words.

Copy link

Choose a reason for hiding this comment

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

Since which python version is it supported?

Copy link

Choose a reason for hiding this comment

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

.

So the subscriptable Match object syntax (matched[1]) is supported starting from Python 3.6, but for maximum compatibility with older Python versions commonly used in systems like OVS, using matched.group(1) is the safer approach.

ovsrobot pushed a commit that referenced this pull request Sep 19, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
ovsrobot pushed a commit that referenced this pull request Oct 9, 2025
When vport_add_channel() is called duplicate, the resources for previously
specified sock was not freed. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    #0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    #1 0x922630 in xmalloc__ lib/util.c:141
    #2 0x922718 in xmalloc lib/util.c:176
    #3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    #4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    #5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    #6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    #7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    #8 0x616354 in dpif_port_add lib/dpif.c:602
    #9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    #10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    #11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    #12 0x416dbc in iface_create vswitchd/bridge.c:2246
    #13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    #14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    #15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    #16 0x420884 in bridge_run vswitchd/bridge.c:3440
    #17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Reproduce steps:
    ovs-vsctl add-br br-ovs
    ovs-vsctl add-port br-ovs test -- set interface test type=internal
    ip netns add ns_test
    ip link set test netns ns_test
    ip netns del ns_test
    ifconfig br-ovs up
    sleep 1
    ifconfig br-ovs down
    sleep 1
    ovs-vsctl del-br br-ovs

Fixes: 69c5158 ("dpif-netlink: don't allocate per thread netlink sockets")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
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.

5 participants