Skip to content

Commit 0ed06fc

Browse files
krzkandersson
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 20635bc commit 0ed06fc

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

drivers/soc/qcom/pdr_interface.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2020 The Linux Foundation. All rights reserved.
44
*/
55

6+
#include <linux/cleanup.h>
67
#include <linux/kernel.h>
78
#include <linux/module.h>
89
#include <linux/slab.h>
@@ -396,13 +397,13 @@ static int pdr_get_domain_list(struct servreg_get_domain_list_req *req,
396397

397398
static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
398399
{
399-
struct servreg_get_domain_list_resp *resp;
400400
struct servreg_get_domain_list_req req;
401401
struct servreg_location_entry *entry;
402402
int domains_read = 0;
403403
int ret, i;
404404

405-
resp = kzalloc(sizeof(*resp), GFP_KERNEL);
405+
struct servreg_get_domain_list_resp *resp __free(kfree) = kzalloc(sizeof(*resp),
406+
GFP_KERNEL);
406407
if (!resp)
407408
return -ENOMEM;
408409

@@ -415,7 +416,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
415416
req.domain_offset = domains_read;
416417
ret = pdr_get_domain_list(&req, resp, pdr);
417418
if (ret < 0)
418-
goto out;
419+
return ret;
419420

420421
for (i = 0; i < resp->domain_list_len; i++) {
421422
entry = &resp->domain_list[i];
@@ -427,7 +428,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
427428
pds->service_data_valid = entry->service_data_valid;
428429
pds->service_data = entry->service_data;
429430
pds->instance = entry->instance;
430-
goto out;
431+
return 0;
431432
}
432433
}
433434

@@ -440,8 +441,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
440441

441442
domains_read += resp->domain_list_len;
442443
} while (domains_read < resp->total_domains);
443-
out:
444-
kfree(resp);
444+
445445
return ret;
446446
}
447447

@@ -517,8 +517,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
517517
const char *service_name,
518518
const char *service_path)
519519
{
520-
struct pdr_service *pds, *tmp;
521-
int ret;
520+
struct pdr_service *tmp;
522521

523522
if (IS_ERR_OR_NULL(pdr))
524523
return ERR_PTR(-EINVAL);
@@ -527,7 +526,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
527526
!service_path || strlen(service_path) > SERVREG_NAME_LENGTH)
528527
return ERR_PTR(-EINVAL);
529528

530-
pds = kzalloc(sizeof(*pds), GFP_KERNEL);
529+
struct pdr_service *pds __free(kfree) = kzalloc(sizeof(*pds), GFP_KERNEL);
531530
if (!pds)
532531
return ERR_PTR(-ENOMEM);
533532

@@ -542,19 +541,15 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
542541
continue;
543542

544543
mutex_unlock(&pdr->list_lock);
545-
ret = -EALREADY;
546-
goto err;
544+
return ERR_PTR(-EALREADY);
547545
}
548546

549547
list_add(&pds->node, &pdr->lookups);
550548
mutex_unlock(&pdr->list_lock);
551549

552550
schedule_work(&pdr->locator_work);
553551

554-
return pds;
555-
err:
556-
kfree(pds);
557-
return ERR_PTR(ret);
552+
return_ptr(pds);
558553
}
559554
EXPORT_SYMBOL_GPL(pdr_add_lookup);
560555

@@ -651,13 +646,12 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
651646
char *service_path,
652647
void *priv), void *priv)
653648
{
654-
struct pdr_handle *pdr;
655649
int ret;
656650

657651
if (!status)
658652
return ERR_PTR(-EINVAL);
659653

660-
pdr = kzalloc(sizeof(*pdr), GFP_KERNEL);
654+
struct pdr_handle *pdr __free(kfree) = kzalloc(sizeof(*pdr), GFP_KERNEL);
661655
if (!pdr)
662656
return ERR_PTR(-ENOMEM);
663657

@@ -676,10 +670,8 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
676670
INIT_WORK(&pdr->indack_work, pdr_indack_work);
677671

678672
pdr->notifier_wq = create_singlethread_workqueue("pdr_notifier_wq");
679-
if (!pdr->notifier_wq) {
680-
ret = -ENOMEM;
681-
goto free_pdr_handle;
682-
}
673+
if (!pdr->notifier_wq)
674+
return ERR_PTR(-ENOMEM);
683675

684676
pdr->indack_wq = alloc_ordered_workqueue("pdr_indack_wq", WQ_HIGHPRI);
685677
if (!pdr->indack_wq) {
@@ -704,16 +696,14 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
704696
if (ret < 0)
705697
goto release_qmi_handle;
706698

707-
return pdr;
699+
return_ptr(pdr);
708700

709701
release_qmi_handle:
710702
qmi_handle_release(&pdr->locator_hdl);
711703
destroy_indack:
712704
destroy_workqueue(pdr->indack_wq);
713705
destroy_notifier:
714706
destroy_workqueue(pdr->notifier_wq);
715-
free_pdr_handle:
716-
kfree(pdr);
717707

718708
return ERR_PTR(ret);
719709
}

0 commit comments

Comments
 (0)