Skip to content
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

bhyve/audio.c: avoid re-calculating the length of dev_name #945

Closed
wants to merge 3 commits into from

Conversation

rilysh
Copy link
Contributor

@rilysh rilysh commented Dec 19, 2023

In the function audio_init(), strlen() is being called two times, first to get the length of dev_name and second to use in memcpy(). Creating a local variable and keeping the length avoids this re-calculation.

Source: usr.sbin/bhyve/audio.c

In the function audio_init(), strlen() is being called two times,
first to get the length of dev_name and second to use in memcpy().
Creating a local variable and keeping the length avoids this
re-calculation.

Signed-off-by: rilysh <nightquick@proton.me>
@rilysh rilysh requested a review from bsdjhb as a code owner December 19, 2023 10:00
Copy link
Contributor

@gmshake gmshake left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -80,15 +80,17 @@ audio_init(const char *dev_name, uint8_t dir)
#endif
};
#endif
size_t sz;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer nlen to sz.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I've updated the name.

Copy link
Member

@bsdimp bsdimp left a comment

Choose a reason for hiding this comment

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

This is ready to land.

freebsd-git pushed a commit that referenced this pull request Dec 26, 2023
In the function audio_init(), strlen() is being called two times,
first to get the length of dev_name and second to use in memcpy().
Creating a local variable and keeping the length avoids this
re-calculation.

Signed-off-by: rilysh <nightquick@proton.me>
Reviewed by: imp, zlei
Pull Request: #945
@bsdimp
Copy link
Member

bsdimp commented Dec 26, 2023

This has landed. Thank you for your contribution.

@bsdimp bsdimp closed this Dec 26, 2023
@bsdimp bsdimp added the merged label Dec 26, 2023
bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this pull request Mar 13, 2024
In the function audio_init(), strlen() is being called two times,
first to get the length of dev_name and second to use in memcpy().
Creating a local variable and keeping the length avoids this
re-calculation.

Signed-off-by: rilysh <nightquick@proton.me>
Reviewed by: imp, zlei
Pull Request: freebsd/freebsd-src#945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants