From: Hans Verkuil <hverkuil@xs4all.nl>
To: linux-sparse@vger.kernel.org
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: sparse: ARRAY_SIZE and sparse array initialization
Date: Sat, 15 Mar 2014 13:09:06 +0100 [thread overview]
Message-ID: <532442E2.7050206@xs4all.nl> (raw)
Hmm, interesting. Twice 'sparse' in the same subject line with different meanings :-)
This is another sparse error I get with drivers/media/v4l2-core/v4l2-ioctl.c:
drivers/media/v4l2-core/v4l2-ioctl.c:424:9: error: cannot size expression
(there are more of those in drivers/media, all with the same cause).
This sparse (the tool) error occurs because of sparse (C language) array initialization
in combination with ARRAY_SIZE:
static const char *v4l2_memory_names[] = {
[V4L2_MEMORY_MMAP] = "mmap",
[V4L2_MEMORY_USERPTR] = "userptr",
[V4L2_MEMORY_OVERLAY] = "overlay",
[V4L2_MEMORY_DMABUF] = "dmabuf",
};
#define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
static void v4l_print_requestbuffers(const void *arg, bool write_only)
{
const struct v4l2_requestbuffers *p = arg;
pr_cont("count=%d, type=%s, memory=%s\n",
p->count,
prt_names(p->type, v4l2_type_names),
prt_names(p->memory, v4l2_memory_names));
}
I could change v4l2_memory_names to:
static const char *v4l2_memory_names[V4L2_MEMORY_DMABUF + 1] = {
and the error goes away.
I'm actually not sure if this is a sparse bug or a feature.
If it is a feature then the error message is definitely wrong, since the size is
perfectly well defined. As an aside: the error message is pretty vague IMHO.
Regards,
Hans
next reply other threads:[~2014-03-15 12:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-15 12:09 Hans Verkuil [this message]
2014-03-15 12:12 ` sparse: ARRAY_SIZE and sparse array initialization Hans Verkuil
2014-03-28 10:50 ` Hans Verkuil
2014-03-30 6:10 ` Christopher Li
2014-03-30 12:03 ` Hans Verkuil
2014-03-30 16:48 ` Linus Torvalds
2014-03-30 17:03 ` Hans Verkuil
2014-03-30 17:16 ` Christopher Li
2014-03-30 17:24 ` Linus Torvalds
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=532442E2.7050206@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
/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).