drm/mipi-dsi: Fix theoretical int overflow in mipi_dsi_dcs_write_seq()

[ Upstream commit 0b03829fde ]

The mipi_dsi_dcs_write_seq() macro makes a call to
mipi_dsi_dcs_write_buffer() which returns a type ssize_t. The macro
then stores it in an int and checks to see if it's negative. This
could theoretically be a problem if "ssize_t" is larger than "int".

To see the issue, imagine that "ssize_t" is 32-bits and "int" is
16-bits, you could see a problem if there was some code out there that
looked like:

  mipi_dsi_dcs_write_seq(dsi, cmd, <32767 bytes as arguments>);

...since we'd get back that 32768 bytes were transferred and 32768
stored in a 16-bit int would look negative.

Though there are no callsites where we'd actually hit this (even if
"int" was only 16-bit), it's cleaner to make the types match so let's
fix it.

Fixes: 2a9e9daf75 ("drm/mipi-dsi: Introduce mipi_dsi_dcs_write_seq macro")
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20240514102056.v5.1.I30fa4c8348ea316c886ef8a522a52fed617f930d@changeid
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240514102056.v5.1.I30fa4c8348ea316c886ef8a522a52fed617f930d@changeid
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Douglas Anderson 2024-05-14 10:20:51 -07:00 committed by Greg Kroah-Hartman
parent cd1885ae4c
commit 4e9d95a132

View File

@ -328,11 +328,11 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
do { \ do { \
static const u8 d[] = { cmd, seq }; \ static const u8 d[] = { cmd, seq }; \
struct device *dev = &dsi->dev; \ struct device *dev = &dsi->dev; \
int ret; \ ssize_t ret; \
ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \ ret = mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
if (ret < 0) { \ if (ret < 0) { \
dev_err_ratelimited( \ dev_err_ratelimited( \
dev, "sending command %#02x failed: %d\n", \ dev, "sending command %#02x failed: %zd\n", \
cmd, ret); \ cmd, ret); \
return ret; \ return ret; \
} \ } \