summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/legacy
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-12-21 11:48:45 +0300
committerFelipe Balbi <felipe.balbi@linux.intel.com>2017-01-24 12:04:08 +0300
commitfdc01cc286be9d32140631469b7608f3f58c2db3 (patch)
tree4e16bc3744f4e5a4e1751d08a4b5a80f0eab44f4 /drivers/usb/gadget/legacy
parent00b6c62eb74d665caa7e399ffd5da55572b61c50 (diff)
downloadlinux-fdc01cc286be9d32140631469b7608f3f58c2db3.tar.xz
usb: gadget: printer: Remove pnp_string static buffer
pnp string is usually much shorter than 1k so let's stop wasting 1k of memory for its buffer and make it dynamically alocated. This also removes 1k len limitation for pnp_string and adds a new line after string content if required. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Diffstat (limited to 'drivers/usb/gadget/legacy')
-rw-r--r--drivers/usb/gadget/legacy/printer.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index 6f969a86175c..4c9cfff34a03 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -88,8 +88,8 @@ static const struct usb_descriptor_header *otg_desc[2];
static char product_desc [40] = DRIVER_DESC;
static char serial_num [40] = "1";
-static char pnp_string[PNP_STRING_LEN] =
- "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;";
+static char *pnp_string =
+ "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;";
/* static strings, in UTF-8 */
static struct usb_string strings [] = {
@@ -143,23 +143,29 @@ static int printer_do_config(struct usb_configuration *c)
static int printer_bind(struct usb_composite_dev *cdev)
{
struct f_printer_opts *opts;
- int ret, len;
+ int ret;
fi_printer = usb_get_function_instance("printer");
if (IS_ERR(fi_printer))
return PTR_ERR(fi_printer);
- if (iPNPstring)
- strlcpy(&pnp_string[2], iPNPstring, PNP_STRING_LEN - 2);
-
- len = strlen(pnp_string);
- pnp_string[0] = (len >> 8) & 0xFF;
- pnp_string[1] = len & 0xFF;
-
opts = container_of(fi_printer, struct f_printer_opts, func_inst);
opts->minor = 0;
- memcpy(opts->pnp_string, pnp_string, PNP_STRING_LEN);
opts->q_len = QLEN;
+ if (iPNPstring) {
+ opts->pnp_string = kstrdup(iPNPstring, GFP_KERNEL);
+ if (!opts->pnp_string) {
+ ret = -ENOMEM;
+ goto fail_put_func_inst;
+ }
+ opts->pnp_string_allocated = true;
+ /*
+ * we don't free this memory in case of error
+ * as printer cleanup func will do this for us
+ */
+ } else {
+ opts->pnp_string = pnp_string;
+ }
ret = usb_string_ids_tab(cdev, strings);
if (ret < 0)