Re: [PATCH v3 1/6] device property: Helper to match multiple connections

Andy Shevchenko
2022-03-07T09:42:33Z

On Sun, Mar 06, 2022 at 08:18:24PM -0600, Bjorn Andersson wrote:
> On Fri 04 Mar 07:52 CST 2022, Andy Shevchenko wrote:
> > On Fri, Mar 04, 2022 at 03:41:33PM +0200, Sakari Ailus wrote:

...

> > I have checked vsnprintf() and indeed, it expects to have the size is 0 when
> > the resulting buffer pointer is NULL, and it doesn't do any additional checks.
>
> Per the vsnprintf() semantics it's not the destination buffer being NULL
> that's significant, but rather just the length being 0 that matters.

Actually the main point is to have buffer to be NULL. But at the same
time size also has to be 0.

When the size is 0, but buffer is not NULL, it's a different story.

> To follow that, I should fill @matches_len entries in @matches and then
> just continue counting without storing anything in @matches.
>
> But that won't work in this case, because in the event that the @match
> function returns something that has to be freed (such as the refcounted
> objects returned by the typec_mux code), dropping this in favor of just
> counting it would cause memory/reference leaks.
>
> As such, I think this should differ in that @matches = NULL is
> significant, and it's nice to not have matches_len turn negative/bogus
> in the count case.
>
> So I like your suggestion.

--
With Best Regards,
Andy Shevchenko