From: Sean Paul <sean@poorly.run>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Sean Paul <sean@poorly.run>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v1] drm/mipi_dbi: Use simple right shift instead of double negation
Date: Thu, 17 Oct 2019 09:10:52 -0400 [thread overview]
Message-ID: <20191017131052.GA85762@art_vandelay> (raw)
In-Reply-To: <20191017114912.61522-1-andriy.shevchenko@linux.intel.com>
On Thu, Oct 17, 2019 at 02:49:12PM +0300, Andy Shevchenko wrote:
> GCC complains about dubious bitwise OR operand:
>
> drivers/gpu/drm/drm_mipi_dbi.c:1024:49: warning: dubious: x | !y
> CC [M] drivers/gpu/drm/drm_mipi_dbi.o
>
> As long as buffer is consist of byte (u8) values, we may use
> simple right shift and satisfy compiler. It also reduces amount of
> operations needed.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
> index 1961f713aaab..445e88b1fc9a 100644
> --- a/drivers/gpu/drm/drm_mipi_dbi.c
> +++ b/drivers/gpu/drm/drm_mipi_dbi.c
> @@ -1021,7 +1021,7 @@ static int mipi_dbi_typec3_command_read(struct mipi_dbi *dbi, u8 *cmd,
> unsigned int i;
>
> for (i = 0; i < len; i++)
> - data[i] = (buf[i] << 1) | !!(buf[i + 1] & BIT(7));
> + data[i] = (buf[i] << 1) | (buf[i + 1] >> 7);
You should probably have ((buf[i + 1] >> 7) & 0x1) to be super safe.
Do you know anything about this code? It seems like nothing is protecting us
from overrunning buf in this loop. We're just assuming that len < tr[1].len
through this loop and I'm not sure what's protecting us from looking where we
shouldn't.
Sean
> }
>
> MIPI_DBI_DEBUG_COMMAND(*cmd, data, len);
> --
> 2.23.0
>
--
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next parent reply other threads:[~2019-10-17 13:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191017114912.61522-1-andriy.shevchenko@linux.intel.com>
2019-10-17 13:10 ` Sean Paul [this message]
[not found] ` <20191017140054.GN32742@smile.fi.intel.com>
2019-10-17 14:24 ` [PATCH v1] drm/mipi_dbi: Use simple right shift instead of double negation Sean Paul
2019-10-17 16:27 ` Noralf Trønnes
2019-10-22 13:37 ` Noralf Trønnes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191017131052.GA85762@art_vandelay \
--to=sean@poorly.run \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).