[Nouveau] libdrm: Make some kernel structures fully initialized

Michel Hermier michel.hermier at gmail.com
Mon Dec 20 00:16:18 PST 2010


I noticed it after sending the patch, the appropriate C allocation
definition seems to be
    struct drm_nouveau_gem_new req = {{ 0 }};

There is a problem with using memset for me. Using this default
initialiser, the compiler should be able to force to 0 only the needed
values when doing optimisations passes, while with memset it may not
see them. And I read on some website that using memset is bad for some
other reasons and that using this construction is the C way to
properly initialise structures/array (on the stack).

2010/12/19 Xavier Chantry <chantry.xavier at gmail.com>:
> On Fri, Dec 17, 2010 at 1:37 PM, Michel Hermier
> <michel.hermier at gmail.com> wrote:
>> Hi,
>> A patch that initialise kernel structures. In addition  to reduce the
>> noise of valgrind when running piglit tests, it may be also
>> interesting to have these structures fully initialised for the future
>> in case of some kernel ioctrl changes.
>>
>
> If you send your patch inline (e.g. with git send-email), we can also
> review inline which is practical.
>
> Just one comment :
> nouveau_bo.c: In function 'nouveau_bo_kalloc':
> nouveau_bo.c:116:9: warning: missing braces around initializer
> nouveau_bo.c:116:9: warning: (near initialization for 'req.info')
>
> Thats because the first member of drm_nouveau_gem_new is another
> structure : drm_nouveau_gem_info
>
> This seems to work:
>        struct drm_nouveau_gem_new req = { { 0 }, 0, 0 };
>
> And we could also use memset.
>


More information about the Nouveau mailing list