Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82c4c3b7 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'fix-printf'



Quentin Monnet says:

====================
Because the "__printf()" attributes were used only where the functions are
implemented, and not in header files, the checks have not been enforced on
all the calls to printf()-like functions, and a number of errors slipped in
bpftool over time.

This set cleans up such errors, and then moves the "__printf()" attributes
to header files, so that the checks are performed at all locations.
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents dadb81d0 8918dc42
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -449,7 +449,7 @@ static int do_dump(int argc, char **argv)

		btf_id = strtoul(*argv, &endptr, 0);
		if (*endptr) {
			p_err("can't parse %s as ID", **argv);
			p_err("can't parse %s as ID", *argv);
			return -1;
		}
		NEXT_ARG();
+4 −4
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ static void btf_dumper_ptr(const void *data, json_writer_t *jw,
			   bool is_plain_text)
{
	if (is_plain_text)
		jsonw_printf(jw, "%p", *(unsigned long *)data);
		jsonw_printf(jw, "%p", data);
	else
		jsonw_printf(jw, "%u", *(unsigned long *)data);
		jsonw_printf(jw, "%lu", *(unsigned long *)data);
}

static int btf_dumper_modifier(const struct btf_dumper *d, __u32 type_id,
@@ -216,7 +216,7 @@ static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
	switch (BTF_INT_ENCODING(*int_type)) {
	case 0:
		if (BTF_INT_BITS(*int_type) == 64)
			jsonw_printf(jw, "%lu", *(__u64 *)data);
			jsonw_printf(jw, "%llu", *(__u64 *)data);
		else if (BTF_INT_BITS(*int_type) == 32)
			jsonw_printf(jw, "%u", *(__u32 *)data);
		else if (BTF_INT_BITS(*int_type) == 16)
@@ -229,7 +229,7 @@ static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
		break;
	case BTF_INT_SIGNED:
		if (BTF_INT_BITS(*int_type) == 64)
			jsonw_printf(jw, "%ld", *(long long *)data);
			jsonw_printf(jw, "%lld", *(long long *)data);
		else if (BTF_INT_BITS(*int_type) == 32)
			jsonw_printf(jw, "%d", *(int *)data);
		else if (BTF_INT_BITS(*int_type) == 16)
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
#define BPF_FS_MAGIC		0xcafe4a11
#endif

void __printf(1, 2) p_err(const char *fmt, ...)
void p_err(const char *fmt, ...)
{
	va_list ap;

@@ -47,7 +47,7 @@ void __printf(1, 2) p_err(const char *fmt, ...)
	va_end(ap);
}

void __printf(1, 2) p_info(const char *fmt, ...)
void p_info(const char *fmt, ...)
{
	va_list ap;

+2 −4
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
#include <malloc.h>
#include <inttypes.h>
#include <stdint.h>
#include <linux/compiler.h>

#include "json_writer.h"

@@ -153,8 +152,7 @@ void jsonw_name(json_writer_t *self, const char *name)
		putc(' ', self->out);
}

void __printf(2, 0)
jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
{
	jsonw_eor(self);
	putc('"', self->out);
@@ -162,7 +160,7 @@ jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
	putc('"', self->out);
}

void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...)
void jsonw_printf(json_writer_t *self, const char *fmt, ...)
{
	va_list ap;

+4 −2
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <linux/compiler.h>

/* Opaque class structure */
typedef struct json_writer json_writer_t;
@@ -30,8 +31,9 @@ void jsonw_pretty(json_writer_t *self, bool on);
void jsonw_name(json_writer_t *self, const char *name);

/* Add value  */
void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap);
void jsonw_printf(json_writer_t *self, const char *fmt, ...);
void __printf(2, 0) jsonw_vprintf_enquote(json_writer_t *self, const char *fmt,
					  va_list ap);
void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...);
void jsonw_string(json_writer_t *self, const char *value);
void jsonw_bool(json_writer_t *self, bool value);
void jsonw_float(json_writer_t *self, double number);
Loading