All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Olivier Lorin <o.lorin@laposte.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH] media: gspca/gl860-mi1320: avoid -Wstring-concatenation warning
Date: Mon, 4 Oct 2021 13:38:23 +0200	[thread overview]
Message-ID: <CAK8P3a0ZOO-1QHAQbhPqFe9URX77bXORCybemLyd8DNQC-wVQw@mail.gmail.com> (raw)
In-Reply-To: <ea4cbdd2-3f78-7bc6-d378-b9edb14ce80d@xs4all.nl>

On Mon, Oct 4, 2021 at 12:55 PM Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> Hi Arnd,
>
> On 27/09/2021 14:20, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > Newer clang versions are suspicious of definitions that mix concatenated
> > strings with comma-separated arrays of strings, this has found real bugs
> > elsewhere, but this seems to be a false positive:
> >
> > drivers/media/usb/gspca/gl860/gl860-mi1320.c:62:37: error: suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma? [-Werror,-Wstring-concatenation]
> >         "\xd3\x02\xd4\x28\xd5\x01\xd0\x02" "\xd1\x18\xd2\xc1"
> >                                            ^
> >                                           ,
> > drivers/media/usb/gspca/gl860/gl860-mi1320.c:62:2: note: place parentheses around the string literal to silence warning
> >         "\xd3\x02\xd4\x28\xd5\x01\xd0\x02" "\xd1\x18\xd2\xc1"
> >
> > Use the extra parentheses as suggested in the warning message.
>
> I noticed that gl860-ov9655.c uses the same construct, doesn't that produce the
> same warning?

Curiously, it does not. I tried reproducing this in godbolt.org,
see https://godbolt.org/z/W6K69qcz3

For some reason, clang only warns about some of those, and it appears to
depend on the ratio between string concatenations and array elements.

> Also, does clang only warn about 'static u8 *tbl[]' initializers, or also
> for 'static u8 *tbl' initializers (i.e. not a pointer array) with the same
> string concatenation?

When there is only one element rather than an array, it does not warn,
because it's not a mix of concatenation and array elements.

> I made a patch that replaces these ugly hex strings with compound initializers:
>
> static u8 *tbl_640[] = {
>         (u8[]){
>                 0x0d, 0x80, 0xf1, 0x08, 0x03, 0x04, 0xf1, 0x04,
>                 0x04, 0x05, 0xf1, 0x02, 0x07, 0x01, 0xf1, 0x7c,
>                 0x08, 0x00, 0xf1, 0x0e, 0x21, 0x80, 0xf1, 0x00,
>                 0x0d, 0x00, 0xf1, 0x08, 0xf0, 0x00, 0xf1, 0x01,
>                 0x34, 0x10, 0xf1, 0x10, 0x3a, 0x43, 0xf1, 0x00,
>                 0xa6, 0x05, 0xf1, 0x02, 0xa9, 0x04, 0xf1, 0x04,
>                 0xa7, 0x02, 0xf1, 0x81, 0xaa, 0x01, 0xf1, 0xe2,
>                 0xae, 0x0c, 0xf1, 0x09
>         }, (u8[]){
>                 0xf0, 0x00, 0xf1, 0x02, 0x39, 0x03, 0xf1, 0xfc,
>                 0x3b, 0x04, 0xf1, 0x04, 0x57, 0x01, 0xf1, 0xb6,
>                 0x58, 0x02, 0xf1, 0x0d, 0x5c, 0x1f, 0xf1, 0x19,
>                 0x5d, 0x24, 0xf1, 0x1e, 0x64, 0x5e, 0xf1, 0x1c,
>                 0xd2, 0x00, 0xf1, 0x00, 0xcb, 0x00, 0xf1, 0x01
>         }, (u8[]){
>                 0xd3, 0x02, 0xd4, 0x10, 0xd5, 0x81, 0xd0, 0x02,
>                 0xd1, 0x08, 0xd2, 0xe1
>         }
> };
>
> but it clang also warns about 'static u8 *tbl' multi-string initializers,
> then it would make sense to replace all these hex-strings. It's rather
> ugly.

This seems fine.

       Arnd

  reply	other threads:[~2021-10-04 11:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 12:20 [PATCH] media: gspca/gl860-mi1320: avoid -Wstring-concatenation warning Arnd Bergmann
2021-10-04 10:55 ` Hans Verkuil
2021-10-04 11:38   ` Arnd Bergmann [this message]
2021-10-04 11:38     ` Arnd Bergmann

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=CAK8P3a0ZOO-1QHAQbhPqFe9URX77bXORCybemLyd8DNQC-wVQw@mail.gmail.com \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=o.lorin@laposte.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.