On Mon, 24 Sep 2012 12:59:42 -0300, Arnaldo Carvalho de Melo wrote: > From: Arnaldo Carvalho de Melo <a...@redhat.com> > > The existing constructor receives a perf_event_attr filled with the > event type and the config. > > To reduce the boilerplate for tracepoints, provide a new constructor, > perf_evsel__newtp() that receives the tracepoint name and will open > the debugfs file, call into libtraceevent new pevent_parse_format file > to fill its ->tp_format member, so that users can then just call > perf_evsel__field() to access its fields. [snip] > +static struct event_format *event_format__new(const char *sys, const char > *name) > +{ > + int fd, n; > + char *filename; > + void *bf = NULL, *nbf; > + size_t size = 0, alloc_size = 0; > + struct event_format *format = NULL; > + > + if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, > name) < 0) > + goto out; > + > + fd = open(filename, O_RDONLY); > + if (fd < 0) > + goto out_free_filename; > + > + do { > + if (size == alloc_size) { > + alloc_size += BUFSIZ; > + nbf = realloc(bf, alloc_size); > + if (nbf == NULL) > + goto out_free_bf; > + bf = nbf; > + } > + > + n = read(fd, bf + size, BUFSIZ);
Wouldn't it be better doing s/BUFSIZ/alloc_size - size/ ? Although there'll be no partial reading issue when working on debugfs I guess. Thanks, Namhyung > + if (n < 0) > + goto out_free_bf; > + size += n; > + } while (n > 0); > + > + pevent_parse_format(&format, bf, size, sys); > + > +out_free_bf: > + free(bf); > + close(fd); > +out_free_filename: > + free(filename); > +out: > + return format; > +} -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/