On Sat, Jul 11, 2026 at 03:26:18PM +0200, Danilo Krummrich wrote:
> On Fri Jul 10, 2026 at 8:52 PM CEST, =?UTF-8?q?Christian=20K=C3=B6nig?= wrote:
> > +/**
> > + * ttm_bo_is_deleted - test if buffer is already deleted
> > + * @bo: the struct ttm_buffer_object to test
> > + *
> > + * Returns true if the buffer is already deleted and only waiting for
> > + * destruction.
> > + */
> > +static inline bool ttm_bo_is_deleted(struct ttm_buffer_object *bo)
> > +{
> > + return !kref_read(&bo->base.refcount);
> > +}
>
> This is an anti-pattern, branch decisions cannot rely on an atomic reference
> count unless additional invariants are upheld that otherwise guarantee that
> the
> read values does not instantly become meaningless.
So I believe that means the TTM refcount reaching zero is a terminal
state; i.e., reinitialization (0 -> 1) is not allowed. I believe I agree
with that or if reinit is allowed the check needs to change.
Matt
>
> Something like this should at least document in which context and under which
> conditions it is valid to rely on the returned value.