From 05bc5e9e03662c395be3883afd6b7033cef67b20 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 9 May 2019 14:37:42 +0200 Subject: [PATCH] tools/csr_usb: Fix compilation failure GCC's "format-nonliteral" security check is enabled as an error in recent versions of Fedora. Given the limited formats, pass a boolean to switch between the 2 different formats. tools/csr_usb.c: In function 'read_value': tools/csr_usb.c:82:2: error: format not a string literal, argument types not checked [-Werror=format-nonliteral] n = fscanf(file, format, &value); ^ Change-Id: Ia0c8d0c4bb77d472afa39a148aff41f220818571 Signed-off-by: himanshu --- tools/csr_usb.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/csr_usb.c b/tools/csr_usb.c index a1d7324..f1ffb00 100755 --- a/tools/csr_usb.c +++ b/tools/csr_usb.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +68,7 @@ struct usbfs_bulktransfer { #define USBFS_IOCTL_CLAIMINTF _IOR('U', 15, unsigned int) #define USBFS_IOCTL_RELEASEINTF _IOR('U', 16, unsigned int) -static int read_value(const char *name, const char *attr, const char *format) +static int read_value(const char *name, const char *attr, bool hex_number) { char path[PATH_MAX]; FILE *file; @@ -79,7 +80,7 @@ static int read_value(const char *name, const char *attr, const char *format) if (!file) return -1; - n = fscanf(file, format, &value); + n = fscanf(file, hex_number ? "%d" : "%04x", &value); if (n != 1) { fclose(file); return -1; @@ -89,26 +90,29 @@ static int read_value(const char *name, const char *attr, const char *format) return value; } +#define read_hex_value(name, file) read_value((name), (file), true) +#define read_num_value(name, file) read_value((name), (file), false) + static char *check_device(const char *name) { char path[PATH_MAX]; int busnum, devnum, vendor, product; - busnum = read_value(name, "busnum", "%d"); + busnum = read_num_value(name, "busnum"); if (busnum < 0) return NULL; - devnum = read_value(name, "devnum", "%d"); + devnum = read_num_value(name, "devnum"); if (devnum < 0) return NULL; snprintf(path, sizeof(path), "/dev/bus/usb/%03u/%03u", busnum, devnum); - vendor = read_value(name, "idVendor", "%04x"); + vendor = read_hex_value(name, "idVendor"); if (vendor < 0) return NULL; - product = read_value(name, "idProduct", "%04x"); + product = read_hex_value(name, "idProduct"); if (product < 0) return NULL; -- 2.7.4