Skip to content

Nuvoton: netsocket correction of judgment errors #12839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 30, 2020
Merged

Nuvoton: netsocket correction of judgment errors #12839

merged 6 commits into from
Apr 30, 2020

Conversation

sword-huang
Copy link
Contributor

@sword-huang sword-huang commented Apr 21, 2020

Description

Fixing reset_phy for Nuvoton - there are two checks that work with invalid values, should check for -1.

Impact of changes

Migration actions required

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers


@ciarmcom ciarmcom requested review from a team April 21, 2020 07:00
@ciarmcom
Copy link
Member

@sword-huang, thank you for your changes.
@ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 requested a review from a team April 21, 2020 07:57
@0xc0170 0xc0170 changed the title Correction of judgment errors. Nuvoton: netsocket correction of judgment errors Apr 21, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 21, 2020

@sword-huang Thanks for the fix. Please describe the fix in few words in description, helps introducing the pull request. I added there a text for now

Although as I don't have the entire context, it would help as well to provide a reason why -1 should be in there instead 0 (I'll read the code above and check return types to find out but should be provided in the commit message itself).

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 21, 2020

Wouldn't this be better than relying on wrapping around ?

    while(delayCnt > 0) {
        delayCnt--;
        if((mdio_read(CONFIG_PHY_ADDR, MII_BMSR) & (BMSR_ANEGCOMPLETE | BMSR_LSTATUS))
                == (BMSR_ANEGCOMPLETE | BMSR_LSTATUS))
            break;
    }

Then the checks for delayCnt == 0 are correct.

@sword-huang
Copy link
Contributor Author

Wouldn't this be better than relying on wrapping around ?

    while(delayCnt > 0) {
        delayCnt--;
        if((mdio_read(CONFIG_PHY_ADDR, MII_BMSR) & (BMSR_ANEGCOMPLETE | BMSR_LSTATUS))
                == (BMSR_ANEGCOMPLETE | BMSR_LSTATUS))
            break;
    }

Then the checks for delayCnt == 0 are correct.

Yes! Your code is more readable. I have recommitted.

@mergify mergify bot added needs: CI and removed needs: review labels Apr 22, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 22, 2020

CI restarted

@mbed-ci
Copy link

mbed-ci commented Apr 22, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 1
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 22, 2020

@ARMmbed/team-nuvoton please review

Copy link
Contributor

@michalpasztamobica michalpasztamobica left a comment

Choose a reason for hiding this comment

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

I guess the main point was for the code to be able to trigger the delayCnt == 0 condition, so this change indeed accomplished its goal. I also understand that this is just a brute-force delay.
However this change actually causes one loop run less: the decrement operator comes first before the comparison, so before the changes the loop ended after 1999 decrements, now it ends after 2000 decrements. It would be good if @ARMmbed/team-nuvoton confirmed that this is also OK. If not - we could do a do-while instead of while-do.
But honestly - I don't think this single loop run makes any difference, so I just approve (ipcore is mentioned as reviewers) ;-)

@@ -78,7 +78,8 @@ static int reset_phy(void)
mdio_write(CONFIG_PHY_ADDR, MII_BMCR, BMCR_RESET);

delayCnt = 2000;
while(delayCnt-- > 0) {
while(delayCnt > 0) {
delayCnt--;
Copy link
Contributor

Choose a reason for hiding this comment

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

please align this (4 spaces to left as other code)

Copy link
Contributor

@cyliangtw cyliangtw left a comment

Choose a reason for hiding this comment

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

This loop is to avoid endless waiting as while PHY broken.
Thanks of your modification.

@mergify mergify bot dismissed 0xc0170’s stale review April 24, 2020 13:15

Pull request has been modified.

0xc0170 added 2 commits April 24, 2020 14:16
Previous commit was incorrect (github does not show tabs..)
Previous commit was wrong (github does not show tabs properly)
0xc0170
0xc0170 previously approved these changes Apr 24, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 24, 2020

I pushed the change via github (there were tabs, was tricky on github), will start CI later today

@mergify mergify bot dismissed 0xc0170’s stale review April 24, 2020 13:20

Pull request has been modified.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 28, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Apr 28, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 2
Build artifacts

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

Successfully merging this pull request may close these issues.

6 participants