> > * The use of from():
> >
> >                 let clk = bindings::qdev_init_clock_in(...)
> >                 Owned::from(&*clk)
> 
> In this case the C side wants to manage the reference that
> qdev_init_clock_in() returns; it is dropped in
> qdev_finalize_clocklist(). So Rust code needs to increase the
> refcount.

Pls forgive me for one more question about qdev_init_clock_in() on the C
side. :-)

qdev_init_clock_in() didn't unref `clk` after object_property_add_child(),
so it is intentional, to make the ref count of `clk` be 2:
 * 1 count is held by clocklist until qdev_finalize_clocklist().
 * another 1 is held by its parent via QOM Child<>.

Am I understanding it correctly?

> > Then the comment "the clock is heap allocated and does not have
> > a reference" sounds like a conflict. I'm sure I'm missing something. :-(
> 
> Changed:
> 
>       // SAFETY: the clock is heap allocated, but qdev_init_clock_in()
>       // does not gift the reference to its caller; so use Owned::from to
>       // add one.  the callback is disabled automatically when the clock
>       // is unparented, which happens before the device is finalized.

LGTM.

Thank you very much for your patience. I think I understand ref count
now.

Regards,
Zhao



Reply via email to