serial: exar: Fix GPIO configuration for Sealevel cards based on XR17V35X
[linux/fpc-iii.git] / kernel / bpf / map_iter.c
blobc69071e334bf6e2c7460715b6e416d9fb6e956f8
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2020 Facebook */
3 #include <linux/bpf.h>
4 #include <linux/fs.h>
5 #include <linux/filter.h>
6 #include <linux/kernel.h>
8 struct bpf_iter_seq_map_info {
9 u32 mid;
12 static void *bpf_map_seq_start(struct seq_file *seq, loff_t *pos)
14 struct bpf_iter_seq_map_info *info = seq->private;
15 struct bpf_map *map;
17 map = bpf_map_get_curr_or_next(&info->mid);
18 if (!map)
19 return NULL;
21 ++*pos;
22 return map;
25 static void *bpf_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
27 struct bpf_iter_seq_map_info *info = seq->private;
28 struct bpf_map *map;
30 ++*pos;
31 ++info->mid;
32 bpf_map_put((struct bpf_map *)v);
33 map = bpf_map_get_curr_or_next(&info->mid);
34 if (!map)
35 return NULL;
37 return map;
40 struct bpf_iter__bpf_map {
41 __bpf_md_ptr(struct bpf_iter_meta *, meta);
42 __bpf_md_ptr(struct bpf_map *, map);
45 DEFINE_BPF_ITER_FUNC(bpf_map, struct bpf_iter_meta *meta, struct bpf_map *map)
47 static int __bpf_map_seq_show(struct seq_file *seq, void *v, bool in_stop)
49 struct bpf_iter__bpf_map ctx;
50 struct bpf_iter_meta meta;
51 struct bpf_prog *prog;
52 int ret = 0;
54 ctx.meta = &meta;
55 ctx.map = v;
56 meta.seq = seq;
57 prog = bpf_iter_get_info(&meta, in_stop);
58 if (prog)
59 ret = bpf_iter_run_prog(prog, &ctx);
61 return ret;
64 static int bpf_map_seq_show(struct seq_file *seq, void *v)
66 return __bpf_map_seq_show(seq, v, false);
69 static void bpf_map_seq_stop(struct seq_file *seq, void *v)
71 if (!v)
72 (void)__bpf_map_seq_show(seq, v, true);
73 else
74 bpf_map_put((struct bpf_map *)v);
77 static const struct seq_operations bpf_map_seq_ops = {
78 .start = bpf_map_seq_start,
79 .next = bpf_map_seq_next,
80 .stop = bpf_map_seq_stop,
81 .show = bpf_map_seq_show,
84 static const struct bpf_iter_reg bpf_map_reg_info = {
85 .target = "bpf_map",
86 .seq_ops = &bpf_map_seq_ops,
87 .init_seq_private = NULL,
88 .fini_seq_private = NULL,
89 .seq_priv_size = sizeof(struct bpf_iter_seq_map_info),
90 .ctx_arg_info_size = 1,
91 .ctx_arg_info = {
92 { offsetof(struct bpf_iter__bpf_map, map),
93 PTR_TO_BTF_ID_OR_NULL },
97 static int __init bpf_map_iter_init(void)
99 return bpf_iter_reg_target(&bpf_map_reg_info);
102 late_initcall(bpf_map_iter_init);