On Wed, 3 Nov 2021 17:44:11 +0200 "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote: > -enum tracefs_kprobe_type tracefs_kprobe_info(const char *group, const char *event, > - char **type, char **addr, char **format) > +enum tracefs_dynevent_type tracefs_kprobe_info(struct tracefs_dynevent *kprobe, > + char **system, char **event, > + char **prefix, char **addr, char **format) > { > - enum tracefs_kprobe_type rtype = TRACEFS_ALL_KPROBES; > - char *saveptr; > - char *content; > - char *system; > - char *probe; > - char *ktype; > - char *kaddr; > - char *kfmt; > - int ret; > - > - if (!group) > - group = KPROBE_DEFAULT_GROUP; > - > - if (type) > - *type = NULL; > + if (system) > + *system = NULL; > + if (event) > + *event = NULL; > + if (prefix) > + *prefix = NULL; > if (addr) > *addr = NULL; > if (format) > *format = NULL; > > - content = tracefs_instance_file_read(NULL, KPROBE_EVENTS, NULL); > - if (!content) > - return rtype; > - > - ret = parse_kprobe(content, &saveptr, &ktype, &system, &probe, > - &kaddr, &kfmt); > - > - while (!ret) { > - > - if (!strcmp(system, group) && !strcmp(probe, event)) { > - if (type) > - *type = strdup(ktype); > - if (addr) > - *addr = strdup(kaddr); > - if (format) > - *format = strdup(kfmt); > + if (!kprobe) > + return TRACEFS_DYNEVENT_MAX; > > - switch (*ktype) { > - case 'p': rtype = TRACEFS_KPROBE; break; > - case 'r': rtype = TRACEFS_KRETPROBE; break; > - } > - break; > + if (system) { > + if (kprobe->system) { > + *system = strdup(kprobe->system); > + if (!(*system)) > + goto error; > } > - ret = parse_kprobe(NULL, &saveptr, &ktype, &system, &probe, > - &kaddr, &kfmt); > } > - free(content); > - return rtype; > + if (event) { > + *event = strdup(kprobe->event); > + if (!(*event)) > + goto error; > + } > + if (prefix) { > + *prefix = strdup(kprobe->prefix); > + if (!(*prefix)) > + goto error; > + } > + if (addr && kprobe->address) { > + *addr = strdup(kprobe->address); > + if (!(*addr)) > + goto error; > + } > + if (format && kprobe->format) { > + *format = strdup(kprobe->format); > + if (!(*format)) > + goto error; > + } > + > + return kprobe->type; > + > +error: > + if (system) > + free(*system); > + if (event) > + free(*event); > + if (prefix) > + free(*prefix); > + if (addr) > + free(*addr); > + if (format) > + free(*format); > + return TRACEFS_DYNEVENT_MAX; > } The above can be shorten to just: enum tracefs_dynevent_type tracefs_kprobe_info(struct tracefs_dynevent *kprobe, char **system, char **event, char **prefix, char **addr, char **format) { char **lvalues[] = { system, event, prefix, addr, format }; char **rvalues[] = { &kprobe->system, &kprobe->event, &kprobe->prefix, &kprobe->address, &kprobe->format }; int i; if (!kprobe) return TRACEFS_DYNEVENT_MAX; for (i = 0; i < 5; i++) { if (lvalues[i]) { if (*rvalues[i]) { *lvalues[i] = strdup(*rvalues[i]); if (!*lvalues[i]) goto error; } else { *lvalues[i] = NULL; } } } return kprobe->type; error: for (i--; i >= 0; i--) { if (lvalues[i]) free(*lvalues[i]); } return TRACEFS_DYNEVENT_MAX; } ;-) -- Steve