staging: greybus: loopback_test: fix potential path truncations

Newer GCC warns about possible truncations of two generated path names as
we're concatenating the configurable sysfs and debugfs path prefixes
with a filename and placing the results in buffers of the same size as
the maximum length of the prefixes.

snprintf(d->name, MAX_STR_LEN, "gb_loopback%u", dev_id);

snprintf(d->sysfs_entry, MAX_SYSFS_PATH, "%s%s/",
t->sysfs_prefix, d->name);

snprintf(d->debugfs_entry, MAX_SYSFS_PATH, "%sraw_latency_%s",
t->debugfs_prefix, d->name);

Fix this by separating the maximum path length from the maximum prefix
length and reducing the latter enough to fit the generated strings.

Note that we also need to reduce the device-name buffer size as GCC
isn't smart enough to figure out that we ever only used MAX_STR_LEN
bytes of it.

Fixes: 6b0658f68786 ("greybus: tools: Add tools directory to greybus repo and add loopback")
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20200312110151.22028-4-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Johan Hovold and committed by Greg Kroah-Hartman ae62cf5e f1602383

Changed files
+8 -7
drivers
staging
greybus
+8 -7
drivers/staging/greybus/tools/loopback_test.c
··· 19 19 #include <signal.h> 20 20 21 21 #define MAX_NUM_DEVICES 10 22 + #define MAX_SYSFS_PREFIX 0x80 22 23 #define MAX_SYSFS_PATH 0x200 23 24 #define CSV_MAX_LINE 0x1000 24 25 #define SYSFS_MAX_INT 0x20 ··· 68 67 }; 69 68 70 69 struct loopback_device { 71 - char name[MAX_SYSFS_PATH]; 70 + char name[MAX_STR_LEN]; 72 71 char sysfs_entry[MAX_SYSFS_PATH]; 73 72 char debugfs_entry[MAX_SYSFS_PATH]; 74 73 struct loopback_results results; ··· 94 93 int stop_all; 95 94 int poll_count; 96 95 char test_name[MAX_STR_LEN]; 97 - char sysfs_prefix[MAX_SYSFS_PATH]; 98 - char debugfs_prefix[MAX_SYSFS_PATH]; 96 + char sysfs_prefix[MAX_SYSFS_PREFIX]; 97 + char debugfs_prefix[MAX_SYSFS_PREFIX]; 99 98 struct timespec poll_timeout; 100 99 struct loopback_device devices[MAX_NUM_DEVICES]; 101 100 struct loopback_results aggregate_results; ··· 908 907 t.iteration_max = atoi(optarg); 909 908 break; 910 909 case 'S': 911 - snprintf(t.sysfs_prefix, MAX_SYSFS_PATH, "%s", optarg); 910 + snprintf(t.sysfs_prefix, MAX_SYSFS_PREFIX, "%s", optarg); 912 911 break; 913 912 case 'D': 914 - snprintf(t.debugfs_prefix, MAX_SYSFS_PATH, "%s", optarg); 913 + snprintf(t.debugfs_prefix, MAX_SYSFS_PREFIX, "%s", optarg); 915 914 break; 916 915 case 'm': 917 916 t.mask = atol(optarg); ··· 962 961 } 963 962 964 963 if (!strcmp(t.sysfs_prefix, "")) 965 - snprintf(t.sysfs_prefix, MAX_SYSFS_PATH, "%s", sysfs_prefix); 964 + snprintf(t.sysfs_prefix, MAX_SYSFS_PREFIX, "%s", sysfs_prefix); 966 965 967 966 if (!strcmp(t.debugfs_prefix, "")) 968 - snprintf(t.debugfs_prefix, MAX_SYSFS_PATH, "%s", debugfs_prefix); 967 + snprintf(t.debugfs_prefix, MAX_SYSFS_PREFIX, "%s", debugfs_prefix); 969 968 970 969 ret = find_loopback_devices(&t); 971 970 if (ret)