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

prov/efa: remove unneeded memset #9655

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

a-szegel
Copy link
Contributor

@a-szegel a-szegel commented Dec 19, 2023

The memset assigns the same length as the variable we are setting.... no chance anything bad will happen.

@a-szegel a-szegel requested a review from a team December 19, 2023 18:11
We have some memset before assignments that do nothing, remove them to
save instructions.

Signed-off-by: Seth Zegelstein <szegel@amazon.com>
@a-szegel a-szegel force-pushed the remove-unneeded-memset branch from 3d0eec5 to b1f41e7 Compare December 19, 2023 18:12
Copy link
Contributor

@wzamazon wzamazon left a comment

Choose a reason for hiding this comment

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

The reason memset can be removed is because there is no gap in struct efa_prv_reverse_av_key

@shijin-aws
Copy link
Contributor

The reason memset can be removed is because there is no gap in struct efa_prv_reverse_av_key

@wzamazon what gap do you mean?

Copy link
Contributor

@shijin-aws shijin-aws left a comment

Choose a reason for hiding this comment

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

Will it be safer to struct efa_cur_reverse_av_key cur_key = {0}; at the beginning?

Ignore this, it doesn't matter since it only has ahn and qpn and we already assign them explicitly

@wzamazon
Copy link
Contributor

I meant the struct struct efa_cur_reverse_av_key consist of two int16_t so there is no gap in the struct. If it has one int32, and one int16 then there will be a gap. because compiler will do padding.

struct efa_cur_reverse_av_key {

@shijin-aws
Copy link
Contributor

I thought the memset isn't needed because efa_cur_reverse_av_key only has ahn and qpn and we already assign them explicitly

@darrylabbate
Copy link
Member

The padding would only be relevant if the object is ever cast or punned to some other struct. Otherwise, you don't (and should rarely) need to be acutely aware of the member padding/alignment.

It should be noted that compilers are pretty good at detecting superfluous memset(&foo, 0, ...), so I wouldn't be surprised if this were optimized out anyway.

@shijin-aws shijin-aws merged commit dcb2150 into ofiwg:main Dec 19, 2023
11 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