From: Hans de Goede <hdegoede@redhat.com>
To: Sidong Yang <realwakka@gmail.com>
Cc: David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/vboxvideo: Avoid double check buffer_overflow in vbva_write()
Date: Sat, 6 Apr 2019 11:47:21 +0200 [thread overview]
Message-ID: <4f5fc992-f220-d7eb-6412-977c49b754ef@redhat.com> (raw)
In-Reply-To: <20190406081850.1906-1-realwakka@gmail.com>
Hi,
On 06-04-19 10:18, Sidong Yang wrote:
> In vbva_write(), We do not need to double check available chunk size if
> chunk is smaller than available buffer. Put the second if clause in the
> first if clause and avoid check twice.
>
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
The code pattern of checking some condition, then fixing it up
and checking again without putting the second check inside the
first check's if block is quite normal and IMHO is more readable
then the nested version with all the extra indentation.
I"m sure the compiler is more then smart enough to just optimize
away the second check if the first one succeeds.
So I see no benefits to this patch, so nack from me.
Regards,
Hans
> ---
> drivers/gpu/drm/vboxvideo/vbva_base.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/vboxvideo/vbva_base.c b/drivers/gpu/drm/vboxvideo/vbva_base.c
> index 36bc9824ec3f..a0c185acf37a 100644
> --- a/drivers/gpu/drm/vboxvideo/vbva_base.c
> +++ b/drivers/gpu/drm/vboxvideo/vbva_base.c
> @@ -80,14 +80,14 @@ bool vbva_write(struct vbva_buf_ctx *vbva_ctx, struct gen_pool *ctx,
> if (chunk >= available) {
> vbva_buffer_flush(ctx);
> available = vbva_buffer_available(vbva);
> - }
> -
> - if (chunk >= available) {
> - if (WARN_ON(available <= vbva->partial_write_tresh)) {
> - vbva_ctx->buffer_overflow = true;
> - return false;
> + if (chunk >= available) {
> + if (WARN_ON(available <= vbva->partial_write_tresh)) {
> + vbva_ctx->buffer_overflow = true;
> + return false;
> + }
> + chunk = available - vbva->partial_write_tresh;
> }
> - chunk = available - vbva->partial_write_tresh;
> +
> }
>
> vbva_buffer_place_data_at(vbva_ctx, p, chunk,
>
prev parent reply other threads:[~2019-04-06 9:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-06 8:18 Sidong Yang
2019-04-06 9:47 ` Hans de Goede [this message]
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=4f5fc992-f220-d7eb-6412-977c49b754ef@redhat.com \
--to=hdegoede@redhat.com \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=realwakka@gmail.com \
/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
all inboxes | Powered by JetHome®