Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1018364yba; Sat, 6 Apr 2019 01:22:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHpwzzzdV8LDzNjwAIt5mPcIAin8hmZFUH4XnRDl9wB0FSmC8G6V7Ghk9GmvMJ5PQoYzxt X-Received: by 2002:aa7:8589:: with SMTP id w9mr17526332pfn.97.1554538929573; Sat, 06 Apr 2019 01:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554538929; cv=none; d=google.com; s=arc-20160816; b=PvyFpui1pH12TilVqLE9903tn3KSFdHPuQRxbf3WiHJwD5l/V1S0gMi388rXgD8ysb H3T9uEEIpLKJQAH+D40toUkUMGtkv9wRfRk874Cyer8M1VwNVJVSzLu+/HRhcnRMapU8 37pxyxD2gMHKy7dh2NsqyoJf2MEjImsBCUZsDDVZMlgkU5grLLSPpRVMmamoRZ+Gz/Vw vlHUZAd7RajIF0GNoaKCPwiWUQY2jp89/KvO1y8jKj3ufnFINDwJnKIDyelrgNQvOOz0 D8ZEmdWRlO/s7EQn3i1/LRSy/J/WQu6P6k42bgodYE8bG/Fy+rK1R76Kvxa5SeVGxdhW /sZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=7S+/otONJq7A1+oidV272OlqVLwinjq666S1Pp9w7yk=; b=r0QHwnWdODMRjiQjjnlKHXaKHlQGW7+frPR2ZERT1eh8aS9Zx/yGvgfzW6GI+Golwl yJdHbNlJWRbBPJ0stsKZhNHMuT8LQ4RCP/nHJ65OEMWbIQmCBdAhjJcCOVfinjgeNW1u jfrIgWsz3ecd8vN63dCn/8IWYUIjbn/CnXtHSaPZVDl90ckMeaxNuMg6WZnvKEsDFc7k 40p305lSyfoOHYowZI0NGrjmKVqwsWN3CRKL6xpoiz9aTNlonrcd+aIZUEw5K9fMQYX+ d9Y8pUtfdZdgORHwO6HliggrF4Ajih8EFI8gCsgBHNixpUWf5XzZF2KjeoR0z0onpKu/ dOyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=edPI+Y5B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u125si19210829pgc.281.2019.04.06.01.21.54; Sat, 06 Apr 2019 01:22:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=edPI+Y5B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbfDFITE (ORCPT + 99 others); Sat, 6 Apr 2019 04:19:04 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34568 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfDFITE (ORCPT ); Sat, 6 Apr 2019 04:19:04 -0400 Received: by mail-pg1-f194.google.com with SMTP id v12so4327749pgq.1 for ; Sat, 06 Apr 2019 01:19:04 -0700 (PDT) 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-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=kKrqM/x8M+J9ulRSLbIOjQ+ZhpPfDG/RUDU3k9M3P9ZPyFvrZV2Zr4duuibekJlJG/ LgHsiSi8ouu+AAs6B6YT5gWIV7qHzIUOC0BwkS3rKldDbh88h6fAWbAQm4nOt963Ei8m 4yXq4cz9YiTxVLCabq64nAiKkd7jFd0OYBDSd5z8JjkQDY6EfGh3f3rEbOPi1vd/FRZe 2MWcjUYvNedlQIiUjzog4OGch+7I0dZGzm/MlEZV1/4NEKZmygSSVROzN+RL0lfbfNws p6B5yOHXxmDoOJ54XNTL+saIj6H5rwROK3GNE4H0y2PkqwVSOe0y4XQhaiEO/+RrUX1I /bbA== X-Gm-Message-State: APjAAAURYfuHxo4xnpZlEZSsmf17vU8lp13KDG8WMR9HtJgPRQtBy57V 91Cl37k66jyIr2TGG57g2Aw= 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 Cc: Sidong Yang , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.11.0