summaryrefslogtreecommitdiffstats
path: root/drivers/rapidio
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2017-03-17 14:48:20 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-21 01:44:33 -0400
commitdbef390d2eb0a7b0a6be21381a326d4e13953aba (patch)
tree959cf65e5592d2d397f92eef4141f70bf200860f /drivers/rapidio
parent493cfaeaa0c9bc0c79ce5751193d49fdac9aaaec (diff)
rapidio: utilize new cdev_device_add helper function
This driver did not originally set kobj.parent so it likely had potential a use after free bug which this patch fixes. We convert from device_register to device_initialize/cdev_device_add. While we are at it we use put_device instead of kfree (as recommended by the device_initialize documentation). We also remove an unnecessary extra get_device from the code. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/rapidio')
-rw-r--r--drivers/rapidio/devices/rio_mport_cdev.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 50b617af81bd..5beb0c361076 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -2444,31 +2444,25 @@ static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
2444 mutex_init(&md->buf_mutex); 2444 mutex_init(&md->buf_mutex);
2445 mutex_init(&md->file_mutex); 2445 mutex_init(&md->file_mutex);
2446 INIT_LIST_HEAD(&md->file_list); 2446 INIT_LIST_HEAD(&md->file_list);
2447 cdev_init(&md->cdev, &mport_fops);
2448 md->cdev.owner = THIS_MODULE;
2449 ret = cdev_add(&md->cdev, MKDEV(MAJOR(dev_number), mport->id), 1);
2450 if (ret < 0) {
2451 kfree(md);
2452 rmcd_error("Unable to register a device, err=%d", ret);
2453 return NULL;
2454 }
2455 2447
2456 md->dev.devt = md->cdev.dev; 2448 device_initialize(&md->dev);
2449 md->dev.devt = MKDEV(MAJOR(dev_number), mport->id);
2457 md->dev.class = dev_class; 2450 md->dev.class = dev_class;
2458 md->dev.parent = &mport->dev; 2451 md->dev.parent = &mport->dev;
2459 md->dev.release = mport_device_release; 2452 md->dev.release = mport_device_release;
2460 dev_set_name(&md->dev, DEV_NAME "%d", mport->id); 2453 dev_set_name(&md->dev, DEV_NAME "%d", mport->id);
2461 atomic_set(&md->active, 1); 2454 atomic_set(&md->active, 1);
2462 2455
2463 ret = device_register(&md->dev); 2456 cdev_init(&md->cdev, &mport_fops);
2457 md->cdev.owner = THIS_MODULE;
2458
2459 ret = cdev_device_add(&md->cdev, &md->dev);
2464 if (ret) { 2460 if (ret) {
2465 rmcd_error("Failed to register mport %d (err=%d)", 2461 rmcd_error("Failed to register mport %d (err=%d)",
2466 mport->id, ret); 2462 mport->id, ret);
2467 goto err_cdev; 2463 goto err_cdev;
2468 } 2464 }
2469 2465
2470 get_device(&md->dev);
2471
2472 INIT_LIST_HEAD(&md->doorbells); 2466 INIT_LIST_HEAD(&md->doorbells);
2473 spin_lock_init(&md->db_lock); 2467 spin_lock_init(&md->db_lock);
2474 INIT_LIST_HEAD(&md->portwrites); 2468 INIT_LIST_HEAD(&md->portwrites);
@@ -2513,8 +2507,7 @@ static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
2513 return md; 2507 return md;
2514 2508
2515err_cdev: 2509err_cdev:
2516 cdev_del(&md->cdev); 2510 put_device(&md->dev);
2517 kfree(md);
2518 return NULL; 2511 return NULL;
2519} 2512}
2520 2513
@@ -2578,7 +2571,7 @@ static void mport_cdev_remove(struct mport_dev *md)
2578 atomic_set(&md->active, 0); 2571 atomic_set(&md->active, 0);
2579 mport_cdev_terminate_dma(md); 2572 mport_cdev_terminate_dma(md);
2580 rio_del_mport_pw_handler(md->mport, md, rio_mport_pw_handler); 2573 rio_del_mport_pw_handler(md->mport, md, rio_mport_pw_handler);
2581 cdev_del(&(md->cdev)); 2574 cdev_device_del(&md->cdev, &md->dev);
2582 mport_cdev_kill_fasync(md); 2575 mport_cdev_kill_fasync(md);
2583 2576
2584 flush_workqueue(dma_wq); 2577 flush_workqueue(dma_wq);
@@ -2603,7 +2596,6 @@ static void mport_cdev_remove(struct mport_dev *md)
2603 2596
2604 rio_release_inb_dbell(md->mport, 0, 0x0fff); 2597 rio_release_inb_dbell(md->mport, 0, 0x0fff);
2605 2598
2606 device_unregister(&md->dev);
2607 put_device(&md->dev); 2599 put_device(&md->dev);
2608} 2600}
2609 2601