| From 851568aab7da5ca340407861c0dcabd3705868ac Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Fri, 28 Aug 2020 14:50:32 +0200 |
| Subject: drm/sun4i: Fix dsi dcs long write function |
| |
| From: Ondrej Jirman <megous@megous.com> |
| |
| [ Upstream commit fd90e3808fd2c207560270c39b86b71af2231aa1 ] |
| |
| It's writing too much data. regmap_bulk_write expects number of |
| register sized chunks to write, not a byte sized length of the |
| bounce buffer. Bounce buffer needs to be padded too, so that |
| regmap_bulk_write will not read past the end of the buffer. |
| |
| Fixes: 133add5b5ad4 ("drm/sun4i: Add Allwinner A31 MIPI-DSI controller support") |
| Signed-off-by: Ondrej Jirman <megous@megous.com> |
| Signed-off-by: Maxime Ripard <maxime@cerno.tech> |
| Reviewed-by: Jernej Skrabec <jernej.skrabec@siol.net> |
| Link: https://patchwork.freedesktop.org/patch/msgid/20200828125032.937148-1-megous@megous.com |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 4 ++-- |
| 1 file changed, 2 insertions(+), 2 deletions(-) |
| |
| diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c |
| index 79eb11cd185d1..9a5584efd5e78 100644 |
| --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c |
| +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c |
| @@ -761,7 +761,7 @@ static int sun6i_dsi_dcs_write_long(struct sun6i_dsi *dsi, |
| regmap_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(0), |
| sun6i_dsi_dcs_build_pkt_hdr(dsi, msg)); |
| |
| - bounce = kzalloc(msg->tx_len + sizeof(crc), GFP_KERNEL); |
| + bounce = kzalloc(ALIGN(msg->tx_len + sizeof(crc), 4), GFP_KERNEL); |
| if (!bounce) |
| return -ENOMEM; |
| |
| @@ -772,7 +772,7 @@ static int sun6i_dsi_dcs_write_long(struct sun6i_dsi *dsi, |
| memcpy((u8 *)bounce + msg->tx_len, &crc, sizeof(crc)); |
| len += sizeof(crc); |
| |
| - regmap_bulk_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(1), bounce, len); |
| + regmap_bulk_write(dsi->regs, SUN6I_DSI_CMD_TX_REG(1), bounce, DIV_ROUND_UP(len, 4)); |
| regmap_write(dsi->regs, SUN6I_DSI_CMD_CTL_REG, len + 4 - 1); |
| kfree(bounce); |
| |
| -- |
| 2.25.1 |
| |