Re: [PATCH v2 04/13] perf dsos: Add dsos__for_each_dso

From: Namhyung Kim
Date: Fri Mar 22 2024 - 16:54:27 EST


On Fri, Mar 22, 2024 at 1:43 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> Hi Ian,
>
> On Thu, Mar 21, 2024 at 9:03 AM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> >
> > To better abstract the dsos internals, add dsos__for_each_dso that
> > does a callback on each dso. This also means the read lock can be
> > correctly held.
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
[SNIP]
> > diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c
> > index d269e09005a7..d43f64939b12 100644
> > --- a/tools/perf/util/dsos.c
> > +++ b/tools/perf/util/dsos.c
> > @@ -433,3 +433,19 @@ struct dso *dsos__find_kernel_dso(struct dsos *dsos)
> > up_read(&dsos->lock);
> > return res;
> > }
> > +
> > +int dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void *data), void *data)
> > +{
> > + struct dso *dso;
> > +
> > + down_read(&dsos->lock);
> > + list_for_each_entry(dso, &dsos->head, node) {
> > + int err;
> > +
> > + err = cb(dso, data);
> > + if (err)
> > + return err;
>
> Please break and return the error to release the lock.

Hmm.. I saw this code was replaced by the next patch.
Then probably it'd be ok to leave it.

Thanks,
Namhyung

>
> > + }
> > + up_read(&dsos->lock);
> > + return 0;
> > +}