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

driver: sensor: adxl372: Bug fix for status2 reg #79105

Conversation

vladislav-pejic
Copy link
Contributor

This is a bug fix for adxl372_get_status function. This function is used to get STATUS1, STATUS2, FIFO_ENTRIES2 and FIFO_ENTRIES1 registers (they are continuously present in the memory in this order). User can choose if it wants STATUS2 and/or FIFO registers by passing pointers where to store received values. Bug was when user doesn't want STATUS2 and want FIFO regs. In that case calculated length would be 3 which will result in reading of STATUS1, STATUS2 and FIFO_ENTRIES2 regs and not expected STATUS1, FIFO_ENTRIES2 and FIFO_ENTRIES1.

Signed-off-by: Vladislav Pejic [email protected]

MaureenHelm
MaureenHelm previously approved these changes Sep 27, 2024
This is a bug fix for adxl372_get_status function.
This function is used to get STATUS1, STATUS2, FIFO_ENTRIES2
and FIFO_ENTRIES1 registers (they are continuously present
in the memory in this order). User can choose if it wants
STATUS2 and/or FIFO registers by passing pointers where
to store received values. Bug was when user doesn't want
STATUS2 and want FIFO regs. In that case calculated length
would be 3 which will result in reading of STATUS1, STATUS2
and FIFO_ENTRIES2 regs and not expected STATUS1, FIFO_ENTRIES2
and FIFO_ENTRIES1.

Signed-off-by: Vladislav Pejic <[email protected]>
Comment on lines -367 to +376
length += 2U;
if (status2) {
length += 2U;
} else {
/* Registers STATUS1, STATUS2, FIFO_ENTRIES2 and FIFO_ENTRIES1
* are one after the other. If user wants fifo_entries and
* not status2, to get the correct values, STATUS2 register
* also must be read but read value will be ignored.
*/
length += 3U;
}
Copy link
Member

@ubieda ubieda Sep 27, 2024

Choose a reason for hiding this comment

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

I'm not sure I understand the rationale for having a variable-length transfer here (I know it was in-tree in the first place; I'm suggesting to simplify it since it had a bug).

Wouldn't it be just easier to always pull the 4-bytes and depending on whether the pointer is valid: pass that config over?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My rationale was that I wanted to reduce SPI overhead and not read registers that are not necessary (FIFO ENTRIES1/2).

Copy link
Member

Choose a reason for hiding this comment

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

Ok - I personally find it harder to maintain this way vs the overhead of 1 or 2 extra bytes. It's a subjective thought though. Approving.

Comment on lines -367 to +376
length += 2U;
if (status2) {
length += 2U;
} else {
/* Registers STATUS1, STATUS2, FIFO_ENTRIES2 and FIFO_ENTRIES1
* are one after the other. If user wants fifo_entries and
* not status2, to get the correct values, STATUS2 register
* also must be read but read value will be ignored.
*/
length += 3U;
}
Copy link
Member

Choose a reason for hiding this comment

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

Ok - I personally find it harder to maintain this way vs the overhead of 1 or 2 extra bytes. It's a subjective thought though. Approving.

@aescolar aescolar merged commit fe5bfc9 into zephyrproject-rtos:main Oct 2, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Sensors Sensors platform: ADI Analog Devices, Inc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants