diff options
author | Alex Elder <elder@linaro.org> | 2021-01-15 06:50:49 -0600 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2021-01-18 11:51:06 -0800 |
commit | 10d0d3970187551645c7ab363e8c9d29e2122088 (patch) | |
tree | 78baeea31836739bbea2d491cbc1a1a2f1179a31 /drivers/net/ipa/ipa_clock.c | |
parent | e938d7ef92c38f43bbb6de03e8399f6f821d217b (diff) |
net: ipa: clean up interconnect initialization
Pass an the address of an IPA interconnect structure and its
configuration data to ipa_interconnect_init_one() and have that
function initialize all the structure's fields. Change the function
to simply return an error code.
Introduce ipa_interconnect_exit_one() to encapsulate the cleanup of
an IPA interconnect structure.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/net/ipa/ipa_clock.c')
-rw-r--r-- | drivers/net/ipa/ipa_clock.c | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/drivers/net/ipa/ipa_clock.c b/drivers/net/ipa/ipa_clock.c index 07069dbc6d03..fbe42106fc2a 100644 --- a/drivers/net/ipa/ipa_clock.c +++ b/drivers/net/ipa/ipa_clock.c @@ -56,17 +56,33 @@ struct ipa_clock { struct ipa_interconnect interconnect[IPA_INTERCONNECT_COUNT]; }; -static struct icc_path * -ipa_interconnect_init_one(struct device *dev, const char *name) +static int ipa_interconnect_init_one(struct device *dev, + struct ipa_interconnect *interconnect, + const struct ipa_interconnect_data *data) { struct icc_path *path; - path = of_icc_get(dev, name); - if (IS_ERR(path)) - dev_err(dev, "error %d getting %s interconnect\n", - (int)PTR_ERR(path), name); + path = of_icc_get(dev, data->name); + if (IS_ERR(path)) { + int ret = PTR_ERR(path); - return path; + dev_err(dev, "error %d getting %s interconnect\n", ret, + data->name); + + return ret; + } + + interconnect->path = path; + interconnect->average_bandwidth = data->average_bandwidth; + interconnect->peak_bandwidth = data->peak_bandwidth; + + return 0; +} + +static void ipa_interconnect_exit_one(struct ipa_interconnect *interconnect) +{ + icc_put(interconnect->path); + memset(interconnect, 0, sizeof(*interconnect)); } /* Initialize interconnects required for IPA operation */ @@ -74,51 +90,46 @@ static int ipa_interconnect_init(struct ipa_clock *clock, struct device *dev, const struct ipa_interconnect_data *data) { struct ipa_interconnect *interconnect; - struct icc_path *path; + int ret; - path = ipa_interconnect_init_one(dev, data->name); - if (IS_ERR(path)) - goto err_return; interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY]; - interconnect->path = path; - interconnect->average_bandwidth = data->average_bandwidth; - interconnect->peak_bandwidth = data->peak_bandwidth; - data++; + ret = ipa_interconnect_init_one(dev, interconnect, data++); + if (ret) + return ret; - path = ipa_interconnect_init_one(dev, data->name); - if (IS_ERR(path)) - goto err_memory_path_put; interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM]; - interconnect->path = path; - interconnect->average_bandwidth = data->average_bandwidth; - interconnect->peak_bandwidth = data->peak_bandwidth; - data++; + ret = ipa_interconnect_init_one(dev, interconnect, data++); + if (ret) + goto err_memory_path_put; - path = ipa_interconnect_init_one(dev, data->name); - if (IS_ERR(path)) + interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM]; + ret = ipa_interconnect_init_one(dev, interconnect, data++); + if (ret) goto err_imem_path_put; - interconnect = &clock->interconnect[IPA_INTERCONNECT_CONFIG]; - interconnect->path = path; - interconnect->average_bandwidth = data->average_bandwidth; - interconnect->peak_bandwidth = data->peak_bandwidth; - data++; return 0; err_imem_path_put: - icc_put(clock->interconnect[IPA_INTERCONNECT_IMEM].path); + interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM]; + ipa_interconnect_exit_one(interconnect); err_memory_path_put: - icc_put(clock->interconnect[IPA_INTERCONNECT_MEMORY].path); -err_return: - return PTR_ERR(path); + interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY]; + ipa_interconnect_exit_one(interconnect); + + return ret; } /* Inverse of ipa_interconnect_init() */ static void ipa_interconnect_exit(struct ipa_clock *clock) { - icc_put(clock->interconnect[IPA_INTERCONNECT_CONFIG].path); - icc_put(clock->interconnect[IPA_INTERCONNECT_IMEM].path); - icc_put(clock->interconnect[IPA_INTERCONNECT_MEMORY].path); + struct ipa_interconnect *interconnect; + + interconnect = &clock->interconnect[IPA_INTERCONNECT_CONFIG]; + ipa_interconnect_exit_one(interconnect); + interconnect = &clock->interconnect[IPA_INTERCONNECT_IMEM]; + ipa_interconnect_exit_one(interconnect); + interconnect = &clock->interconnect[IPA_INTERCONNECT_MEMORY]; + ipa_interconnect_exit_one(interconnect); } /* Currently we only use one bandwidth level, so just "enable" interconnects */ |