Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

device-dax: utilize new cdev_device_add helper function

Replace the open coded registration of the cdev and dev with the
new device_add_cdev() helper. The helper replaces a common pattern by
taking the proper reference against the parent device and adding both
the cdev and the device.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Logan Gunthorpe and committed by
Greg Kroah-Hartman
92a3fa07 ed01e50a

+5 -13
+5 -13
drivers/dax/dax.c
··· 677 677 678 678 static void kill_dax_dev(struct dax_dev *dax_dev) 679 679 { 680 - struct cdev *cdev = &dax_dev->cdev; 681 - 682 680 /* 683 681 * Note, rcu is not protecting the liveness of dax_dev, rcu is 684 682 * ensuring that any fault handlers that might have seen ··· 687 689 dax_dev->alive = false; 688 690 synchronize_rcu(); 689 691 unmap_mapping_range(dax_dev->inode->i_mapping, 0, 0, 1); 690 - cdev_del(cdev); 691 692 } 692 693 693 694 static void unregister_dax_dev(void *dev) ··· 696 699 dev_dbg(dev, "%s\n", __func__); 697 700 698 701 kill_dax_dev(dax_dev); 699 - device_unregister(dev); 702 + cdev_device_del(&dax_dev->cdev, dev); 703 + put_device(dev); 700 704 } 701 705 702 706 struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region, ··· 748 750 goto err_inode; 749 751 } 750 752 751 - /* device_initialize() so cdev can reference kobj parent */ 753 + /* from here on we're committed to teardown via dax_dev_release() */ 752 754 device_initialize(dev); 753 755 754 756 cdev = &dax_dev->cdev; 755 757 cdev_init(cdev, &dax_fops); 756 758 cdev->owner = parent->driver->owner; 757 - cdev->kobj.parent = &dev->kobj; 758 - rc = cdev_add(&dax_dev->cdev, dev_t, 1); 759 - if (rc) 760 - goto err_cdev; 761 759 762 - /* from here on we're committed to teardown via dax_dev_release() */ 763 760 dax_dev->num_resources = count; 764 761 dax_dev->alive = true; 765 762 dax_dev->region = dax_region; ··· 766 773 dev->groups = dax_attribute_groups; 767 774 dev->release = dax_dev_release; 768 775 dev_set_name(dev, "dax%d.%d", dax_region->id, dax_dev->id); 769 - rc = device_add(dev); 776 + 777 + rc = cdev_device_add(cdev, dev); 770 778 if (rc) { 771 779 kill_dax_dev(dax_dev); 772 780 put_device(dev); ··· 780 786 781 787 return dax_dev; 782 788 783 - err_cdev: 784 - iput(dax_dev->inode); 785 789 err_inode: 786 790 ida_simple_remove(&dax_minor_ida, minor); 787 791 err_minor: