Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: bridge: sii8620: fix possible off-by-one

The next call to sii8620_burst_get_tx_buf will result in off-by-one
When ctx->burst.tx_count + size == ARRAY_SIZE(ctx->burst.tx_buf). The same
thing happens in sii8620_burst_get_rx_buf.

This patch also change tx_count and tx_buf to rx_count and rx_buf in
sii8620_burst_get_rx_buf. It is unreasonable to check tx_buf's size and
use rx_buf.

Fixes: e19e9c692f81 ("drm/bridge/sii8620: add support for burst eMSC transmissions")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Signed-off-by: Robert Foss <robert.foss@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20220518065856.18936-1-hbh25y@gmail.com

authored by

Hangyu Hua and committed by
Robert Foss
21779cc2 f0dce5c4

+2 -2
+2 -2
drivers/gpu/drm/bridge/sil-sii8620.c
··· 605 605 u8 *buf = &ctx->burst.tx_buf[ctx->burst.tx_count]; 606 606 int size = len + 2; 607 607 608 - if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { 608 + if (ctx->burst.tx_count + size >= ARRAY_SIZE(ctx->burst.tx_buf)) { 609 609 dev_err(ctx->dev, "TX-BLK buffer exhausted\n"); 610 610 ctx->error = -EINVAL; 611 611 return NULL; ··· 622 622 u8 *buf = &ctx->burst.rx_buf[ctx->burst.rx_count]; 623 623 int size = len + 1; 624 624 625 - if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { 625 + if (ctx->burst.rx_count + size >= ARRAY_SIZE(ctx->burst.rx_buf)) { 626 626 dev_err(ctx->dev, "RX-BLK buffer exhausted\n"); 627 627 ctx->error = -EINVAL; 628 628 return NULL;