From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hans Verkuil Subject: Re: sparse: ARRAY_SIZE and sparse array initialization Date: Sat, 15 Mar 2014 13:12:27 +0100 Message-ID: <532443AB.9080105@xs4all.nl> References: <532442E2.7050206@xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from smtp-vbr2.xs4all.nl ([194.109.24.22]:4194 "EHLO smtp-vbr2.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754911AbaCOMMh (ORCPT ); Sat, 15 Mar 2014 08:12:37 -0400 In-Reply-To: <532442E2.7050206@xs4all.nl> Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: linux-sparse@vger.kernel.org Cc: Linux Media Mailing List For the record: all these tests were done with a 3.14-rc5 kernel and sparse compiled from the git tree as of today (version v0.5.0). The gcc version is 4.8.2. Regards, Hans On 03/15/2014 01:09 PM, Hans Verkuil wrote: > 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 > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >