summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/legacy/printer.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/legacy/printer.c')
-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)