Skip to content

Fix SAI_STATUS_IS_* attribute-range helpers for negative status codes#2308

Merged
kcudnik merged 1 commit into
opencomputeproject:masterfrom
MoriLevinzon:fix/attr-status-range-helpers
Jul 7, 2026
Merged

Fix SAI_STATUS_IS_* attribute-range helpers for negative status codes#2308
kcudnik merged 1 commit into
opencomputeproject:masterfrom
MoriLevinzon:fix/attr-status-range-helpers

Conversation

@MoriLevinzon

Copy link
Copy Markdown
Contributor

Fixes #2307

Two fixes in the SAI_STATUS_IS_* helpers in inc/saistatus.h:

  • Compare on the magnitude (SAI_STATUS_CODE(x)) before masking, so the range
    check is correct for negative status codes on Linux. Previously a non-zero
    attribute index borrowed across the 16-bit boundary and matched the wrong
    range (e.g. INVALID_ATTR_VALUE index 3 classified as ATTR_NOT_IMPLEMENTED).
    No-op on Windows, where SAI_STATUS_CODE is identity.
  • Fix SAI_STATUS_IS_UNKNOWN_ATTRIBUTE, which compared against
    SAI_STATUS_INVALID_ATTRIBUTE_0 instead of SAI_STATUS_UNKNOWN_ATTRIBUTE_0
    (wrong on all platforms).

@kcudnik

kcudnik commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Related: #1570 #1235

@kcudnik kcudnik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if you are changing this, add unittests in sanitycheck for corner cases like suggested here: #1235

@MoriLevinzon MoriLevinzon force-pushed the fix/attr-status-range-helpers branch from da06436 to 2bb106f Compare July 2, 2026 15:03
@MoriLevinzon

Copy link
Copy Markdown
Contributor Author

Added check_status_attr_ranges() in meta/saisanitycheck.c (called from main), covering the corner cases from #1235 for all five attribute-error ranges:

Encoding value: SAI_STATUS_0 + SAI_STATUS_CODE(index) == SAI_STATUS_CODE(base + index).
Classification: each indexed code matches its own SAI_STATUS_IS
* helper and no other (this also covers the SAI_STATUS_IS_UNKNOWN_ATTRIBUTE wrong-base fix).
Boundaries: indices 0, 1, _MAX and _MAX-1 (the MAX-2 case from), plus the codes just below _0 and just above _MAX must not match.
Index round-trip: the decoded attribute index equals the input.
Sentinels must not match: SAI_STATUS_SUCCESS, SAI_STATUS_FAILURE, SAI_STATUS_NOT_EXECUTED, 1, -1.

The test passes with the fixed macros and fails against the current ones, so it guards the fix. Verified it compiles under the meta flags (-Wconversion -Werror).

@MoriLevinzon MoriLevinzon force-pushed the fix/attr-status-range-helpers branch from 2bb106f to ad55ee6 Compare July 3, 2026 09:13
@MoriLevinzon MoriLevinzon requested a review from kcudnik July 7, 2026 07:49
@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

update aspell:

WARNING: Word 'xFFFF' is misspelled ./saisanitycheck.c

@MoriLevinzon MoriLevinzon force-pushed the fix/attr-status-range-helpers branch from ad55ee6 to f904222 Compare July 7, 2026 08:44
@MoriLevinzon

Copy link
Copy Markdown
Contributor Author

update aspell:

WARNING: Word 'xFFFF' is misspelled ./saisanitycheck.c

Added xFFFF to meta/aspell.en.pws

@MoriLevinzon MoriLevinzon requested a review from kcudnik July 7, 2026 08:46
@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

we could update aspell to automatically exclude all hexadecimal numbers instead of adding each one somewhere here https://github.com/opencomputeproject/SAI/blob/master/meta/aspellcheck.pl#L190

Signed-off-by: Mori Levinzon <mlevinzon@nvidia.com>
@MoriLevinzon MoriLevinzon force-pushed the fix/attr-status-range-helpers branch from f904222 to 7a9c7c3 Compare July 7, 2026 09:17
@MoriLevinzon

Copy link
Copy Markdown
Contributor Author

we could update aspell to automatically exclude all hexadecimal numbers instead of adding each one somewhere here https://github.com/opencomputeproject/SAI/blob/master/meta/aspellcheck.pl#L190

Updated meta/aspellcheck.pl to skip C-style hexadecimal literals and removed the one-off xFFFF entry from meta/aspell.en.pws, so future hex constants won't need dictionary additions

@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

thanks

@kcudnik

kcudnik commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@MoriLevinzon

Copy link
Copy Markdown
Contributor Author

Thanks @kcudnik! All checks are green and it's approved — please merge when you can

@kcudnik kcudnik merged commit 084e554 into opencomputeproject:master Jul 7, 2026
3 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.

SAI_STATUS_IS_* attribute range helpers: wrong for negative status codes on Linux, and IS_UNKNOWN_ATTRIBUTE checks the wrong base (all platforms)

2 participants