Skip to content

Commit 4e60867

Browse files
author
Alexei Starovoitov
committed
Merge up to bpf_probe_read_kernel_str() fix into bpf-next
2 parents 9d9d8cc + 02553b9 commit 4e60867

7 files changed

Lines changed: 11 additions & 24 deletions

File tree

‎include/uapi/linux/bpf.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@ union bpf_attr {
31683168
* Return
31693169
* The id is returned or 0 in case the id could not be retrieved.
31703170
*
3171-
* void *bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
3171+
* int bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
31723172
* Description
31733173
* Copy *size* bytes from *data* into a ring buffer *ringbuf*.
31743174
* If BPF_RB_NO_WAKEUP is specified in *flags*, no notification of

‎kernel/trace/bpf_trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bpf_probe_read_kernel_str_common(void *dst, u32 size, const void *unsafe_ptr)
241241
if (unlikely(ret < 0))
242242
goto fail;
243243

244-
return 0;
244+
return ret;
245245
fail:
246246
memset(dst, 0, size);
247247
return ret;

‎samples/bpf/xdp_monitor_user.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,8 @@ static void *alloc_rec_per_cpu(int record_size)
509509
{
510510
unsigned int nr_cpus = bpf_num_possible_cpus();
511511
void *array;
512-
size_t size;
513512

514-
size = record_size * nr_cpus;
515-
array = malloc(size);
516-
memset(array, 0, size);
513+
array = calloc(nr_cpus, record_size);
517514
if (!array) {
518515
fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
519516
exit(EXIT_FAIL_MEM);
@@ -528,8 +525,7 @@ static struct stats_record *alloc_stats_record(void)
528525
int i;
529526

530527
/* Alloc main stats_record structure */
531-
rec = malloc(sizeof(*rec));
532-
memset(rec, 0, sizeof(*rec));
528+
rec = calloc(1, sizeof(*rec));
533529
if (!rec) {
534530
fprintf(stderr, "Mem alloc error\n");
535531
exit(EXIT_FAIL_MEM);

‎samples/bpf/xdp_redirect_cpu_user.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,8 @@ static struct datarec *alloc_record_per_cpu(void)
207207
{
208208
unsigned int nr_cpus = bpf_num_possible_cpus();
209209
struct datarec *array;
210-
size_t size;
211210

212-
size = sizeof(struct datarec) * nr_cpus;
213-
array = malloc(size);
214-
memset(array, 0, size);
211+
array = calloc(nr_cpus, sizeof(struct datarec));
215212
if (!array) {
216213
fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
217214
exit(EXIT_FAIL_MEM);
@@ -226,11 +223,11 @@ static struct stats_record *alloc_stats_record(void)
226223

227224
size = sizeof(*rec) + n_cpus * sizeof(struct record);
228225
rec = malloc(size);
229-
memset(rec, 0, size);
230226
if (!rec) {
231227
fprintf(stderr, "Mem alloc error\n");
232228
exit(EXIT_FAIL_MEM);
233229
}
230+
memset(rec, 0, size);
234231
rec->rx_cnt.cpu = alloc_record_per_cpu();
235232
rec->redir_err.cpu = alloc_record_per_cpu();
236233
rec->kthread.cpu = alloc_record_per_cpu();

‎samples/bpf/xdp_rxq_info_user.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,8 @@ static struct datarec *alloc_record_per_cpu(void)
198198
{
199199
unsigned int nr_cpus = bpf_num_possible_cpus();
200200
struct datarec *array;
201-
size_t size;
202201

203-
size = sizeof(struct datarec) * nr_cpus;
204-
array = malloc(size);
205-
memset(array, 0, size);
202+
array = calloc(nr_cpus, sizeof(struct datarec));
206203
if (!array) {
207204
fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
208205
exit(EXIT_FAIL_MEM);
@@ -214,11 +211,8 @@ static struct record *alloc_record_per_rxq(void)
214211
{
215212
unsigned int nr_rxqs = bpf_map__def(rx_queue_index_map)->max_entries;
216213
struct record *array;
217-
size_t size;
218214

219-
size = sizeof(struct record) * nr_rxqs;
220-
array = malloc(size);
221-
memset(array, 0, size);
215+
array = calloc(nr_rxqs, sizeof(struct record));
222216
if (!array) {
223217
fprintf(stderr, "Mem alloc error (nr_rxqs:%u)\n", nr_rxqs);
224218
exit(EXIT_FAIL_MEM);
@@ -232,8 +226,7 @@ static struct stats_record *alloc_stats_record(void)
232226
struct stats_record *rec;
233227
int i;
234228

235-
rec = malloc(sizeof(*rec));
236-
memset(rec, 0, sizeof(*rec));
229+
rec = calloc(1, sizeof(struct stats_record));
237230
if (!rec) {
238231
fprintf(stderr, "Mem alloc error\n");
239232
exit(EXIT_FAIL_MEM);

‎tools/bpf/bpftool/map.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const char * const map_type_name[] = {
4949
[BPF_MAP_TYPE_STACK] = "stack",
5050
[BPF_MAP_TYPE_SK_STORAGE] = "sk_storage",
5151
[BPF_MAP_TYPE_STRUCT_OPS] = "struct_ops",
52+
[BPF_MAP_TYPE_RINGBUF] = "ringbuf",
5253
};
5354

5455
const size_t map_type_name_size = ARRAY_SIZE(map_type_name);

‎tools/include/uapi/linux/bpf.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@ union bpf_attr {
31683168
* Return
31693169
* The id is returned or 0 in case the id could not be retrieved.
31703170
*
3171-
* void *bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
3171+
* int bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
31723172
* Description
31733173
* Copy *size* bytes from *data* into a ring buffer *ringbuf*.
31743174
* If BPF_RB_NO_WAKEUP is specified in *flags*, no notification of

0 commit comments

Comments
 (0)