mirror of
https://github.com/torvalds/linux.git
synced 2026-05-27 16:44:58 +02:00
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: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240703-thermal-const-v1-4-6e59e139c65d@linaro.org Signed-off-by: Bjorn Andersson <andersson@kernel.org>
This commit is contained in:
parent
20635bcc12
commit
0ed06fcc7a
|
|
@ -3,6 +3,7 @@
|
|||
* Copyright (C) 2020 The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
|
|
@ -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)
|
||||
{
|
||||
struct servreg_get_domain_list_resp *resp;
|
||||
struct servreg_get_domain_list_req req;
|
||||
struct servreg_location_entry *entry;
|
||||
int domains_read = 0;
|
||||
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)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
@ -415,7 +416,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
|
|||
req.domain_offset = domains_read;
|
||||
ret = pdr_get_domain_list(&req, resp, pdr);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < resp->domain_list_len; i++) {
|
||||
entry = &resp->domain_list[i];
|
||||
|
|
@ -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 = entry->service_data;
|
||||
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)
|
|||
|
||||
domains_read += resp->domain_list_len;
|
||||
} while (domains_read < resp->total_domains);
|
||||
out:
|
||||
kfree(resp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -517,8 +517,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
|
|||
const char *service_name,
|
||||
const char *service_path)
|
||||
{
|
||||
struct pdr_service *pds, *tmp;
|
||||
int ret;
|
||||
struct pdr_service *tmp;
|
||||
|
||||
if (IS_ERR_OR_NULL(pdr))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
|
@ -527,7 +526,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
|
|||
!service_path || strlen(service_path) > SERVREG_NAME_LENGTH)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
pds = kzalloc(sizeof(*pds), GFP_KERNEL);
|
||||
struct pdr_service *pds __free(kfree) = kzalloc(sizeof(*pds), GFP_KERNEL);
|
||||
if (!pds)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
|
|
@ -542,8 +541,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
|
|||
continue;
|
||||
|
||||
mutex_unlock(&pdr->list_lock);
|
||||
ret = -EALREADY;
|
||||
goto err;
|
||||
return ERR_PTR(-EALREADY);
|
||||
}
|
||||
|
||||
list_add(&pds->node, &pdr->lookups);
|
||||
|
|
@ -551,10 +549,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
|
|||
|
||||
schedule_work(&pdr->locator_work);
|
||||
|
||||
return pds;
|
||||
err:
|
||||
kfree(pds);
|
||||
return ERR_PTR(ret);
|
||||
return_ptr(pds);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pdr_add_lookup);
|
||||
|
||||
|
|
@ -651,13 +646,12 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
|
|||
char *service_path,
|
||||
void *priv), void *priv)
|
||||
{
|
||||
struct pdr_handle *pdr;
|
||||
int ret;
|
||||
|
||||
if (!status)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
pdr = kzalloc(sizeof(*pdr), GFP_KERNEL);
|
||||
struct pdr_handle *pdr __free(kfree) = kzalloc(sizeof(*pdr), GFP_KERNEL);
|
||||
if (!pdr)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
|
|
@ -676,10 +670,8 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
|
|||
INIT_WORK(&pdr->indack_work, pdr_indack_work);
|
||||
|
||||
pdr->notifier_wq = create_singlethread_workqueue("pdr_notifier_wq");
|
||||
if (!pdr->notifier_wq) {
|
||||
ret = -ENOMEM;
|
||||
goto free_pdr_handle;
|
||||
}
|
||||
if (!pdr->notifier_wq)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
pdr->indack_wq = alloc_ordered_workqueue("pdr_indack_wq", WQ_HIGHPRI);
|
||||
if (!pdr->indack_wq) {
|
||||
|
|
@ -704,7 +696,7 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
|
|||
if (ret < 0)
|
||||
goto release_qmi_handle;
|
||||
|
||||
return pdr;
|
||||
return_ptr(pdr);
|
||||
|
||||
release_qmi_handle:
|
||||
qmi_handle_release(&pdr->locator_hdl);
|
||||
|
|
@ -712,8 +704,6 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
|
|||
destroy_workqueue(pdr->indack_wq);
|
||||
destroy_notifier:
|
||||
destroy_workqueue(pdr->notifier_wq);
|
||||
free_pdr_handle:
|
||||
kfree(pdr);
|
||||
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user