return sum;
}
-static __noinline void fill(struct bpf_iter_num *it, int *arr, __u32 n, int mul)
+#define ARR_SZ 16
+
+static __noinline void fill(struct bpf_iter_num *it, int *arr, int mul)
{
- int *t, i;
+ int *t;
+ __u64 i;
while ((t = bpf_iter_num_next(it))) {
i = *t;
- if (i >= n)
+ if (i >= ARR_SZ)
break;
arr[i] = i * mul;
}
}
-static __noinline int sum(struct bpf_iter_num *it, int *arr, __u32 n)
+static __noinline int sum(struct bpf_iter_num *it, int *arr)
{
- int *t, i, sum = 0;;
+ int *t, sum = 0;;
+ __u64 i;
while ((t = bpf_iter_num_next(it))) {
i = *t;
- if (i >= n)
+ if (i >= ARR_SZ)
break;
sum += arr[i];
}
__success
int iter_pass_iter_ptr_to_subprog(const void *ctx)
{
- int arr1[16], arr2[32];
+ int arr1[ARR_SZ], arr2[ARR_SZ];
struct bpf_iter_num it;
int n, sum1, sum2;
/* fill arr1 */
n = ARRAY_SIZE(arr1);
bpf_iter_num_new(&it, 0, n);
- fill(&it, arr1, n, 2);
+ fill(&it, arr1, 2);
bpf_iter_num_destroy(&it);
/* fill arr2 */
n = ARRAY_SIZE(arr2);
bpf_iter_num_new(&it, 0, n);
- fill(&it, arr2, n, 10);
+ fill(&it, arr2, 10);
bpf_iter_num_destroy(&it);
/* sum arr1 */
n = ARRAY_SIZE(arr1);
bpf_iter_num_new(&it, 0, n);
- sum1 = sum(&it, arr1, n);
+ sum1 = sum(&it, arr1);
bpf_iter_num_destroy(&it);
/* sum arr2 */
n = ARRAY_SIZE(arr2);
bpf_iter_num_new(&it, 0, n);
- sum2 = sum(&it, arr2, n);
+ sum2 = sum(&it, arr2);
bpf_iter_num_destroy(&it);
bpf_printk("sum1=%d, sum2=%d", sum1, sum2);