Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1067148yba; Sat, 6 Apr 2019 02:49:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxg6ozrCzDiOGVrEV0opqD2dG2WqVjBUPdoEGkDmOKWq02RY70jEMR1SCUPV8q6yk5EIJtm X-Received: by 2002:a63:d444:: with SMTP id i4mr17355692pgj.149.1554544189987; Sat, 06 Apr 2019 02:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554544189; cv=none; d=google.com; s=arc-20160816; b=MtigAkGdlBcvNhPcHHI3qJsIO8Nh7hrr0Ib5cS0HYcXH/BDMHx2aK4ItJLzupqsJaW gWD9UosPjTw18VdFhysBkCa2l/Y00m/JMLhk/g1Zpwd0Gnfu4wNLCD/rZrYDYc4892Zj VpFc/CVryKEbgflnC2OeM+sHKKA/DVSC4RVxLaiMSYhEdEizaOEwgNkAoByA9Wr7oTVv 4Te7kqkps4H7xbK+qy/y4zK3RGqTSnFumUV8DJJ5iSjFj1mPxkLeMuGQ2BecVghQkT/I StNeZkExzZOCoh13Sum4wtVYf1PshpcMluFllp1QvDfV40gJ08y74c1Q8LqkhmEE90ns KmsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=LcuR4nAQbGGhCKHp6GxzOlh9AEq6YAbVCqgH19rhQYU=; b=YCOk+mJ52mTjZ/+SA3COSKtS7XLSwHKbcvizKQOesRD/+PFHjRFz+DTAoxh/SPVBQb E7Nzd6GtZ2h5gYAlS8ygSqlR21v47nXqrAU3KwOpjUCK9SuEfnf9I106qm+Z13AL5GM7 Po9uyy92SbLg3zA2ffuzaGOraT2TxFxrPfS9N/HU9plWhaM8J+i3eQuQQRj+HrpCi846 4/NwQtg72Xqv+M7x3AmEF518W1npMPKiVWezSN4TvesbqSzd5g0DPSvhQg+eXYH6mwUA xuhX/x7+tlKDYyJLjy8hujnAKZ6o93hXexC1d/vM7lVuqeqoHw5SANYGK3v3usUfkvUc oQJA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si14832167pll.127.2019.04.06.02.49.34; Sat, 06 Apr 2019 02:49:49 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbfDFJrZ (ORCPT + 99 others); Sat, 6 Apr 2019 05:47:25 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34994 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725978AbfDFJrZ (ORCPT ); Sat, 6 Apr 2019 05:47:25 -0400 Received: by mail-ed1-f65.google.com with SMTP id s39so7572663edb.2 for ; Sat, 06 Apr 2019 02:47:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LcuR4nAQbGGhCKHp6GxzOlh9AEq6YAbVCqgH19rhQYU=; b=dszE5Sto64hmC4jXpNN8RlQpP4nbMYRPVjRAhoYr2RnbvG+veNTWRHLfsdGZ7N1yaf ga1fSLc9avIZtt25ZTTGDqPt048xEOHwHO31VC+xwM1rxb0rmRHYpod/SPXtOmCyWMP/ N7VpDl9X7vPLmramgZi1a/opiZXwu3cgZ5EYm5YVog58Js5iGfRZa7OA1qFr0GK/9b2Z RKsLXBH6l5+UlM7eMqrENi5GkXJb3Bo5PukpRFdeQkcXZjGIRXbiLuVYe8ROA80P6sGf wcjT2kzzvxQZ0LiA8eeXDGGXSVA7eKVyAanEh88r7SU4RYYJ2sxB+RkyjH05c878ejnx 4fVw== X-Gm-Message-State: APjAAAXEjhpkHNZ4g/6mOSklQSdgxaxUzW1+wbiG5KpkovfnKfNBYjv/ 02Uipaz++0ryToyVFDXt8zn4bsy1LvU= X-Received: by 2002:a17:906:1984:: with SMTP id g4mr9890808ejd.260.1554544043313; Sat, 06 Apr 2019 02:47:23 -0700 (PDT) Received: from shalem.localdomain (84-106-84-65.cable.dynamic.v4.ziggo.nl. [84.106.84.65]) by smtp.gmail.com with ESMTPSA id y12sm2295370ejr.75.2019.04.06.02.47.22 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sat, 06 Apr 2019 02:47:22 -0700 (PDT) Subject: Re: [PATCH] drm/vboxvideo: Avoid double check buffer_overflow in vbva_write() To: Sidong Yang Cc: David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20190406081850.1906-1-realwakka@gmail.com> From: Hans de Goede Message-ID: <4f5fc992-f220-d7eb-6412-977c49b754ef@redhat.com> Date: Sat, 6 Apr 2019 11:47:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190406081850.1906-1-realwakka@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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, >