aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-10-15 12:20:54 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-16 13:25:54 -0400
commita9556040119a63d06fd5238d47f5b683fba4178b (patch)
tree8aafbcdd5f060b193f5cf5308195ecab6df4e9dc /drivers
parent7bdce71822f471433dd3014692e9096996c7b5f0 (diff)
USB: cyberjack: fix port-data memory leak
Fix port-data memory leak by replacing attach and release with port_probe and port_remove. Since commit 0998d0631001288 (device-core: Ensure drvdata = NULL when no driver is bound) the port private data is no longer freed at release as it is no longer accessible. Note that the write waitqueue was initialised but never used. Compile-only tested. Cc: <stable@vger.kernel.org> Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/serial/cyberjack.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 2a7aecc72237..4ee77dcbe690 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -55,9 +55,9 @@
55#define CYBERJACK_PRODUCT_ID 0x0100 55#define CYBERJACK_PRODUCT_ID 0x0100
56 56
57/* Function prototypes */ 57/* Function prototypes */
58static int cyberjack_startup(struct usb_serial *serial);
59static void cyberjack_disconnect(struct usb_serial *serial); 58static void cyberjack_disconnect(struct usb_serial *serial);
60static void cyberjack_release(struct usb_serial *serial); 59static int cyberjack_port_probe(struct usb_serial_port *port);
60static int cyberjack_port_remove(struct usb_serial_port *port);
61static int cyberjack_open(struct tty_struct *tty, 61static int cyberjack_open(struct tty_struct *tty,
62 struct usb_serial_port *port); 62 struct usb_serial_port *port);
63static void cyberjack_close(struct usb_serial_port *port); 63static void cyberjack_close(struct usb_serial_port *port);
@@ -83,9 +83,9 @@ static struct usb_serial_driver cyberjack_device = {
83 .description = "Reiner SCT Cyberjack USB card reader", 83 .description = "Reiner SCT Cyberjack USB card reader",
84 .id_table = id_table, 84 .id_table = id_table,
85 .num_ports = 1, 85 .num_ports = 1,
86 .attach = cyberjack_startup,
87 .disconnect = cyberjack_disconnect, 86 .disconnect = cyberjack_disconnect,
88 .release = cyberjack_release, 87 .port_probe = cyberjack_port_probe,
88 .port_remove = cyberjack_port_remove,
89 .open = cyberjack_open, 89 .open = cyberjack_open,
90 .close = cyberjack_close, 90 .close = cyberjack_close,
91 .write = cyberjack_write, 91 .write = cyberjack_write,
@@ -107,56 +107,45 @@ struct cyberjack_private {
107 short wrsent; /* Data already sent */ 107 short wrsent; /* Data already sent */
108}; 108};
109 109
110/* do some startup allocations not currently performed by usb_serial_probe() */ 110static int cyberjack_port_probe(struct usb_serial_port *port)
111static int cyberjack_startup(struct usb_serial *serial)
112{ 111{
113 struct cyberjack_private *priv; 112 struct cyberjack_private *priv;
114 int i; 113 int result;
115 114
116 /* allocate the private data structure */
117 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL); 115 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
118 if (!priv) 116 if (!priv)
119 return -ENOMEM; 117 return -ENOMEM;
120 118
121 /* set initial values */
122 spin_lock_init(&priv->lock); 119 spin_lock_init(&priv->lock);
123 priv->rdtodo = 0; 120 priv->rdtodo = 0;
124 priv->wrfilled = 0; 121 priv->wrfilled = 0;
125 priv->wrsent = 0; 122 priv->wrsent = 0;
126 usb_set_serial_port_data(serial->port[0], priv);
127 123
128 init_waitqueue_head(&serial->port[0]->write_wait); 124 usb_set_serial_port_data(port, priv);
129 125
130 for (i = 0; i < serial->num_ports; ++i) { 126 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
131 int result; 127 if (result)
132 result = usb_submit_urb(serial->port[i]->interrupt_in_urb, 128 dev_err(&port->dev, "usb_submit_urb(read int) failed\n");
133 GFP_KERNEL);
134 if (result)
135 dev_err(&serial->dev->dev,
136 "usb_submit_urb(read int) failed\n");
137 dev_dbg(&serial->dev->dev, "%s - usb_submit_urb(int urb)\n",
138 __func__);
139 }
140 129
141 return 0; 130 return 0;
142} 131}
143 132
144static void cyberjack_disconnect(struct usb_serial *serial) 133static int cyberjack_port_remove(struct usb_serial_port *port)
145{ 134{
146 int i; 135 struct cyberjack_private *priv;
147 136
148 for (i = 0; i < serial->num_ports; ++i) 137 priv = usb_get_serial_port_data(port);
149 usb_kill_urb(serial->port[i]->interrupt_in_urb); 138 kfree(priv);
139
140 return 0;
150} 141}
151 142
152static void cyberjack_release(struct usb_serial *serial) 143static void cyberjack_disconnect(struct usb_serial *serial)
153{ 144{
154 int i; 145 int i;
155 146
156 for (i = 0; i < serial->num_ports; ++i) { 147 for (i = 0; i < serial->num_ports; ++i)
157 /* My special items, the standard routines free my urbs */ 148 usb_kill_urb(serial->port[i]->interrupt_in_urb);
158 kfree(usb_get_serial_port_data(serial->port[i]));
159 }
160} 149}
161 150
162static int cyberjack_open(struct tty_struct *tty, 151static int cyberjack_open(struct tty_struct *tty,