alistair23-linux/drivers/usb/typec/bus.h
Arnd Bergmann 8160eac121 usb: typec: avoid format-overflow warning
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: 4ab8c18d4d ("usb: typec: Register a device for every mode")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-06 16:36:19 +02:00

39 lines
925 B
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __USB_TYPEC_ALTMODE_H__
#define __USB_TYPEC_ALTMODE_H__
#include <linux/usb/typec_altmode.h>
#include <linux/usb/typec_mux.h>
struct bus_type;
struct altmode {
unsigned int id;
struct typec_altmode adev;
struct typec_mux *mux;
enum typec_port_data roles;
struct attribute *attrs[5];
char group_name[8];
struct attribute_group group;
const struct attribute_group *groups[2];
struct altmode *partner;
struct altmode *plug[2];
struct blocking_notifier_head nh;
};
#define to_altmode(d) container_of(d, struct altmode, adev)
extern struct bus_type typec_bus;
extern const struct device_type typec_altmode_dev_type;
extern const struct device_type typec_port_dev_type;
#define is_typec_altmode(_dev_) (_dev_->type == &typec_altmode_dev_type)
#define is_typec_port(_dev_) (_dev_->type == &typec_port_dev_type)
#endif /* __USB_TYPEC_ALTMODE_H__ */