drm/sun4i: Fix dsi dcs long write function
PATCH 1/1 drm/sun4i: Fix dsi dcs long write function
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.
--- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +2 -2
@@ -889,7 +889,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 (msg->tx_len +sizeof (crc) +3 ,GFP_KERNEL );if (!bounce)return -ENOMEM ;
@@ -900,7 +900,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);
Signature · 1 line
2.28.0
Dne petek, 28. avgust 2020 ob 13:24:44 CEST je Ondrej Jirman napisal(a):
Quoted 6 lines
It's writing too much data.
regmap_bulk_writeexpects number of register sized chunks to write, not a byte sized length of the bounce buffer. Bounce buffer needs to be padded too, so thatregmap_bulk_writewill not read past the end of the buffer.Signed-off-by Ondrej Jirman <[email protected]>
support")
should be added. Fix will be then automatically picked into stable releases.
Small nit below.
Quoted 10 lines
--- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.cindex7f13f4d715bf..840fad1b68dd100644
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c static int sun6i_dsi_dcs_write_long(struct sun6i_dsi · line 892
Quoted 5 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +1
-1@@ -889,7 +889,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 (msg->tx_len +sizeof (crc) +3 ,GFP_KERNEL );
It would be nicer to use ALIGN() macro, but I'm fine either way.
Best regards,
Jernej
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c static int sun6i_dsi_dcs_write_long(struct sun6i_dsi · line 903
Quoted 8 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +0
-1if (!bounce)return -ENOMEM ;@@ -900,7 +900,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);
Quoted 4 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +1
-0+ 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);
Quoted 10 lines · Jernej Škrabec
Dne petek, 28. avgust 2020 ob 13:24:44 CEST je Ondrej Jirman napisal(a):
Quoted 6 lines
It's writing too much data.
regmap_bulk_writeexpects number of register sized chunks to write, not a byte sized length of the bounce buffer. Bounce buffer needs to be padded too, so thatregmap_bulk_writewill not read past the end of the buffer.Signed-off-by Ondrej Jirman <[email protected]>Fixes 133add5b5ad4 ("drm/sun4i: Add Allwinner A31 MIPI-DSI controllersupport")
It doesn't really fix anything user visible though, and will not help the stable branch in any way. It just makes the code more correct.
Though now that you came up with the tag, copypasting it is not that much work. ;) So I added it.
Quoted 17 lines
should be added. Fix will be then automatically picked into stable releases.
Small nit below.
Quoted 13 lines
--- drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.cindex7f13f4d715bf..840fad1b68dd100644drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +0
-0@@ -889,7 +889,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));
Quoted 4 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c static int sun6i_dsi_dcs_write_long(struct sun6i_dsi *dsi, · line 892
Quoted 2 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +1
-1- bounce =kzalloc (msg->tx_len +sizeof (crc),GFP_KERNEL ); + bounce =kzalloc (msg->tx_len +sizeof (crc) +3 ,GFP_KERNEL );It would be nicer to use
ALIGN()macro, but I'm fine either way.
Nice idea.
Quoted 1 line
Reviewed-by Jernej Skrabec <[email protected]>
Thanks. :)
regards,
o.
Quoted 20 lines
Best regards,
Jernejdrivers/gpu/drm/sun4i/sun6i_mipi_dsi.c static int sun6i_dsi_dcs_write_long(struct sun6i_dsi · line 903
Quoted 8 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +0
-1if (!bounce)return -ENOMEM ;@@ -900,7 +900,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);
Quoted 4 lines
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +1
-0+ 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);