aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/pl2303.c
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2013-12-29 13:23:01 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-01-03 15:31:47 -0500
commit362eb02603be7bb835c47f2cf585954a5080449d (patch)
treeaf97e6a7a5bc5c9edaed645b640ea337ab78c558 /drivers/usb/serial/pl2303.c
parentccfe8188a321f4039a7e52c8336bb4ff3ca35139 (diff)
USB: pl2303: add error handling to vendor read and write functions
Add error handling and clean up vendor read and write functions. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial/pl2303.c')
-rw-r--r--drivers/usb/serial/pl2303.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index a44154ac335c..4058ceec884d 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -140,35 +140,46 @@ struct pl2303_private {
140 u8 line_settings[7]; 140 u8 line_settings[7];
141}; 141};
142 142
143static int pl2303_vendor_read(u16 value, u16 index, 143static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
144 struct usb_serial *serial, unsigned char *buf) 144 unsigned char buf[1])
145{ 145{
146 struct device *dev = &serial->interface->dev;
146 int res; 147 int res;
147 148
148 res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 149 res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
149 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, 150 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
150 value, index, buf, 1, 100); 151 value, 0, buf, 1, 100);
152 if (res != 1) {
153 dev_err(dev, "%s - failed to read [%04x]: %d\n", __func__,
154 value, res);
155 if (res >= 0)
156 res = -EIO;
157
158 return res;
159 }
151 160
152 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", 161 dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, buf[0]);
153 VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index,
154 res, buf[0]);
155 162
156 return res; 163 return 0;
157} 164}
158 165
159static int pl2303_vendor_write(u16 value, u16 index, struct usb_serial *serial) 166static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
160{ 167{
168 struct device *dev = &serial->interface->dev;
161 int res; 169 int res;
162 170
171 dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);
172
163 res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 173 res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
164 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, 174 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
165 value, index, NULL, 0, 100); 175 value, index, NULL, 0, 100);
176 if (res) {
177 dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
178 value, res);
179 return res;
180 }
166 181
167 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d\n", 182 return 0;
168 VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index,
169 res);
170
171 return res;
172} 183}
173 184
174static int pl2303_startup(struct usb_serial *serial) 185static int pl2303_startup(struct usb_serial *serial)
@@ -181,7 +192,7 @@ static int pl2303_startup(struct usb_serial *serial)
181 if (!spriv) 192 if (!spriv)
182 return -ENOMEM; 193 return -ENOMEM;
183 194
184 buf = kmalloc(10, GFP_KERNEL); 195 buf = kmalloc(1, GFP_KERNEL);
185 if (!buf) { 196 if (!buf) {
186 kfree(spriv); 197 kfree(spriv);
187 return -ENOMEM; 198 return -ENOMEM;
@@ -200,20 +211,20 @@ static int pl2303_startup(struct usb_serial *serial)
200 spriv->type = type; 211 spriv->type = type;
201 usb_set_serial_data(serial, spriv); 212 usb_set_serial_data(serial, spriv);
202 213
203 pl2303_vendor_read(0x8484, 0, serial, buf); 214 pl2303_vendor_read(serial, 0x8484, buf);
204 pl2303_vendor_write(0x0404, 0, serial); 215 pl2303_vendor_write(serial, 0x0404, 0);
205 pl2303_vendor_read(0x8484, 0, serial, buf); 216 pl2303_vendor_read(serial, 0x8484, buf);
206 pl2303_vendor_read(0x8383, 0, serial, buf); 217 pl2303_vendor_read(serial, 0x8383, buf);
207 pl2303_vendor_read(0x8484, 0, serial, buf); 218 pl2303_vendor_read(serial, 0x8484, buf);
208 pl2303_vendor_write(0x0404, 1, serial); 219 pl2303_vendor_write(serial, 0x0404, 1);
209 pl2303_vendor_read(0x8484, 0, serial, buf); 220 pl2303_vendor_read(serial, 0x8484, buf);
210 pl2303_vendor_read(0x8383, 0, serial, buf); 221 pl2303_vendor_read(serial, 0x8383, buf);
211 pl2303_vendor_write(0, 1, serial); 222 pl2303_vendor_write(serial, 0, 1);
212 pl2303_vendor_write(1, 0, serial); 223 pl2303_vendor_write(serial, 1, 0);
213 if (type == HX) 224 if (type == HX)
214 pl2303_vendor_write(2, 0x44, serial); 225 pl2303_vendor_write(serial, 2, 0x44);
215 else 226 else
216 pl2303_vendor_write(2, 0x24, serial); 227 pl2303_vendor_write(serial, 2, 0x24);
217 228
218 kfree(buf); 229 kfree(buf);
219 230
@@ -473,11 +484,11 @@ static void pl2303_set_termios(struct tty_struct *tty,
473 484
474 if (C_CRTSCTS(tty)) { 485 if (C_CRTSCTS(tty)) {
475 if (spriv->type == HX) 486 if (spriv->type == HX)
476 pl2303_vendor_write(0x0, 0x61, serial); 487 pl2303_vendor_write(serial, 0x0, 0x61);
477 else 488 else
478 pl2303_vendor_write(0x0, 0x41, serial); 489 pl2303_vendor_write(serial, 0x0, 0x41);
479 } else { 490 } else {
480 pl2303_vendor_write(0x0, 0x0, serial); 491 pl2303_vendor_write(serial, 0x0, 0x0);
481 } 492 }
482 493
483 kfree(buf); 494 kfree(buf);
@@ -517,8 +528,8 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
517 usb_clear_halt(serial->dev, port->read_urb->pipe); 528 usb_clear_halt(serial->dev, port->read_urb->pipe);
518 } else { 529 } else {
519 /* reset upstream data pipes */ 530 /* reset upstream data pipes */
520 pl2303_vendor_write(8, 0, serial); 531 pl2303_vendor_write(serial, 8, 0);
521 pl2303_vendor_write(9, 0, serial); 532 pl2303_vendor_write(serial, 9, 0);
522 } 533 }
523 534
524 /* Setup termios */ 535 /* Setup termios */