Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1570082 > unrolled thread

Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer is aligned

Started bySean Paul <seanpaul@chromium.org>
First post2017-01-30 21:10 +0100
Last post2017-01-31 16:10 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer  is aligned Sean Paul <seanpaul@chromium.org> - 2017-01-30 21:10 +0100
    Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer  is aligned John Keeping <john@metanate.com> - 2017-01-31 13:00 +0100
      Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer  is aligned Sean Paul <seanpaul@chromium.org> - 2017-01-31 16:10 +0100

#1570082 — Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer is aligned

FromSean Paul <seanpaul@chromium.org>
Date2017-01-30 21:10 +0100
SubjectRe: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer is aligned
Message-ID<t5qqZ-8nj-1@gated-at.bofh.it>
On Sun, Jan 29, 2017 at 01:24:30PM +0000, John Keeping wrote:
> By dereferencing the MIPI command buffer as a u32* we rely on it being
> correctly aligned on ARM, but this may not be the case.  Copy it into a
> stack variable that will be correctly aligned.
> 
> Signed-off-by: John Keeping <john@metanate.com>
> Reviewed-by: Chris Zhong <zyw@rock-chips.com>
> ---
> v3:
> - Add Chris' Reviewed-by
> Unchanged in v2
> 
>  drivers/gpu/drm/rockchip/dw-mipi-dsi.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> index 03fc096fe1bd..ddbc037e7ced 100644
> --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> @@ -607,10 +607,10 @@ static int dw_mipi_dsi_dcs_short_write(struct dw_mipi_dsi *dsi,
>  static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
>  				      const struct mipi_dsi_msg *msg)
>  {
> -	const u32 *tx_buf = msg->tx_buf;
> -	int len = msg->tx_len, pld_data_bytes = sizeof(*tx_buf), ret;
> +	const u8 *tx_buf = msg->tx_buf;
> +	int len = msg->tx_len, pld_data_bytes = sizeof(u32), ret;
>  	u32 hdr_val = GEN_HDATA(msg->tx_len) | GEN_HTYPE(msg->type);
> -	u32 remainder = 0;
> +	u32 remainder;
>  	u32 val;
>  
>  	if (msg->tx_len < 3) {
> @@ -621,12 +621,14 @@ static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
>  
>  	while (DIV_ROUND_UP(len, pld_data_bytes)) {
>  		if (len < pld_data_bytes) {
> +			remainder = 0;
>  			memcpy(&remainder, tx_buf, len);
>  			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
>  			len = 0;
>  		} else {
> -			dsi_write(dsi, DSI_GEN_PLD_DATA, *tx_buf);
> -			tx_buf++;
> +			memcpy(&remainder, tx_buf, pld_data_bytes);
> +			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> +			tx_buf += pld_data_bytes;
>  			len -= pld_data_bytes;
>  		}


You can clean this up further by removing a couple of the locals, the
conditional and the division:

while(len < msg->tx_len) {
        size_t to_write = MIN(msg->tx_len - len, sizeof(remainder));

        memcpy(&remainder, msg->tx_buf + len, to_write);
        dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
        len += to_write;

        ...
}

Sean


>  
> -- 
> 2.11.0.197.gb556de5.dirty
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS

[toc] | [next] | [standalone]


#1570650

FromJohn Keeping <john@metanate.com>
Date2017-01-31 13:00 +0100
Message-ID<t5Fgl-f7-9@gated-at.bofh.it>
In reply to#1570082
On Mon, 30 Jan 2017 15:08:11 -0500, Sean Paul wrote:

> On Sun, Jan 29, 2017 at 01:24:30PM +0000, John Keeping wrote:
> > By dereferencing the MIPI command buffer as a u32* we rely on it being
> > correctly aligned on ARM, but this may not be the case.  Copy it into a
> > stack variable that will be correctly aligned.
> > 
> > Signed-off-by: John Keeping <john@metanate.com>
> > Reviewed-by: Chris Zhong <zyw@rock-chips.com>
> > ---
> > v3:
> > - Add Chris' Reviewed-by
> > Unchanged in v2
> > 
> >  drivers/gpu/drm/rockchip/dw-mipi-dsi.c | 12 +++++++-----
> >  1 file changed, 7 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > index 03fc096fe1bd..ddbc037e7ced 100644
> > --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > @@ -607,10 +607,10 @@ static int dw_mipi_dsi_dcs_short_write(struct dw_mipi_dsi *dsi,
> >  static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
> >  				      const struct mipi_dsi_msg *msg)
> >  {
> > -	const u32 *tx_buf = msg->tx_buf;
> > -	int len = msg->tx_len, pld_data_bytes = sizeof(*tx_buf), ret;
> > +	const u8 *tx_buf = msg->tx_buf;
> > +	int len = msg->tx_len, pld_data_bytes = sizeof(u32), ret;
> >  	u32 hdr_val = GEN_HDATA(msg->tx_len) | GEN_HTYPE(msg->type);
> > -	u32 remainder = 0;
> > +	u32 remainder;
> >  	u32 val;
> >  
> >  	if (msg->tx_len < 3) {
> > @@ -621,12 +621,14 @@ static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
> >  
> >  	while (DIV_ROUND_UP(len, pld_data_bytes)) {
> >  		if (len < pld_data_bytes) {
> > +			remainder = 0;
> >  			memcpy(&remainder, tx_buf, len);
> >  			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> >  			len = 0;
> >  		} else {
> > -			dsi_write(dsi, DSI_GEN_PLD_DATA, *tx_buf);
> > -			tx_buf++;
> > +			memcpy(&remainder, tx_buf, pld_data_bytes);
> > +			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> > +			tx_buf += pld_data_bytes;
> >  			len -= pld_data_bytes;
> >  		}  
> 
> 
> You can clean this up further by removing a couple of the locals, the
> conditional and the division:
> 
> while(len < msg->tx_len) {
>         size_t to_write = MIN(msg->tx_len - len, sizeof(remainder));
> 
>         memcpy(&remainder, msg->tx_buf + len, to_write);
>         dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
>         len += to_write;
> 
>         ...
> }

That's a nice simplification, but it's more than I was trying to do with
this patch.  I can add a cleanup patch on top to simplify the function,
but I don't have that much time to spend on this at the moment and I'd
rather not block this fix because the original code structure could be
improved.

[toc] | [prev] | [next] | [standalone]


#1570814

FromSean Paul <seanpaul@chromium.org>
Date2017-01-31 16:10 +0100
Message-ID<t5Ied-2dH-17@gated-at.bofh.it>
In reply to#1570650
On Tue, Jan 31, 2017 at 11:56:18AM +0000, John Keeping wrote:
> On Mon, 30 Jan 2017 15:08:11 -0500, Sean Paul wrote:
> 
> > On Sun, Jan 29, 2017 at 01:24:30PM +0000, John Keeping wrote:
> > > By dereferencing the MIPI command buffer as a u32* we rely on it being
> > > correctly aligned on ARM, but this may not be the case.  Copy it into a
> > > stack variable that will be correctly aligned.
> > > 
> > > Signed-off-by: John Keeping <john@metanate.com>
> > > Reviewed-by: Chris Zhong <zyw@rock-chips.com>
> > > ---
> > > v3:
> > > - Add Chris' Reviewed-by
> > > Unchanged in v2
> > > 
> > >  drivers/gpu/drm/rockchip/dw-mipi-dsi.c | 12 +++++++-----
> > >  1 file changed, 7 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > > index 03fc096fe1bd..ddbc037e7ced 100644
> > > --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > > +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c
> > > @@ -607,10 +607,10 @@ static int dw_mipi_dsi_dcs_short_write(struct dw_mipi_dsi *dsi,
> > >  static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
> > >  				      const struct mipi_dsi_msg *msg)
> > >  {
> > > -	const u32 *tx_buf = msg->tx_buf;
> > > -	int len = msg->tx_len, pld_data_bytes = sizeof(*tx_buf), ret;
> > > +	const u8 *tx_buf = msg->tx_buf;
> > > +	int len = msg->tx_len, pld_data_bytes = sizeof(u32), ret;
> > >  	u32 hdr_val = GEN_HDATA(msg->tx_len) | GEN_HTYPE(msg->type);
> > > -	u32 remainder = 0;
> > > +	u32 remainder;
> > >  	u32 val;
> > >  
> > >  	if (msg->tx_len < 3) {
> > > @@ -621,12 +621,14 @@ static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi,
> > >  
> > >  	while (DIV_ROUND_UP(len, pld_data_bytes)) {
> > >  		if (len < pld_data_bytes) {
> > > +			remainder = 0;
> > >  			memcpy(&remainder, tx_buf, len);
> > >  			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> > >  			len = 0;
> > >  		} else {
> > > -			dsi_write(dsi, DSI_GEN_PLD_DATA, *tx_buf);
> > > -			tx_buf++;
> > > +			memcpy(&remainder, tx_buf, pld_data_bytes);
> > > +			dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> > > +			tx_buf += pld_data_bytes;
> > >  			len -= pld_data_bytes;
> > >  		}  
> > 
> > 
> > You can clean this up further by removing a couple of the locals, the
> > conditional and the division:
> > 
> > while(len < msg->tx_len) {
> >         size_t to_write = MIN(msg->tx_len - len, sizeof(remainder));
> > 
> >         memcpy(&remainder, msg->tx_buf + len, to_write);
> >         dsi_write(dsi, DSI_GEN_PLD_DATA, remainder);
> >         len += to_write;
> > 
> >         ...
> > }
> 
> That's a nice simplification, but it's more than I was trying to do with
> this patch.  I can add a cleanup patch on top to simplify the function,
> but I don't have that much time to spend on this at the moment and I'd
> rather not block this fix because the original code structure could be
> improved.

Ok. I'm inclined to argue that writing your response probably took more time
than the copy/paste to fix it, but *shrug*.

Sean

> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web