diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2017-01-02 04:11:04 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-01-27 05:49:10 -0500 |
commit | b6160e26936bcf1b9181bb34ad4f420ccd3f39f0 (patch) | |
tree | 05415262587e48a656bf801651d4ffaac0669742 /drivers/base/power/opp/core.c | |
parent | dc2c9ad52af45ebecf9743aacb1916ebb2f1e848 (diff) |
PM / OPP: Split out part of _add_opp_table() and _remove_opp_table()
Split out parts of _add_opp_table() and _remove_opp_table() into
separate routines. This improves readability as well.
Should result in no functional changes.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/base/power/opp/core.c')
-rw-r--r-- | drivers/base/power/opp/core.c | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index f35effad60d1..622dd32f8dda 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c | |||
@@ -819,26 +819,12 @@ struct opp_device *_add_opp_dev(const struct device *dev, | |||
819 | return opp_dev; | 819 | return opp_dev; |
820 | } | 820 | } |
821 | 821 | ||
822 | /** | 822 | static struct opp_table *_allocate_opp_table(struct device *dev) |
823 | * _add_opp_table() - Find OPP table or allocate a new one | ||
824 | * @dev: device for which we do this operation | ||
825 | * | ||
826 | * It tries to find an existing table first, if it couldn't find one, it | ||
827 | * allocates a new OPP table and returns that. | ||
828 | * | ||
829 | * Return: valid opp_table pointer if success, else NULL. | ||
830 | */ | ||
831 | struct opp_table *_add_opp_table(struct device *dev) | ||
832 | { | 823 | { |
833 | struct opp_table *opp_table; | 824 | struct opp_table *opp_table; |
834 | struct opp_device *opp_dev; | 825 | struct opp_device *opp_dev; |
835 | int ret; | 826 | int ret; |
836 | 827 | ||
837 | /* Check for existing table for 'dev' first */ | ||
838 | opp_table = _find_opp_table(dev); | ||
839 | if (!IS_ERR(opp_table)) | ||
840 | return opp_table; | ||
841 | |||
842 | /* | 828 | /* |
843 | * Allocate a new OPP table. In the infrequent case where a new | 829 | * Allocate a new OPP table. In the infrequent case where a new |
844 | * device is needed to be added, we pay this penalty. | 830 | * device is needed to be added, we pay this penalty. |
@@ -875,6 +861,27 @@ struct opp_table *_add_opp_table(struct device *dev) | |||
875 | } | 861 | } |
876 | 862 | ||
877 | /** | 863 | /** |
864 | * _add_opp_table() - Find OPP table or allocate a new one | ||
865 | * @dev: device for which we do this operation | ||
866 | * | ||
867 | * It tries to find an existing table first, if it couldn't find one, it | ||
868 | * allocates a new OPP table and returns that. | ||
869 | * | ||
870 | * Return: valid opp_table pointer if success, else NULL. | ||
871 | */ | ||
872 | struct opp_table *_add_opp_table(struct device *dev) | ||
873 | { | ||
874 | struct opp_table *opp_table; | ||
875 | |||
876 | /* Check for existing table for 'dev' first */ | ||
877 | opp_table = _find_opp_table(dev); | ||
878 | if (!IS_ERR(opp_table)) | ||
879 | return opp_table; | ||
880 | |||
881 | return _allocate_opp_table(dev); | ||
882 | } | ||
883 | |||
884 | /** | ||
878 | * _kfree_device_rcu() - Free opp_table RCU handler | 885 | * _kfree_device_rcu() - Free opp_table RCU handler |
879 | * @head: RCU head | 886 | * @head: RCU head |
880 | */ | 887 | */ |
@@ -886,6 +893,27 @@ static void _kfree_device_rcu(struct rcu_head *head) | |||
886 | kfree_rcu(opp_table, rcu_head); | 893 | kfree_rcu(opp_table, rcu_head); |
887 | } | 894 | } |
888 | 895 | ||
896 | static void _free_opp_table(struct opp_table *opp_table) | ||
897 | { | ||
898 | struct opp_device *opp_dev; | ||
899 | |||
900 | /* Release clk */ | ||
901 | if (!IS_ERR(opp_table->clk)) | ||
902 | clk_put(opp_table->clk); | ||
903 | |||
904 | opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, | ||
905 | node); | ||
906 | |||
907 | _remove_opp_dev(opp_dev, opp_table); | ||
908 | |||
909 | /* dev_list must be empty now */ | ||
910 | WARN_ON(!list_empty(&opp_table->dev_list)); | ||
911 | |||
912 | list_del_rcu(&opp_table->node); | ||
913 | call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, | ||
914 | _kfree_device_rcu); | ||
915 | } | ||
916 | |||
889 | /** | 917 | /** |
890 | * _remove_opp_table() - Removes a OPP table | 918 | * _remove_opp_table() - Removes a OPP table |
891 | * @opp_table: OPP table to be removed. | 919 | * @opp_table: OPP table to be removed. |
@@ -894,8 +922,6 @@ static void _kfree_device_rcu(struct rcu_head *head) | |||
894 | */ | 922 | */ |
895 | static void _remove_opp_table(struct opp_table *opp_table) | 923 | static void _remove_opp_table(struct opp_table *opp_table) |
896 | { | 924 | { |
897 | struct opp_device *opp_dev; | ||
898 | |||
899 | if (!list_empty(&opp_table->opp_list)) | 925 | if (!list_empty(&opp_table->opp_list)) |
900 | return; | 926 | return; |
901 | 927 | ||
@@ -911,21 +937,7 @@ static void _remove_opp_table(struct opp_table *opp_table) | |||
911 | if (opp_table->set_opp) | 937 | if (opp_table->set_opp) |
912 | return; | 938 | return; |
913 | 939 | ||
914 | /* Release clk */ | 940 | _free_opp_table(opp_table); |
915 | if (!IS_ERR(opp_table->clk)) | ||
916 | clk_put(opp_table->clk); | ||
917 | |||
918 | opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, | ||
919 | node); | ||
920 | |||
921 | _remove_opp_dev(opp_dev, opp_table); | ||
922 | |||
923 | /* dev_list must be empty now */ | ||
924 | WARN_ON(!list_empty(&opp_table->dev_list)); | ||
925 | |||
926 | list_del_rcu(&opp_table->node); | ||
927 | call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, | ||
928 | _kfree_device_rcu); | ||
929 | } | 941 | } |
930 | 942 | ||
931 | void _opp_free(struct dev_pm_opp *opp) | 943 | void _opp_free(struct dev_pm_opp *opp) |