Commit 0ed06fcc authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Bjorn Andersson

soc: qcom: pdr: simplify with cleanup.h

Allocate the memory with scoped/cleanup.h to reduce error handling (less
error paths) and make the code a bit simpler.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240703-thermal-const-v1-4-6e59e139c65d@linaro.orgSigned-off-by: default avatarBjorn Andersson <andersson@kernel.org>
parent 20635bcc
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Copyright (C) 2020 The Linux Foundation. All rights reserved. * Copyright (C) 2020 The Linux Foundation. All rights reserved.
*/ */
#include <linux/cleanup.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -396,13 +397,13 @@ static int pdr_get_domain_list(struct servreg_get_domain_list_req *req, ...@@ -396,13 +397,13 @@ static int pdr_get_domain_list(struct servreg_get_domain_list_req *req,
static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds) static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
{ {
struct servreg_get_domain_list_resp *resp;
struct servreg_get_domain_list_req req; struct servreg_get_domain_list_req req;
struct servreg_location_entry *entry; struct servreg_location_entry *entry;
int domains_read = 0; int domains_read = 0;
int ret, i; int ret, i;
resp = kzalloc(sizeof(*resp), GFP_KERNEL); struct servreg_get_domain_list_resp *resp __free(kfree) = kzalloc(sizeof(*resp),
GFP_KERNEL);
if (!resp) if (!resp)
return -ENOMEM; return -ENOMEM;
...@@ -415,7 +416,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds) ...@@ -415,7 +416,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
req.domain_offset = domains_read; req.domain_offset = domains_read;
ret = pdr_get_domain_list(&req, resp, pdr); ret = pdr_get_domain_list(&req, resp, pdr);
if (ret < 0) if (ret < 0)
goto out; return ret;
for (i = 0; i < resp->domain_list_len; i++) { for (i = 0; i < resp->domain_list_len; i++) {
entry = &resp->domain_list[i]; entry = &resp->domain_list[i];
...@@ -427,7 +428,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds) ...@@ -427,7 +428,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
pds->service_data_valid = entry->service_data_valid; pds->service_data_valid = entry->service_data_valid;
pds->service_data = entry->service_data; pds->service_data = entry->service_data;
pds->instance = entry->instance; pds->instance = entry->instance;
goto out; return 0;
} }
} }
...@@ -440,8 +441,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds) ...@@ -440,8 +441,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
domains_read += resp->domain_list_len; domains_read += resp->domain_list_len;
} while (domains_read < resp->total_domains); } while (domains_read < resp->total_domains);
out:
kfree(resp);
return ret; return ret;
} }
...@@ -517,8 +517,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr, ...@@ -517,8 +517,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
const char *service_name, const char *service_name,
const char *service_path) const char *service_path)
{ {
struct pdr_service *pds, *tmp; struct pdr_service *tmp;
int ret;
if (IS_ERR_OR_NULL(pdr)) if (IS_ERR_OR_NULL(pdr))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -527,7 +526,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr, ...@@ -527,7 +526,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
!service_path || strlen(service_path) > SERVREG_NAME_LENGTH) !service_path || strlen(service_path) > SERVREG_NAME_LENGTH)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
pds = kzalloc(sizeof(*pds), GFP_KERNEL); struct pdr_service *pds __free(kfree) = kzalloc(sizeof(*pds), GFP_KERNEL);
if (!pds) if (!pds)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -542,8 +541,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr, ...@@ -542,8 +541,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
continue; continue;
mutex_unlock(&pdr->list_lock); mutex_unlock(&pdr->list_lock);
ret = -EALREADY; return ERR_PTR(-EALREADY);
goto err;
} }
list_add(&pds->node, &pdr->lookups); list_add(&pds->node, &pdr->lookups);
...@@ -551,10 +549,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr, ...@@ -551,10 +549,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
schedule_work(&pdr->locator_work); schedule_work(&pdr->locator_work);
return pds; return_ptr(pds);
err:
kfree(pds);
return ERR_PTR(ret);
} }
EXPORT_SYMBOL_GPL(pdr_add_lookup); EXPORT_SYMBOL_GPL(pdr_add_lookup);
...@@ -651,13 +646,12 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state, ...@@ -651,13 +646,12 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
char *service_path, char *service_path,
void *priv), void *priv) void *priv), void *priv)
{ {
struct pdr_handle *pdr;
int ret; int ret;
if (!status) if (!status)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
pdr = kzalloc(sizeof(*pdr), GFP_KERNEL); struct pdr_handle *pdr __free(kfree) = kzalloc(sizeof(*pdr), GFP_KERNEL);
if (!pdr) if (!pdr)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -676,10 +670,8 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state, ...@@ -676,10 +670,8 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
INIT_WORK(&pdr->indack_work, pdr_indack_work); INIT_WORK(&pdr->indack_work, pdr_indack_work);
pdr->notifier_wq = create_singlethread_workqueue("pdr_notifier_wq"); pdr->notifier_wq = create_singlethread_workqueue("pdr_notifier_wq");
if (!pdr->notifier_wq) { if (!pdr->notifier_wq)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto free_pdr_handle;
}
pdr->indack_wq = alloc_ordered_workqueue("pdr_indack_wq", WQ_HIGHPRI); pdr->indack_wq = alloc_ordered_workqueue("pdr_indack_wq", WQ_HIGHPRI);
if (!pdr->indack_wq) { if (!pdr->indack_wq) {
...@@ -704,7 +696,7 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state, ...@@ -704,7 +696,7 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
if (ret < 0) if (ret < 0)
goto release_qmi_handle; goto release_qmi_handle;
return pdr; return_ptr(pdr);
release_qmi_handle: release_qmi_handle:
qmi_handle_release(&pdr->locator_hdl); qmi_handle_release(&pdr->locator_hdl);
...@@ -712,8 +704,6 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state, ...@@ -712,8 +704,6 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
destroy_workqueue(pdr->indack_wq); destroy_workqueue(pdr->indack_wq);
destroy_notifier: destroy_notifier:
destroy_workqueue(pdr->notifier_wq); destroy_workqueue(pdr->notifier_wq);
free_pdr_handle:
kfree(pdr);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment