aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/iuu_phoenix.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/iuu_phoenix.c')
-rw-r--r--drivers/usb/serial/iuu_phoenix.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 01da3ea36e89..cd5533e81de7 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -53,6 +53,8 @@ static int iuu_cardout;
53static bool xmas; 53static bool xmas;
54static int vcc_default = 5; 54static int vcc_default = 5;
55 55
56static int iuu_create_sysfs_attrs(struct usb_serial_port *port);
57static int iuu_remove_sysfs_attrs(struct usb_serial_port *port);
56static void read_rxcmd_callback(struct urb *urb); 58static void read_rxcmd_callback(struct urb *urb);
57 59
58struct iuu_private { 60struct iuu_private {
@@ -72,63 +74,55 @@ struct iuu_private {
72 u32 clk; 74 u32 clk;
73}; 75};
74 76
75 77static int iuu_port_probe(struct usb_serial_port *port)
76static void iuu_free_buf(struct iuu_private *priv)
77{
78 kfree(priv->buf);
79 kfree(priv->writebuf);
80}
81
82static int iuu_alloc_buf(struct usb_serial *serial, struct iuu_private *priv)
83{
84 priv->buf = kzalloc(256, GFP_KERNEL);
85 priv->writebuf = kzalloc(256, GFP_KERNEL);
86 if (!priv->buf || !priv->writebuf) {
87 iuu_free_buf(priv);
88 dev_dbg(&serial->dev->dev, "%s problem allocation buffer\n", __func__);
89 return -ENOMEM;
90 }
91 dev_dbg(&serial->dev->dev, "%s - Privates buffers allocation success\n", __func__);
92 return 0;
93}
94
95static int iuu_startup(struct usb_serial *serial)
96{ 78{
97 struct iuu_private *priv; 79 struct iuu_private *priv;
80 int ret;
98 81
99 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); 82 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
100 dev_dbg(&serial->dev->dev, "%s- priv allocation success\n", __func__);
101 if (!priv) 83 if (!priv)
102 return -ENOMEM; 84 return -ENOMEM;
103 if (iuu_alloc_buf(serial, priv)) { 85
86 priv->buf = kzalloc(256, GFP_KERNEL);
87 if (!priv->buf) {
88 kfree(priv);
89 return -ENOMEM;
90 }
91
92 priv->writebuf = kzalloc(256, GFP_KERNEL);
93 if (!priv->writebuf) {
94 kfree(priv->buf);
104 kfree(priv); 95 kfree(priv);
105 return -ENOMEM; 96 return -ENOMEM;
106 } 97 }
98
107 priv->vcc = vcc_default; 99 priv->vcc = vcc_default;
108 spin_lock_init(&priv->lock); 100 spin_lock_init(&priv->lock);
109 init_waitqueue_head(&priv->delta_msr_wait); 101 init_waitqueue_head(&priv->delta_msr_wait);
110 usb_set_serial_port_data(serial->port[0], priv); 102
103 usb_set_serial_port_data(port, priv);
104
105 ret = iuu_create_sysfs_attrs(port);
106 if (ret) {
107 kfree(priv->writebuf);
108 kfree(priv->buf);
109 kfree(priv);
110 return ret;
111 }
112
111 return 0; 113 return 0;
112} 114}
113 115
114/* Release function */ 116static int iuu_port_remove(struct usb_serial_port *port)
115static void iuu_release(struct usb_serial *serial)
116{ 117{
117 struct usb_serial_port *port = serial->port[0];
118 struct iuu_private *priv = usb_get_serial_port_data(port); 118 struct iuu_private *priv = usb_get_serial_port_data(port);
119 if (!port)
120 return;
121 119
122 if (priv) { 120 iuu_remove_sysfs_attrs(port);
123 iuu_free_buf(priv); 121 kfree(priv->writebuf);
124 dev_dbg(&port->dev, "%s - I will free all\n", __func__); 122 kfree(priv->buf);
125 usb_set_serial_port_data(port, NULL); 123 kfree(priv);
126
127 dev_dbg(&port->dev, "%s - priv is not anymore in port structure\n", __func__);
128 kfree(priv);
129 124
130 dev_dbg(&port->dev, "%s priv is now kfree\n", __func__); 125 return 0;
131 }
132} 126}
133 127
134static int iuu_tiocmset(struct tty_struct *tty, 128static int iuu_tiocmset(struct tty_struct *tty,
@@ -1215,8 +1209,6 @@ static struct usb_serial_driver iuu_device = {
1215 .num_ports = 1, 1209 .num_ports = 1,
1216 .bulk_in_size = 512, 1210 .bulk_in_size = 512,
1217 .bulk_out_size = 512, 1211 .bulk_out_size = 512,
1218 .port_probe = iuu_create_sysfs_attrs,
1219 .port_remove = iuu_remove_sysfs_attrs,
1220 .open = iuu_open, 1212 .open = iuu_open,
1221 .close = iuu_close, 1213 .close = iuu_close,
1222 .write = iuu_uart_write, 1214 .write = iuu_uart_write,
@@ -1225,8 +1217,8 @@ static struct usb_serial_driver iuu_device = {
1225 .tiocmset = iuu_tiocmset, 1217 .tiocmset = iuu_tiocmset,
1226 .set_termios = iuu_set_termios, 1218 .set_termios = iuu_set_termios,
1227 .init_termios = iuu_init_termios, 1219 .init_termios = iuu_init_termios,
1228 .attach = iuu_startup, 1220 .port_probe = iuu_port_probe,
1229 .release = iuu_release, 1221 .port_remove = iuu_port_remove,
1230}; 1222};
1231 1223
1232static struct usb_serial_driver * const serial_drivers[] = { 1224static struct usb_serial_driver * const serial_drivers[] = {