From: Arnd Bergmann <arnd@arndb.de>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: typec: avoid format-overflow warning
Date: Fri, 6 Jul 2018 15:28:32 +0200 [thread overview]
Message-ID: <20180706132843.51206-1-arnd@arndb.de> (raw)
gcc-8 points out that the fix-byte buffer might be too small if
desc->mode is a three-digit number:
drivers/usb/typec/class.c: In function 'typec_register_altmode':
drivers/usb/typec/class.c:502:32: error: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Werror=format-overflow=]
sprintf(alt->group_name, "mode%d", desc->mode);
^~
drivers/usb/typec/class.c:502:27: note: directive argument in the range [0, 255]
sprintf(alt->group_name, "mode%d", desc->mode);
^~~~~~~~
drivers/usb/typec/class.c:502:2: note: 'sprintf' output between 6 and 8 bytes into a destination of size 6
sprintf(alt->group_name, "mode%d", desc->mode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I assume this cannot happen in practice, but we can simply make the
string long enough to avoid the warning. This uses the two padding
bytes that already exist after the string.
Fixes: 4ab8c18d4d67 ("usb: typec: Register a device for every mode")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/usb/typec/bus.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/typec/bus.h b/drivers/usb/typec/bus.h
index 62aaf8b56bde..db40e61d8b72 100644
--- a/drivers/usb/typec/bus.h
+++ b/drivers/usb/typec/bus.h
@@ -16,7 +16,7 @@ struct altmode {
enum typec_port_data roles;
struct attribute *attrs[5];
- char group_name[6];
+ char group_name[8];
struct attribute_group group;
const struct attribute_group *groups[2];
--
2.9.0
next reply other threads:[~2018-07-06 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-06 13:28 Arnd Bergmann [this message]
2018-07-09 8:27 ` Heikki Krogerus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180706132843.51206-1-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome