Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf()

Annotate guest printf helpers with __printf() so that the compiler will
warn about incorrect formatting at compile time (see git log for how easy
it is to screw up with the formatting).

Suggested-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20231129224916.532431-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+5 -4
+1 -1
tools/testing/selftests/kvm/include/test_util.h
··· 191 191 } 192 192 193 193 int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args); 194 - int guest_snprintf(char *buf, int n, const char *fmt, ...); 194 + __printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...); 195 195 196 196 char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1))); 197 197
+4 -3
tools/testing/selftests/kvm/include/ucall_common.h
··· 34 34 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu); 35 35 36 36 void ucall(uint64_t cmd, int nargs, ...); 37 - void ucall_fmt(uint64_t cmd, const char *fmt, ...); 38 - void ucall_assert(uint64_t cmd, const char *exp, const char *file, 39 - unsigned int line, const char *fmt, ...); 37 + __printf(2, 3) void ucall_fmt(uint64_t cmd, const char *fmt, ...); 38 + __printf(5, 6) void ucall_assert(uint64_t cmd, const char *exp, 39 + const char *file, unsigned int line, 40 + const char *fmt, ...); 40 41 uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); 41 42 void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa); 42 43 int ucall_nr_pages_required(uint64_t page_size);