diff options
Diffstat (limited to 'drivers/fpga/fpga-mgr.c')
| -rw-r--r-- | drivers/fpga/fpga-mgr.c | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index a41b07e37884..c3866816456a 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c | |||
| @@ -558,6 +558,9 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unlock); | |||
| 558 | * @mops: pointer to structure of fpga manager ops | 558 | * @mops: pointer to structure of fpga manager ops |
| 559 | * @priv: fpga manager private data | 559 | * @priv: fpga manager private data |
| 560 | * | 560 | * |
| 561 | * The caller of this function is responsible for freeing the struct with | ||
| 562 | * fpga_mgr_free(). Using devm_fpga_mgr_create() instead is recommended. | ||
| 563 | * | ||
| 561 | * Return: pointer to struct fpga_manager or NULL | 564 | * Return: pointer to struct fpga_manager or NULL |
| 562 | */ | 565 | */ |
| 563 | struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name, | 566 | struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name, |
| @@ -618,8 +621,8 @@ error_kfree: | |||
| 618 | EXPORT_SYMBOL_GPL(fpga_mgr_create); | 621 | EXPORT_SYMBOL_GPL(fpga_mgr_create); |
| 619 | 622 | ||
| 620 | /** | 623 | /** |
| 621 | * fpga_mgr_free - deallocate a FPGA manager | 624 | * fpga_mgr_free - free a FPGA manager created with fpga_mgr_create() |
| 622 | * @mgr: fpga manager struct created by fpga_mgr_create | 625 | * @mgr: fpga manager struct |
| 623 | */ | 626 | */ |
| 624 | void fpga_mgr_free(struct fpga_manager *mgr) | 627 | void fpga_mgr_free(struct fpga_manager *mgr) |
| 625 | { | 628 | { |
| @@ -628,9 +631,55 @@ void fpga_mgr_free(struct fpga_manager *mgr) | |||
| 628 | } | 631 | } |
| 629 | EXPORT_SYMBOL_GPL(fpga_mgr_free); | 632 | EXPORT_SYMBOL_GPL(fpga_mgr_free); |
| 630 | 633 | ||
| 634 | static void devm_fpga_mgr_release(struct device *dev, void *res) | ||
| 635 | { | ||
| 636 | struct fpga_manager *mgr = *(struct fpga_manager **)res; | ||
| 637 | |||
| 638 | fpga_mgr_free(mgr); | ||
| 639 | } | ||
| 640 | |||
| 641 | /** | ||
| 642 | * devm_fpga_mgr_create - create and initialize a managed FPGA manager struct | ||
| 643 | * @dev: fpga manager device from pdev | ||
| 644 | * @name: fpga manager name | ||
| 645 | * @mops: pointer to structure of fpga manager ops | ||
| 646 | * @priv: fpga manager private data | ||
| 647 | * | ||
| 648 | * This function is intended for use in a FPGA manager driver's probe function. | ||
| 649 | * After the manager driver creates the manager struct with | ||
| 650 | * devm_fpga_mgr_create(), it should register it with fpga_mgr_register(). The | ||
| 651 | * manager driver's remove function should call fpga_mgr_unregister(). The | ||
| 652 | * manager struct allocated with this function will be freed automatically on | ||
| 653 | * driver detach. This includes the case of a probe function returning error | ||
| 654 | * before calling fpga_mgr_register(), the struct will still get cleaned up. | ||
| 655 | * | ||
| 656 | * Return: pointer to struct fpga_manager or NULL | ||
| 657 | */ | ||
| 658 | struct fpga_manager *devm_fpga_mgr_create(struct device *dev, const char *name, | ||
| 659 | const struct fpga_manager_ops *mops, | ||
| 660 | void *priv) | ||
| 661 | { | ||
| 662 | struct fpga_manager **ptr, *mgr; | ||
| 663 | |||
| 664 | ptr = devres_alloc(devm_fpga_mgr_release, sizeof(*ptr), GFP_KERNEL); | ||
| 665 | if (!ptr) | ||
| 666 | return NULL; | ||
| 667 | |||
| 668 | mgr = fpga_mgr_create(dev, name, mops, priv); | ||
| 669 | if (!mgr) { | ||
| 670 | devres_free(ptr); | ||
| 671 | } else { | ||
| 672 | *ptr = mgr; | ||
| 673 | devres_add(dev, ptr); | ||
| 674 | } | ||
| 675 | |||
| 676 | return mgr; | ||
| 677 | } | ||
| 678 | EXPORT_SYMBOL_GPL(devm_fpga_mgr_create); | ||
| 679 | |||
| 631 | /** | 680 | /** |
| 632 | * fpga_mgr_register - register a FPGA manager | 681 | * fpga_mgr_register - register a FPGA manager |
| 633 | * @mgr: fpga manager struct created by fpga_mgr_create | 682 | * @mgr: fpga manager struct |
| 634 | * | 683 | * |
| 635 | * Return: 0 on success, negative error code otherwise. | 684 | * Return: 0 on success, negative error code otherwise. |
| 636 | */ | 685 | */ |
| @@ -661,8 +710,10 @@ error_device: | |||
| 661 | EXPORT_SYMBOL_GPL(fpga_mgr_register); | 710 | EXPORT_SYMBOL_GPL(fpga_mgr_register); |
| 662 | 711 | ||
| 663 | /** | 712 | /** |
| 664 | * fpga_mgr_unregister - unregister and free a FPGA manager | 713 | * fpga_mgr_unregister - unregister a FPGA manager |
| 665 | * @mgr: fpga manager struct | 714 | * @mgr: fpga manager struct |
| 715 | * | ||
| 716 | * This function is intended for use in a FPGA manager driver's remove function. | ||
| 666 | */ | 717 | */ |
| 667 | void fpga_mgr_unregister(struct fpga_manager *mgr) | 718 | void fpga_mgr_unregister(struct fpga_manager *mgr) |
| 668 | { | 719 | { |
| @@ -681,9 +732,6 @@ EXPORT_SYMBOL_GPL(fpga_mgr_unregister); | |||
| 681 | 732 | ||
| 682 | static void fpga_mgr_dev_release(struct device *dev) | 733 | static void fpga_mgr_dev_release(struct device *dev) |
| 683 | { | 734 | { |
| 684 | struct fpga_manager *mgr = to_fpga_manager(dev); | ||
| 685 | |||
| 686 | fpga_mgr_free(mgr); | ||
| 687 | } | 735 | } |
| 688 | 736 | ||
| 689 | static int __init fpga_mgr_class_init(void) | 737 | static int __init fpga_mgr_class_init(void) |
