Subject: Re: [PATCH v2 bpf-next 2/3] libbpf: make global data internal arrays mmap()-able, if possible

From: Jakub Kicinski <[email-masked]>
Date: Mon, 11 Nov 2019 10:40:57 -0800

On Sat, 9 Nov 2019 00:06:31 -0800, Andrii Nakryiko wrote:
> +static int bpf_object__probe_array_mmap(struct bpf_object *obj)
> +{
> +	struct bpf_create_map_attr attr = {
> +		.map_type = BPF_MAP_TYPE_ARRAY,
> +		.map_flags = BPF_F_MMAPABLE,
> +		.key_size = sizeof(int),
> +		.value_size = sizeof(int),
> +		.max_entries = 1,
> +	};
> +	int fd = bpf_create_map_xattr(&attr);
> +
> +	if (fd >= 0) {

The point of the empty line between variable declarations and code in
the Linux coding style is to provide a visual separation between
variables and code.

If you call a complex function in variable init and then check for
errors in the code that really breaks that principle.

> +		obj->caps.array_mmap = 1;
> +		close(fd);
> +		return 1;
> +	}
> +
> +	return 0;
> +}