Skip to content

Conversation

@jayvikdesai
Copy link

Add input validation to single-pin GPIO APIs (e.g., gpio_pin_configure) and emulator-specific helpers to return -EINVAL for invalid pins. This ensures tests correctly fail when targeting non-existent pins.

For standard port-wide APIs (e.g., gpio_port_set_bits_raw), align behavior with hardware drivers by masking out invalid pins instead of returning an error. This mimics hardware behavior where writing to unimplemented bits is ignored, and ensures compatibility with generic tests that use full 32-bit masks (e.g., 0xFFFFFFFF).

Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think this is easier to read and it matches the other checks done in this file.

Suggested change
if ((config->common.port_pin_mask & mask) == 0) {

Copy link
Author

@jayvikdesai jayvikdesai Dec 23, 2025

Choose a reason for hiding this comment

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

Acknowledged

@jayvikdesai jayvikdesai force-pushed the validate_gpioemul_input_pin branch from d9cd735 to efcd029 Compare December 23, 2025 17:50
…t APIs

Add input validation to single-pin GPIO APIs (e.g., gpio_pin_configure)
and emulator-specific helpers to return -EINVAL for invalid pins. This
ensures tests correctly fail when targeting non-existent pins.

For standard port-wide APIs (e.g., gpio_port_set_bits_raw), align behavior
with hardware drivers by masking out invalid pins instead of returning an
error. This mimics hardware behavior where writing to unimplemented bits
is ignored, and ensures compatibility with generic tests that use full
32-bit masks (e.g., 0xFFFFFFFF).

Signed-off-by: jayvikdesai <[email protected]>
@jayvikdesai jayvikdesai force-pushed the validate_gpioemul_input_pin branch from efcd029 to ff49cf7 Compare December 23, 2025 17:52
@sonarqubecloud
Copy link

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.

3 participants