Re: [PATCH 1/2] tracing/ftrace: handle more than one stat file pertracer

From: Steven Rostedt
Date: Tue Jan 06 2009 - 12:28:45 EST




On Tue, 6 Jan 2009, Frederic Weisbecker wrote:
> > > +
> > > + if (all_stat_sessions) {
> > > + for (i = 0; i < nb_sessions; i++) {
> > > + session = all_stat_sessions[i];
> > > + reset_stat_session(session);
> > > + mutex_destroy(&session->stat_mutex);
> > > + kfree(session);
> > > + }
> > > + }
> > > + all_stat_sessions = kmalloc(sizeof(struct tracer_stat_session *) * nb,
> > > + GFP_KERNEL);
> >
> > You want this to be kzalloc.
> >
> > > + if (!all_stat_sessions)
> > > + return -ENOMEM;
> > > +
> > > + for (i = 0; i < nb; i++) {
> > > + session = kmalloc(sizeof(struct tracer_stat_session) * nb,
> > > + GFP_KERNEL);
> >
> > Not so important, but you probably want to do it here too.
> >
> > > + if (!session)
> > > + goto free_sessions;
> > > +
> > > + INIT_LIST_HEAD(&session->stat_list.list);
> > > + mutex_init(&session->stat_mutex);
> > > + session->ts = &ts[i];
> > > + all_stat_sessions[i] = session;
> > > + }
> > > + nb_sessions = nb;
> > > + return 0;
> > > +
> > > +free_sessions:
> > > +
> > > + for (j = 0; j < i; j++)
> > > + kfree(all_stat_sessions[i]);
> >
> > With out the kzalloc above, this may crash the kernel, because
> > all_stat_sessions[i] might not be NULL when they were not initialized.
>
>
> I'm not sure. j will not go through indexes of rooms that weren't allocated.

Ah, OK, my eyes confused i's and j's so I did not notice the loop to last
failed. Which is strange because I write similar code :-/.

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/