3
3
* Copyright (C) 2020 The Linux Foundation. All rights reserved.
4
4
*/
5
5
6
+ #include <linux/cleanup.h>
6
7
#include <linux/kernel.h>
7
8
#include <linux/module.h>
8
9
#include <linux/slab.h>
@@ -396,13 +397,13 @@ static int pdr_get_domain_list(struct servreg_get_domain_list_req *req,
396
397
397
398
static int pdr_locate_service (struct pdr_handle * pdr , struct pdr_service * pds )
398
399
{
399
- struct servreg_get_domain_list_resp * resp ;
400
400
struct servreg_get_domain_list_req req ;
401
401
struct servreg_location_entry * entry ;
402
402
int domains_read = 0 ;
403
403
int ret , i ;
404
404
405
- resp = kzalloc (sizeof (* resp ), GFP_KERNEL );
405
+ struct servreg_get_domain_list_resp * resp __free (kfree ) = kzalloc (sizeof (* resp ),
406
+ GFP_KERNEL );
406
407
if (!resp )
407
408
return - ENOMEM ;
408
409
@@ -415,7 +416,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
415
416
req .domain_offset = domains_read ;
416
417
ret = pdr_get_domain_list (& req , resp , pdr );
417
418
if (ret < 0 )
418
- goto out ;
419
+ return ret ;
419
420
420
421
for (i = 0 ; i < resp -> domain_list_len ; i ++ ) {
421
422
entry = & resp -> domain_list [i ];
@@ -427,7 +428,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
427
428
pds -> service_data_valid = entry -> service_data_valid ;
428
429
pds -> service_data = entry -> service_data ;
429
430
pds -> instance = entry -> instance ;
430
- goto out ;
431
+ return 0 ;
431
432
}
432
433
}
433
434
@@ -440,8 +441,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
440
441
441
442
domains_read += resp -> domain_list_len ;
442
443
} while (domains_read < resp -> total_domains );
443
- out :
444
- kfree (resp );
444
+
445
445
return ret ;
446
446
}
447
447
@@ -517,8 +517,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
517
517
const char * service_name ,
518
518
const char * service_path )
519
519
{
520
- struct pdr_service * pds , * tmp ;
521
- int ret ;
520
+ struct pdr_service * tmp ;
522
521
523
522
if (IS_ERR_OR_NULL (pdr ))
524
523
return ERR_PTR (- EINVAL );
@@ -527,7 +526,7 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
527
526
!service_path || strlen (service_path ) > SERVREG_NAME_LENGTH )
528
527
return ERR_PTR (- EINVAL );
529
528
530
- pds = kzalloc (sizeof (* pds ), GFP_KERNEL );
529
+ struct pdr_service * pds __free ( kfree ) = kzalloc (sizeof (* pds ), GFP_KERNEL );
531
530
if (!pds )
532
531
return ERR_PTR (- ENOMEM );
533
532
@@ -542,19 +541,15 @@ struct pdr_service *pdr_add_lookup(struct pdr_handle *pdr,
542
541
continue ;
543
542
544
543
mutex_unlock (& pdr -> list_lock );
545
- ret = - EALREADY ;
546
- goto err ;
544
+ return ERR_PTR (- EALREADY );
547
545
}
548
546
549
547
list_add (& pds -> node , & pdr -> lookups );
550
548
mutex_unlock (& pdr -> list_lock );
551
549
552
550
schedule_work (& pdr -> locator_work );
553
551
554
- return pds ;
555
- err :
556
- kfree (pds );
557
- return ERR_PTR (ret );
552
+ return_ptr (pds );
558
553
}
559
554
EXPORT_SYMBOL_GPL (pdr_add_lookup );
560
555
@@ -651,13 +646,12 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
651
646
char * service_path ,
652
647
void * priv ), void * priv )
653
648
{
654
- struct pdr_handle * pdr ;
655
649
int ret ;
656
650
657
651
if (!status )
658
652
return ERR_PTR (- EINVAL );
659
653
660
- pdr = kzalloc (sizeof (* pdr ), GFP_KERNEL );
654
+ struct pdr_handle * pdr __free ( kfree ) = kzalloc (sizeof (* pdr ), GFP_KERNEL );
661
655
if (!pdr )
662
656
return ERR_PTR (- ENOMEM );
663
657
@@ -676,10 +670,8 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
676
670
INIT_WORK (& pdr -> indack_work , pdr_indack_work );
677
671
678
672
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 );
683
675
684
676
pdr -> indack_wq = alloc_ordered_workqueue ("pdr_indack_wq" , WQ_HIGHPRI );
685
677
if (!pdr -> indack_wq ) {
@@ -704,16 +696,14 @@ struct pdr_handle *pdr_handle_alloc(void (*status)(int state,
704
696
if (ret < 0 )
705
697
goto release_qmi_handle ;
706
698
707
- return pdr ;
699
+ return_ptr ( pdr ) ;
708
700
709
701
release_qmi_handle :
710
702
qmi_handle_release (& pdr -> locator_hdl );
711
703
destroy_indack :
712
704
destroy_workqueue (pdr -> indack_wq );
713
705
destroy_notifier :
714
706
destroy_workqueue (pdr -> notifier_wq );
715
- free_pdr_handle :
716
- kfree (pdr );
717
707
718
708
return ERR_PTR (ret );
719
709
}
0 commit comments