usb: gadget: f_fs: Fix -Wformat-truncation in proxy endpoint names
PATCH 1/1 usb: gadget: f_fs: Fix -Wformat-truncation in proxy endpoint names
When using the functionfs rw_proxy feature, proxy endpoint names are generated by appending "_rw" to the base endpoint name. The base endpoint name is copied via snprintf into an 8-byte buffer (comp->name). On some architectures (e.g., s390), the compiler flags a -Wformat-truncation warning because %s_rw could potentially overflow if the source string is unexpectedly long.
Fix this by specifying a maximum field width of 4 characters when formatting the endpoint name string. This guarantees that at most 4 characters plus the 3 characters "_rw" (and null terminator) will be written, fitting within the 8-byte limit.
Note that this is purely to address the compiler static analysis. In practice, FFS_MAX_EPS_COUNT is limited to 31, meaning the longest possible base endpoint name is "ep30", and therefore the resulting proxy name, "ep30_rw", is exactly 7 characters.
--- drivers/usb/gadget/function/f_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_fs.c +1 -1
@@ -2441,7 +2441,7 @@ static int ffs_epfiles_create(struct ffs_data *ffs)mutex_init (&comp->mutex);mutex_init (&comp->dmabufs_mutex);INIT_LIST_HEAD (&comp->dmabufs); -snprintf (comp->name,sizeof (comp->name),"%s_rw" , +snprintf (comp->name,sizeof (comp->name),"%.4s_rw" , epfiles[i].name); err =ffs_sb_create_file (ffs->sb, comp->name, comp, &ffs_epfile_operations);
Signature · 1 line
2.55.0.229.g6434b31f56-goog