1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include "sample.h" 3 #include "debug.h" 4 #include <linux/zalloc.h> 5 #include <stdlib.h> 6 #include <string.h> 7 8 void perf_sample__init(struct perf_sample *sample, bool all) 9 { 10 if (all) { 11 memset(sample, 0, sizeof(*sample)); 12 } else { 13 sample->user_regs = NULL; 14 sample->intr_regs = NULL; 15 } 16 } 17 18 void perf_sample__exit(struct perf_sample *sample) 19 { 20 free(sample->user_regs); 21 free(sample->intr_regs); 22 } 23 24 struct regs_dump *perf_sample__user_regs(struct perf_sample *sample) 25 { 26 if (!sample->user_regs) { 27 sample->user_regs = zalloc(sizeof(*sample->user_regs)); 28 if (!sample->user_regs) 29 pr_err("Failure to allocate sample user_regs"); 30 } 31 return sample->user_regs; 32 } 33 34 35 struct regs_dump *perf_sample__intr_regs(struct perf_sample *sample) 36 { 37 if (!sample->intr_regs) { 38 sample->intr_regs = zalloc(sizeof(*sample->intr_regs)); 39 if (!sample->intr_regs) 40 pr_err("Failure to allocate sample intr_regs"); 41 } 42 return sample->intr_regs; 43 } 44