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

[Coverity CID: 353654] Unintended sign extension in drivers/sensor/ams/tsl2591/tsl2591.c #74752

Closed
zephyrbot opened this issue Jun 22, 2024 · 1 comment · Fixed by #76669
Closed
Assignees
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: medium Medium impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/dcf42917c550714d2457947538b9e29d083e872e/drivers/sensor/ams/tsl2591/tsl2591.c#L139

Category: Integer handling issues
Function: tsl2591_channel_get
Component: Drivers
CID: 353654

Details:

int64_t cpl = data->atime * data->again;

133     }
134    
135     static int tsl2591_channel_get(const struct device *dev, enum sensor_channel chan,
136                             struct sensor_value *val)
137     {
138      const struct tsl2591_data *data = dev->data;
>>>     CID 353654:  Integer handling issues  (SIGN_EXTENSION)
>>>     Suspicious implicit sign extension: "data->again" with type "uint16_t" (16 bits, unsigned) is promoted in "data->atime * data->again" to type "int" (32 bits, signed), then sign-extended to type "long long" (64 bits, signed).  If "data->atime * data->again" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.
139      int64_t cpl = data->atime * data->again;
140      int64_t strength;
141    
142      /* Unfortunately, datasheet does not provide a lux conversion formula for this particular
143       * device. There is still ongoing discussion about the proper formula, though this
144       * implementation uses a slightly modified version of the Adafruit library formula:

For more information about the violation, check the Coverity Reference. (CWE-194)

Please fix or provide comments in coverity using the link:

https://scan9.scan.coverity.com/#/project-view/29271/12996?selectedIssue=353654

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the MAINTAINERS file.

@zephyrbot zephyrbot added area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: medium Medium impact/importance bug labels Jun 22, 2024
@MaureenHelm
Copy link
Member

@kurtjd please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants