From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 935ECC433B4 for ; Wed, 5 May 2021 21:42:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 11735613E3 for ; Wed, 5 May 2021 21:42:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11735613E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lePHX-000495-87 for qemu-devel@archiver.kernel.org; Wed, 05 May 2021 17:42:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leP3V-0002zG-N6; Wed, 05 May 2021 17:27:41 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]:44632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1leP3U-000500-1e; Wed, 05 May 2021 17:27:41 -0400 Received: by mail-ej1-x635.google.com with SMTP id gx5so5050853ejb.11; Wed, 05 May 2021 14:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dXBkKKd+m6tu8qUnC9WZa5slYUNEIVTt4LsyJPz79YE=; b=Jy+G/COwEoalNAdnZZJ+/lREXcNTIhFU+een1rGJnffdQX63shkJ4DvpKofx0FpcAx W8yvF67+osf47gythctVciIK/YrgJmk8kKFzWHEo4SvGba1R4yGku+OU/p4j9fR074O8 7XQfczKJlTdvXorCEWzAZFYe75IW1/kiCj/TLidsB1zBtZWgpICfkEW5GRoTgzptJfrY 8MMY638HsUcpK0jSYhNnury1/TYiysT8q3Dt4xjtFmPuxj9rKGLwoYnsZdRFqjWQUWMx k6HB/UuI8Ca+cXpQeM0AZmekHWp/roMIxwn3ExklclojOSE3uVjY3oHYrgb+SVtQS0No Wirg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dXBkKKd+m6tu8qUnC9WZa5slYUNEIVTt4LsyJPz79YE=; b=KsyvlOYQl7wHiZ5yTfqtmyL7nNXul3zIz1Mt70ctVGx2naYJV0AL4568rHuvufrqcz OIV+5lwYybUC614Q8WxQMlCMsRGt1iRuNYEMIEzZvVY80VSCV+vknEhUGwvnm1OrFqfe sqRCJGAzp0nrv69FChJnh/wKFaew5y9sS3AQfGzysPksVb6gMgNzyHGD7+bVnZC7aeqs S6CB3tt/Z/EoJktokNnt2+MwkbIW4sGokoSKauA94+G4wlOjiTvLPvCp9N6jInkI/Vxi AuY+kjOPcOWVT14O+25AYRFsOBVRm0EUMhXEA4ZTMjXyx52s6NT0Ouqe/3pGWvZWZIXU HCdg== X-Gm-Message-State: AOAM533sditY6+NR6laK/MraRCFFUX/Xe1K6fu1S4pdAOB2s+/Qq+2E7 f/+hHM81y9045X+ohgJqhsxojf506BbpwmXB4JPeqOgDg9g= X-Google-Smtp-Source: ABdhPJyJpmt3CbSHS67kNtc6MvGj0zO51nIM9zwOCIOIvm2GWOSvU6gU3Ydoy5x6eSV0Jsc7FApfJSYSUrfGIsku+yc= X-Received: by 2002:a17:906:7e51:: with SMTP id z17mr839225ejr.92.1620250057369; Wed, 05 May 2021 14:27:37 -0700 (PDT) MIME-Version: 1.0 References: <20210505211047.1496765-1-philmd@redhat.com> <20210505211047.1496765-4-philmd@redhat.com> In-Reply-To: <20210505211047.1496765-4-philmd@redhat.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Thu, 6 May 2021 01:27:25 +0400 Message-ID: Subject: Re: [PATCH 03/23] chardev/baum: Use definitions to avoid dynamic stack allocation To: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Content-Type: multipart/alternative; boundary="0000000000001deb9305c19bddc4" Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=marcandre.lureau@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , "open list:Block layer core" , Richard Henderson , QEMU , "open list:sPAPR pseries" , Gerd Hoffmann , Paolo Bonzini , Samuel Thibault Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000001deb9305c19bddc4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 6, 2021 at 1:14 AM Philippe Mathieu-Daud=C3=A9 wrote: > We know 'x * y' will be at most 'X_MAX * Y_MAX' (which is not > a big value, it is actually 84). Instead of having the compiler > use variable-length array, declare an array able to hold the > maximum 'x * y'. > > Signed-off-by: Philippe Mathieu-Daud=C3=A9 > Reviewed-by: Marc-Andr=C3=A9 Lureau --- > chardev/baum.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/chardev/baum.c b/chardev/baum.c > index adc3d7b3b56..0822e9ed5f3 100644 > --- a/chardev/baum.c > +++ b/chardev/baum.c > @@ -383,9 +383,9 @@ static int baum_eat_packet(BaumChardev *baum, const > uint8_t *buf, int len) > switch (req) { > case BAUM_REQ_DisplayData: > { > - uint8_t cells[baum->x * baum->y], c; > - uint8_t text[baum->x * baum->y]; > - uint8_t zero[baum->x * baum->y]; > + uint8_t cells[X_MAX * Y_MAX], c; > + uint8_t text[X_MAX * Y_MAX]; > + uint8_t zero[X_MAX * Y_MAX]; > int cursor =3D BRLAPI_CURSOR_OFF; > int i; > > @@ -408,7 +408,7 @@ static int baum_eat_packet(BaumChardev *baum, const > uint8_t *buf, int len) > } > timer_del(baum->cellCount_timer); > > - memset(zero, 0, sizeof(zero)); > + memset(zero, 0, baum->x * baum->y); > eh, I would have left the sizeof(zero).. > brlapi_writeArguments_t wa =3D { > .displayNumber =3D BRLAPI_DISPLAY_DEFAULT, > -- > 2.26.3 > > > --=20 Marc-Andr=C3=A9 Lureau --0000000000001deb9305c19bddc4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, May 6, 2021 at 1:14 AM Philip= pe Mathieu-Daud=C3=A9 <philmd@redhat.com> wrote:
We know 'x * y' will be at most 'X_MAX *= Y_MAX' (which is not
a big value, it is actually 84). Instead of having the compiler
use variable-length array, declare an array able to hold the
maximum 'x * y'.

Signed-off-by: Philippe Mathieu-Daud=C3=A9 <philmd@redhat.com>
<= br>
Reviewed-by: Marc-Andr=C3=A9 Lureau <marcandre.lureau@redhat.com= >

---
=C2=A0chardev/baum.c | 8 ++++----
=C2=A01 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/chardev/baum.c b/chardev/baum.c
index adc3d7b3b56..0822e9ed5f3 100644
--- a/chardev/baum.c
+++ b/chardev/baum.c
@@ -383,9 +383,9 @@ static int baum_eat_packet(BaumChardev *baum, const uin= t8_t *buf, int len)
=C2=A0 =C2=A0 =C2=A0switch (req) {
=C2=A0 =C2=A0 =C2=A0case BAUM_REQ_DisplayData:
=C2=A0 =C2=A0 =C2=A0{
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t cells[baum->x * baum->y], c;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t text[baum->x * baum->y];
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t zero[baum->x * baum->y];
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t cells[X_MAX * Y_MAX], c;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t text[X_MAX * Y_MAX];
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t zero[X_MAX * Y_MAX];
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int cursor =3D BRLAPI_CURSOR_OFF;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int i;

@@ -408,7 +408,7 @@ static int baum_eat_packet(BaumChardev *baum, const uin= t8_t *buf, int len)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0timer_del(baum->cellCount_timer);

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 memset(zero, 0, sizeof(zero));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 memset(zero, 0, baum->x * baum->y);
<= /blockquote>

eh, I would have left the sizeof(zero)..


=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0brlapi_writeArguments_t wa =3D {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.displayNumber =3D BRLAPI_D= ISPLAY_DEFAULT,
--
2.26.3




--
Marc-Andr= =C3=A9 Lureau
--0000000000001deb9305c19bddc4--