linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Nathan Chancellor <natechancellor@gmail.com>,
	linux-media@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] media: saa7146: avoid high stack usage with clang
Date: Tue, 19 Feb 2019 10:41:40 -0800	[thread overview]
Message-ID: <CAKwvOdn0hF0s7-O2X98TSgO0C685ktZPTXRQ7CeR5vKHVZktPQ@mail.gmail.com> (raw)
In-Reply-To: <20190219170209.4180739-1-arnd@arndb.de>

On Tue, Feb 19, 2019 at 9:02 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> Two saa7146/hexium files contain a construct that causes a warning
> when built with clang:
>
> drivers/media/pci/saa7146/hexium_orion.c:210:12: error: stack frame size of 2272 bytes in function 'hexium_probe'
>       [-Werror,-Wframe-larger-than=]
> static int hexium_probe(struct saa7146_dev *dev)
>            ^
> drivers/media/pci/saa7146/hexium_gemini.c:257:12: error: stack frame size of 2304 bytes in function 'hexium_attach'
>       [-Werror,-Wframe-larger-than=]
> static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
>            ^
>
> This one happens regardless of KASAN, and the problem is that a
> constructor to initalize a dynamically allocated structure leads
> to a copy of that structure on the stack, whereas gcc initializes
> it in place.
>
> Link: https://bugs.llvm.org/show_bug.cgi?id=40776

oof, great bug report by the way!  Thanks for the fix.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/media/pci/saa7146/hexium_gemini.c | 4 +---
>  drivers/media/pci/saa7146/hexium_orion.c  | 4 +---
>  2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
> index 5817d9cde4d0..f7ce0e1770bf 100644
> --- a/drivers/media/pci/saa7146/hexium_gemini.c
> +++ b/drivers/media/pci/saa7146/hexium_gemini.c
> @@ -270,9 +270,7 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
>         /* enable i2c-port pins */
>         saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
>
> -       hexium->i2c_adapter = (struct i2c_adapter) {
> -               .name = "hexium gemini",
> -       };
> +       strscpy(hexium->i2c_adapter.name, "hexium gemini", sizeof(hexium->i2c_adapter.name));
>         saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
>         if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
>                 DEB_S("cannot register i2c-device. skipping.\n");
> diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
> index 0a05176c18ab..b9f4a09c744d 100644
> --- a/drivers/media/pci/saa7146/hexium_orion.c
> +++ b/drivers/media/pci/saa7146/hexium_orion.c
> @@ -231,9 +231,7 @@ static int hexium_probe(struct saa7146_dev *dev)
>         saa7146_write(dev, DD1_STREAM_B, 0x00000000);
>         saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
>
> -       hexium->i2c_adapter = (struct i2c_adapter) {
> -               .name = "hexium orion",
> -       };
> +       strscpy(hexium->i2c_adapter.name, "hexium orion", sizeof(hexium->i2c_adapter.name));

Note that "sparse" designated initialization zero initializes unnnamed members:
https://godbolt.org/z/LkSpJp
This transform you've done is safe because hexium was zero initialized
via kzalloc, and struct hexium contains a struct i2c_adapter (as
opposed to  a pointer to a struct i2c_adapter).  The same is true for
both translation units you've touched. LGTM

>         saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
>         if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
>                 DEB_S("cannot register i2c-device. skipping.\n");
> --
> 2.20.0
>


-- 
Thanks,
~Nick Desaulniers

      parent reply	other threads:[~2019-02-19 18:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19 17:01 [PATCH 1/3] media: saa7146: avoid high stack usage with clang Arnd Bergmann
2019-02-19 17:01 ` [PATCH 2/3] media: vicodec: avoic clang frame size warning Arnd Bergmann
2019-02-19 19:01   ` Nick Desaulniers
2019-02-19 19:14     ` Arnd Bergmann
2019-02-19 19:56   ` Hans Verkuil
2019-02-19 17:01 ` [PATCH 3/3] media: go7007: avoid clang frame overflow warning with KASAN Arnd Bergmann
2019-02-19 18:41 ` Nick Desaulniers [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=CAKwvOdn0hF0s7-O2X98TSgO0C685ktZPTXRQ7CeR5vKHVZktPQ@mail.gmail.com \
    --to=ndesaulniers@google.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=natechancellor@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;
as well as URLs for NNTP newsgroup(s).