* [PATCH] usb: typec: avoid format-overflow warning
@ 2018-07-06 13:28 Arnd Bergmann
2018-07-09 8:27 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2018-07-06 13:28 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Arnd Bergmann, linux-usb, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: typec: avoid format-overflow warning
2018-07-06 13:28 [PATCH] usb: typec: avoid format-overflow warning Arnd Bergmann
@ 2018-07-09 8:27 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2018-07-09 8:27 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel
On Fri, Jul 06, 2018 at 03:28:32PM +0200, Arnd Bergmann wrote:
> 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>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> 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];
>
Thanks,
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-09 8:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06 13:28 [PATCH] usb: typec: avoid format-overflow warning Arnd Bergmann
2018-07-09 8:27 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).