zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.48k stars 6.41k forks source link

[Coverity CID: 353647] Operands don't affect result in drivers/mfd/mfd_axp192.c #74751

Open zephyrbot opened 2 months ago

zephyrbot commented 2 months ago

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/dcf42917c550714d2457947538b9e29d083e872e/drivers/mfd/mfd_axp192.c#L555

Category: Integer handling issues Function: mfd_axp192_gpio_read_port Component: Drivers CID: 353647

Details:

https://github.com/zephyrproject-rtos/zephyr/blob/dcf42917c550714d2457947538b9e29d083e872e/drivers/mfd/mfd_axp192.c#L555

549      gpio_input_val |=
550              (((gpio34_val & AXP192_GPIO34_INTPUT_MASK) >> AXP192_GPIO34_INTPUT_SHIFT) << 3u);
551    
552      gpio_output_val = (gpio012_val & AXP192_GPIO012_OUTPUT_MASK);
553      gpio_output_val |= ((gpio34_val & AXP192_GPIO34_OUTPUT_MASK) << 3u);
554      gpio_output_val |=
>>>     CID 353647:  Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "(gpio5_val & 4U) >> 3U" is 0 regardless of the values of its operands. This occurs as a value.
555              (((gpio5_val & AXP192_GPIO5_OUTPUT_MASK) >> AXP192_GPIO5_OUTPUT_SHIFT) << 5u);
556    
557      *value = gpio_input_val & ~(data->gpio_mask_output);
558      *value |= (gpio_output_val & data->gpio_mask_output);
559    
560      return 0;

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

Please fix or provide comments in coverity using the link:

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

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.


Driver introduced in 09da4cf89df5b4be1caf6505c78aa543b0bed8ee offending line in 2a83c5802364

aescolar commented 2 months ago

CC @MrMarteng @gmarull @aasinclair

MrMarteng commented 1 month ago

@aescolar Thanks. I am on it. I identified, that there was a general mixup with GPIO5.