summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2022-11-18 15:32:08 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-12-31 15:33:10 +0300
commit1665c3aa251f8bf8db1ba52092652ba41b5cba53 (patch)
tree168eb0ce3c2e3da85b8498d35d100b923d3b04e8 /drivers/regulator
parentd04481ee5e15b88e57514fa11eac77f53f7f0a24 (diff)
downloadlinux-1665c3aa251f8bf8db1ba52092652ba41b5cba53.tar.xz
iio: addac: ad74413r: fix integer promotion bug in ad74413_get_input_current_offset()
commit 980389d06d08442fad0139874bff455c76125e47 upstream. The constant AD74413R_ADC_RESULT_MAX is defined via GENMASK, so its type is "unsigned long". Hence in the expression voltage_offset * AD74413R_ADC_RESULT_MAX, voltage_offset is first promoted to unsigned long, and since it may be negative, that results in a garbage value. For example, when range is AD74413R_ADC_RANGE_5V_BI_DIR, voltage_offset is -2500 and voltage_range is 5000, so the RHS of this assignment is, depending on sizeof(long), either 826225UL or 3689348814709142UL, which after truncation to int then results in either 826225 or 1972216214 being the output from in_currentX_offset. Casting to int avoids that promotion and results in the correct -32767 output. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Fixes: fea251b6a5db (iio: addac: add AD74413R driver) Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20221118123209.1658420-1-linux@rasmusvillemoes.dk Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/regulator')
0 files changed, 0 insertions, 0 deletions