Skip to content

Conversation

@opsiff
Copy link
Member

@opsiff opsiff commented Mar 19, 2025

…event received

Delay calling usb_autopm_put_interface until the WMT event response is received to ensure proper synchronization and prevent premature power management actions.

Co-developed-by: Yake Yang [email protected]

Summary by Sourcery

Delays calling usb_autopm_put_interface until the WMT event response is received to ensure proper synchronization and prevent premature power management actions.

…event received

Delay calling usb_autopm_put_interface until the WMT event response is
received to ensure proper synchronization and prevent premature power
management actions.

Co-developed-by: Yake Yang <[email protected]>
Signed-off-by: Yake Yang <[email protected]>
Signed-off-by: Sean Wang <[email protected]>
Signed-off-by: Wentao Guan <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2025

Reviewer's Guide by Sourcery

This pull request delays the call to usb_autopm_put_interface in the btmtk_usb_hci_wmt_sync function until after the WMT event response is received. This ensures proper synchronization and prevents premature power management actions. Error handling is adjusted to ensure usb_autopm_put_interface is always called.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
The call to usb_autopm_put_interface is delayed until after the WMT event response is received.
  • Moved the usb_autopm_put_interface call from before the btmtk_usb_submit_wmt_recv_urb call to after the WMT event processing.
  • Added a new label err_pm_put to jump to the usb_autopm_put_interface call in case of errors.
drivers/bluetooth/btmtk.c

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码重构

    • err_free_wc标签处,usb_autopm_put_interface(data->intf);被重复调用,应该将其移动到err_pm_put标签处,以避免重复操作。
  2. 错误处理

    • err_free_wc标签处,kfree(wc);被调用,但在err_pm_put标签处没有相应的kfree(wc);调用。这可能会导致内存泄漏。应该在err_pm_put标签处添加kfree(wc);
  3. 代码可读性

    • err_free_wcerr_pm_put标签的命名不够明确,建议使用更具描述性的命名,如err_free_resourceserr_power_management_put
  4. 代码风格

    • 代码缩进和格式不一致,建议统一代码风格,以提高可读性。
  5. 错误码处理

    • err变量被赋值为-ETIMEDOUT时,应该检查err变量是否已经被赋值为其他错误码,以避免覆盖之前的错误信息。
  6. 资源管理

    • usb_autopm_put_interface(data->intf);调用后,应该检查返回值以确保资源正确释放。

综合以上意见,修改后的代码可能如下:

static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev,
                                 struct btmtk_wmt_cmd *cmd,
                                 struct btmtk_wmt_evt *evt)
{
    struct btmtk_data *data = hci_get_drvdata(hdev);
    struct btmtk_wmt_cmd_wc *wc;
    struct sk_buff *wmt_skb;
    struct btmtk_hci_wmt_evt *wmt_evt;
    int err;

    wc = kzalloc(sizeof(*wc), GFP_KERNEL);
    if (!wc)
        return -ENOMEM;

    err = btmtk_usb_submit_wmt_send_urb(hdev, cmd, wc);
    if (err < 0) {
        clear_bit(BTMTK_TX_WAIT_VND_EVT, &data->flags);
        goto err_free_wc;
    }

    err = btmtk_usb_submit_wmt_recv_urb(hdev);
    if (err < 0)
        goto err_pm_put;

    /* The vendor specific WMT commands are all answered by a vendor
     * specific event and will have the Command Status or Command
     * Complete event.
     */
    err = wait_event_interruptible(data->wait,
                                   test_bit(BTMTK_RX_WAIT_VND_EVT, &data->flags));
    if (err == -EINTR) {
        bt_dev_err(hdev, "Execution of wmt command interrupted");
        clear_bit(BTMTK_TX_WAIT_VND_EVT, &data->flags);
        goto err_pm_put;
    }

    if (err) {
        bt_dev_err(hdev, "Execution of wmt command timed out");
        clear_bit(BTMTK_TX_WAIT_VND_EVT, &data->flags);
        err = -ETIMEDOUT;
        goto err_pm_put;
    }

    if (data->evt_skb == NULL)
        goto err_pm_put;

    /* Parse and handle the return WMT event */
    wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data;

    /* ... */

err_free_skb:
    kfree_skb(data->evt_skb);
    data->evt_skb = NULL;
err_pm_put:
    usb_autopm_put_interface(data->intf);
err_free_wc:
    kfree(wc);
    return err;
}

请注意,这只是一个示例,具体的修改可能需要根据实际代码逻辑进行调整。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hello666888999
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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 @opsiff - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why usb_autopm_put_interface is called in the new err_pm_put label.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@opsiff opsiff merged commit 8b59768 into deepin-community:linux-6.6.y Mar 21, 2025
5 of 7 checks passed
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.

4 participants