[igt-dev] [PATCH 01/76] lib: Introduce typed cleanups

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Wed Oct 5 08:02:57 UTC 2022


On Wed, 5 Oct 2022 09:45:32 +0200
Zbigniew Kempczyński <zbigniew.kempczynski at intel.com> wrote:

> > +void igt_cleanup_fd(volatile int *fd);
> > +#define igt_fd_t(x__) \
> > +	volatile int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)  
> 
> Why do we need volatile here? Variable after initalization (open) likely won't
> be touched (until exiting its scope) so what's the risk?

With current gcc versions, volatile is not needed, but this fails with
clang. The real problem is that C spec doesn't define what happens
with an automatic stack variable after doing a longjmp.

From Petri's feedback, the only solution that works is to declare
such variables as volatile.

Regards,
Mauro


More information about the igt-dev mailing list