Page MenuHomeFreeBSD

libkern.h: avoid errors with roundup_pow_of_two() in __aligned()
AbandonedPublic

Authored by bz on Sep 26 2024, 11:49 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 25, 12:18 PM
Unknown Object (File)
Thu, Oct 24, 6:02 AM
Unknown Object (File)
Fri, Oct 18, 3:43 PM
Unknown Object (File)
Oct 3 2024, 9:20 AM
Unknown Object (File)
Sep 30 2024, 5:53 PM
Unknown Object (File)
Sep 29 2024, 4:51 AM
Unknown Object (File)
Sep 28 2024, 1:06 PM
Subscribers

Details

Reviewers
dougm
alc
markj
Summary

iwlwifi uses: __aligned(roundup_pow_of_two(sizeof(struct ...)))
which results in 'statement expression not allowed at file scope'
errors.

Make order_base_2() not use a local variable to avoid this problem.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 59609
Build 56496: arc lint + arc unit

Event Timeline

bz requested review of this revision.Sep 26 2024, 11:49 PM

My concern with this is that if the argument n to the macro has side effects, they will be effected twice. I don't find examples of that in the kernel, though I do find somewhere that n is a function call, so that a function would be invoked twice.

Let me suggest an alternative.

#define order_base_2(n) ilog2(2*(n)-1)

I believe that addresses your problem. What it costs is overflow when n has its high order bit set. I don't think that's a significant cost.

My concern with this is that if the argument n to the macro has side effects, they will be effected twice. I don't find examples of that in the kernel, though I do find somewhere that n is a function call, so that a function would be invoked twice.

Let me suggest an alternative.

#define order_base_2(n) ilog2(2*(n)-1)

I believe that addresses your problem. What it costs is overflow when n has its high order bit set. I don't think that's a significant cost.

Seems to work for me. Do you want to commandeer the change for this?

In D46800#1067418, @bz wrote:

My concern with this is that if the argument n to the macro has side effects, they will be effected twice. I don't find examples of that in the kernel, though I do find somewhere that n is a function call, so that a function would be invoked twice.

Let me suggest an alternative.

#define order_base_2(n) ilog2(2*(n)-1)

I believe that addresses your problem. What it costs is overflow when n has its high order bit set. I don't think that's a significant cost.

Seems to work for me. Do you want to commandeer the change for this?

I will post it for review in the next two hours.