[PATCH v2] drm/ttm: Silence randstruct warning about casting struct file

Kees Cook kees at kernel.org
Fri May 2 02:24:30 UTC 2025


On Thu, May 01, 2025 at 07:13:12PM -0700, Matthew Brost wrote:
> On Thu, May 01, 2025 at 05:24:38PM -0700, Kees Cook wrote:
> > Casting through a "void *" isn't sufficient to convince the randstruct
> > GCC plugin that the result is intentional. Instead operate through an
> > explicit union to silence the warning:
> > 
> > drivers/gpu/drm/ttm/ttm_backup.c: In function 'ttm_file_to_backup':
> > drivers/gpu/drm/ttm/ttm_backup.c:21:16: note: randstruct: casting between randomized structure pointer types (ssa): 'struct ttm_backup' and 'struct file'
> >    21 |         return (void *)file;
> >       |                ^~~~~~~~~~~~
> > 
> > Suggested-by: Matthew Brost <matthew.brost at intel.com>
> 
> I forgot the policy if suggest-by but will add:
> Reviewed-by: Matthew Brost <matthew.brost at intel.com>

Yeah, and feel free to snag authorship entirely if you want. I only
updated the comment, really. :)

> Thomas was out today I suspect he will look at this tomorrow when he is
> back too.

Cool, no rush. It's currently just a warning in -next re-exposed by
randstruct getting cleared for allmodconfig again. :)

Thanks!

-Kees

-- 
Kees Cook


More information about the dri-devel mailing list