File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -403,9 +403,17 @@ static int max1125x_read_sample(const struct device *dev)
403403 * the available input range is limited to the minimum or maximum
404404 * data value.
405405 */
406+
407+ if (config -> resolution > 24 || config -> resolution < 1 ) {
408+ LOG_ERR ("Unsupported ADC resolution: %u" , config -> resolution );
409+ return - EINVAL ;
410+ }
411+
406412 is_positive = buffer_rx [(config -> resolution / 8 )] >> 7 ;
413+
407414 if (is_positive ) {
408- * data -> buffer ++ = sys_get_be24 (buffer_rx ) - (1 << (config -> resolution - 1 ));
415+ /* Ensure left shift is done using unsigned literal to avoid overflow. */
416+ * data -> buffer ++ = sys_get_be24 (buffer_rx ) - (1U << (config -> resolution - 1 ));
409417 } else {
410418 * data -> buffer ++ = sys_get_be24 (buffer_rx + 1 );
411419 }
You can’t perform that action at this time.
0 commit comments