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


Groups > linux.kernel > #1570814

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

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!feeders.as203319.net!feeder01.as203319.net!aioe.org!bofh.it!news.nic.it!robomod
From Sean Paul <seanpaul@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH v3 10/24] drm/rockchip: dw-mipi-dsi: don't assume buffer is aligned
Date Tue, 31 Jan 2017 16:10:01 +0100
Message-ID <t5Ied-2dH-17@gated-at.bofh.it> (permalink)
References <t4Yl3-811-7@gated-at.bofh.it> <t4Yl3-811-13@gated-at.bofh.it> <t5qqZ-8nj-1@gated-at.bofh.it> <t5Fgl-f7-9@gated-at.bofh.it>
X-Original-To John Keeping <john@metanate.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=l8dILQyLblbinApGfTyqu2QBC08tawlCPI4bFNNERx0=; b=foQTh+bTipKVq2PKLehqJRLTc1pRB5umVstsPYntlOQ8A3eemSMZX9rnMwBAEr5uqK +fWjZQs20RAHj9rVJof0ycdW2fhhhOqlweRczcJPMjk7Y0IVzg+MJJJBGK39ZVZk3Iqi KOGHjt5VHzHQqBPpJHYL1Nf4GCIYGrNTWkYA0=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=l8dILQyLblbinApGfTyqu2QBC08tawlCPI4bFNNERx0=; b=JDwmwmexTwmuyDaNEUtMIKFogd9YEERFf/74+Qt7AXIquT8i/Xyx3C1hdCmfrQ+ZkD 8irMnnldwbpxF+zB/1/9K2b1CAKG668VoMwCLR8xScopyGUloth3tB/czzo6UKMX/KBD IhDcGFbsXfBMfY6Z1BRJKKypusM75Nn9QX2c2Ah77amfY+GsOc73eor3IOfkq5OzE9Ox iIVwwZHgnVDxySapnf3qOCTvmxKzfNqYS5gej39ClUt50nFHS5DhjdZDRzptk/0yIQ4+ EF0Pvne7NkY7jCYXFPspbIrwmjphKnqN7A/6Wc4o0afyQu9Csw0e/99RUW+rqkDEXdSQ eItw==
X-Gm-Message-State AIkVDXI/pXXHT97AartzpYZ9hEeNlCGqVE9hjBsAx3o4jbKwysPq1TGDx4awJGMumX2+Fm6F
X-Received by 10.200.55.205 with SMTP id e13mr25040794qtc.69.1485874395083; Tue, 31 Jan 2017 06:53:15 -0800 (PST)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.21 (2010-09-15)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 85
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, Chris Zhong <zyw@rock-chips.com>, linux-arm-kernel@lists.infradead.org
X-Original-Date Tue, 31 Jan 2017 09:53:13 -0500
X-Original-Message-ID <20170131145313.GY20076@art_vandelay>
X-Original-References <20170129132444.25251-1-john@metanate.com> <20170129132444.25251-11-john@metanate.com> <20170130200811.GK20076@art_vandelay> <20170131115618.633398fc.john@metanate.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1570814

Show key headers only | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web