From patchwork Sat Apr 6 08:18:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sidong Yang X-Patchwork-Id: 10888879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 306421708 for ; Mon, 8 Apr 2019 07:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1198626E69 for ; Mon, 8 Apr 2019 07:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 062D127FA9; Mon, 8 Apr 2019 07:23:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C33B526E69 for ; Mon, 8 Apr 2019 07:23:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7472F89322; Mon, 8 Apr 2019 07:23:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id 11FED89CDB for ; Sat, 6 Apr 2019 08:19:04 +0000 (UTC) Received: by mail-pf1-x443.google.com with SMTP id 10so4582555pfo.5 for ; Sat, 06 Apr 2019 01:19:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7S+/otONJq7A1+oidV272OlqVLwinjq666S1Pp9w7yk=; b=o9ZY1GxbELwMLxPKqx4n3dNBzEPOECTtv+bd2Li4KCOSKleo6BW8FTgDO/CZskIbSv orclAGT/sDtgXNzQBP+tB5Y3whyrmKwDJk/pWJ7+P+gdI/qmgBOS8DSPjF/7PVdn+6B3 DYRgE1s4oUtEe35H0sJ5CgKtZoP8seklf70o0Hq4GaQbsQ4q8gvim+vBwIfialZdKG4Y OJlfufytVP7VWSk2yNUom40EMcdzWaZciVxsHww86oXH/0HdyXVZ80z7vVGhpBOQiTeF ex8YsLIct/DVE0fW7Xcf8INH40r5L+0y+8++oy0YLUsAdtH0IvX40oPcT8xPbOWvc8b/ 5QRw== X-Gm-Message-State: APjAAAXgX97Zcxjm5SHxrc5S/+ssB2UURv+Y2uI0Ykm7y545Drya2O7o 6OO6D5CzbIVTdwJHcUmeq28= X-Google-Smtp-Source: APXvYqwsxhy+Wk/hmYBSfSP5bpAzWRjeU28BIu70K15iarj0EOrUh1kb+fIHZ1vKe3wg5HJu5r5g/Q== X-Received: by 2002:a63:d304:: with SMTP id b4mr16710145pgg.300.1554538743269; Sat, 06 Apr 2019 01:19:03 -0700 (PDT) Received: from localhost.localdomain ([61.83.141.141]) by smtp.gmail.com with ESMTPSA id v43sm1694652pgn.57.2019.04.06.01.18.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Apr 2019 01:19:02 -0700 (PDT) From: Sidong Yang To: Hans de Goede Subject: [PATCH] drm/vboxvideo: Avoid double check buffer_overflow in vbva_write() Date: Sat, 6 Apr 2019 08:18:50 +0000 Message-Id: <20190406081850.1906-1-realwakka@gmail.com> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Mon, 08 Apr 2019 07:23:35 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7S+/otONJq7A1+oidV272OlqVLwinjq666S1Pp9w7yk=; b=edPI+Y5BRmiu56Ok5EQdQKQcP2P9Fft5RRaHds0yJym7y1CZNILfieCbgI5eyRCKIX OMEUGvsLMQ/X+4rzKNmdXc2j5qG9+goYWJBihiUEnJw0c7xnz/1o9voitkAzSQVY092Z DrcFMp8T8YLt9WGMO+riMo3zSCR1LxM07jQfa47VUGAuy7I3peWT6EiBP+wSUGAFxNYQ hPdMOz3/q970CinePpHjMtblt47HstWwx2aTkhUJrG8zXqLbI11GkseYjJn4JB8o/wbC x5KEQWNMUKDrqkGnlttZqgb3hWbCdzIqflHG+uzUXykqjlIZlXqDNGd3WAg832mg4HPu 5v/A== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Sidong Yang , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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,