aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/rfcomm
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2014-02-09 20:59:19 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-02-14 16:39:31 -0500
commitf355095756c2a0b77a5b0aa0384c0c09d9735252 (patch)
tree0398680c23156f609f1a95d10430b37c2b193fe0 /net/bluetooth/rfcomm
parent033ace99c444daa4141b84419f670513ce637b77 (diff)
Bluetooth: Refactor rfcomm_dev_add()
Move rfcomm_dev allocation and initialization into new function, __rfcomm_dev_add(), to simplify resource release in error handling. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Tested-By: Alexander Holler <holler@ahsoftware.de> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/rfcomm')
-rw-r--r--net/bluetooth/rfcomm/tty.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index ef2769553dab..0537a0501595 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -208,17 +208,16 @@ static ssize_t show_channel(struct device *tty_dev, struct device_attribute *att
208static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); 208static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
209static DEVICE_ATTR(channel, S_IRUGO, show_channel, NULL); 209static DEVICE_ATTR(channel, S_IRUGO, show_channel, NULL);
210 210
211static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) 211static struct rfcomm_dev *__rfcomm_dev_add(struct rfcomm_dev_req *req,
212 struct rfcomm_dlc *dlc)
212{ 213{
213 struct rfcomm_dev *dev, *entry; 214 struct rfcomm_dev *dev, *entry;
214 struct list_head *head = &rfcomm_dev_list; 215 struct list_head *head = &rfcomm_dev_list;
215 int err = 0; 216 int err = 0;
216 217
217 BT_DBG("id %d channel %d", req->dev_id, req->channel);
218
219 dev = kzalloc(sizeof(struct rfcomm_dev), GFP_KERNEL); 218 dev = kzalloc(sizeof(struct rfcomm_dev), GFP_KERNEL);
220 if (!dev) 219 if (!dev)
221 return -ENOMEM; 220 return ERR_PTR(-ENOMEM);
222 221
223 spin_lock(&rfcomm_dev_lock); 222 spin_lock(&rfcomm_dev_lock);
224 223
@@ -301,22 +300,37 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
301 holds reference to this module. */ 300 holds reference to this module. */
302 __module_get(THIS_MODULE); 301 __module_get(THIS_MODULE);
303 302
303 spin_unlock(&rfcomm_dev_lock);
304 return dev;
305
304out: 306out:
305 spin_unlock(&rfcomm_dev_lock); 307 spin_unlock(&rfcomm_dev_lock);
308 kfree(dev);
309 return ERR_PTR(err);
310}
306 311
307 if (err < 0) 312static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
308 goto free; 313{
314 struct rfcomm_dev *dev;
315 struct device *tty;
316
317 BT_DBG("id %d channel %d", req->dev_id, req->channel);
309 318
310 dev->tty_dev = tty_port_register_device(&dev->port, rfcomm_tty_driver, 319 dev = __rfcomm_dev_add(req, dlc);
320 if (IS_ERR(dev))
321 return PTR_ERR(dev);
322
323 tty = tty_port_register_device(&dev->port, rfcomm_tty_driver,
311 dev->id, NULL); 324 dev->id, NULL);
312 if (IS_ERR(dev->tty_dev)) { 325 if (IS_ERR(tty)) {
313 err = PTR_ERR(dev->tty_dev);
314 spin_lock(&rfcomm_dev_lock); 326 spin_lock(&rfcomm_dev_lock);
315 list_del(&dev->list); 327 list_del(&dev->list);
316 spin_unlock(&rfcomm_dev_lock); 328 spin_unlock(&rfcomm_dev_lock);
317 goto free; 329 kfree(dev);
330 return PTR_ERR(tty);
318 } 331 }
319 332
333 dev->tty_dev = tty;
320 rfcomm_reparent_device(dev); 334 rfcomm_reparent_device(dev);
321 dev_set_drvdata(dev->tty_dev, dev); 335 dev_set_drvdata(dev->tty_dev, dev);
322 336
@@ -327,10 +341,6 @@ out:
327 BT_ERR("Failed to create channel attribute"); 341 BT_ERR("Failed to create channel attribute");
328 342
329 return dev->id; 343 return dev->id;
330
331free:
332 kfree(dev);
333 return err;
334} 344}
335 345
336/* ---- Send buffer ---- */ 346/* ---- Send buffer ---- */