@@ -87,35 +87,26 @@ static int set_etr3(struct pmc_dev *pmcdev)
87
87
struct pmc * pmc = pmcdev -> pmcs [PMC_IDX_MAIN ];
88
88
const struct pmc_reg_map * map = pmc -> map ;
89
89
u32 reg ;
90
- int err ;
91
90
92
91
if (!map -> etr3_offset )
93
92
return - EOPNOTSUPP ;
94
93
95
- mutex_lock (& pmcdev -> lock );
94
+ guard ( mutex ) (& pmcdev -> lock );
96
95
97
96
/* check if CF9 is locked */
98
97
reg = pmc_core_reg_read (pmc , map -> etr3_offset );
99
- if (reg & ETR3_CF9LOCK ) {
100
- err = - EACCES ;
101
- goto out_unlock ;
102
- }
98
+ if (reg & ETR3_CF9LOCK )
99
+ return - EACCES ;
103
100
104
101
/* write CF9 global reset bit */
105
102
reg |= ETR3_CF9GR ;
106
103
pmc_core_reg_write (pmc , map -> etr3_offset , reg );
107
104
108
105
reg = pmc_core_reg_read (pmc , map -> etr3_offset );
109
- if (!(reg & ETR3_CF9GR )) {
110
- err = - EIO ;
111
- goto out_unlock ;
112
- }
113
-
114
- err = 0 ;
106
+ if (!(reg & ETR3_CF9GR ))
107
+ return - EIO ;
115
108
116
- out_unlock :
117
- mutex_unlock (& pmcdev -> lock );
118
- return err ;
109
+ return 0 ;
119
110
}
120
111
static umode_t etr3_is_visible (struct kobject * kobj ,
121
112
struct attribute * attr ,
@@ -127,9 +118,8 @@ static umode_t etr3_is_visible(struct kobject *kobj,
127
118
const struct pmc_reg_map * map = pmc -> map ;
128
119
u32 reg ;
129
120
130
- mutex_lock (& pmcdev -> lock );
131
- reg = pmc_core_reg_read (pmc , map -> etr3_offset );
132
- mutex_unlock (& pmcdev -> lock );
121
+ scoped_guard (mutex , & pmcdev -> lock )
122
+ reg = pmc_core_reg_read (pmc , map -> etr3_offset );
133
123
134
124
return reg & ETR3_CF9LOCK ? attr -> mode & (SYSFS_PREALLOC | 0444 ) : attr -> mode ;
135
125
}
@@ -145,12 +135,10 @@ static ssize_t etr3_show(struct device *dev,
145
135
if (!map -> etr3_offset )
146
136
return - EOPNOTSUPP ;
147
137
148
- mutex_lock (& pmcdev -> lock );
149
-
150
- reg = pmc_core_reg_read (pmc , map -> etr3_offset );
151
- reg &= ETR3_CF9GR | ETR3_CF9LOCK ;
152
-
153
- mutex_unlock (& pmcdev -> lock );
138
+ scoped_guard (mutex , & pmcdev -> lock ) {
139
+ reg = pmc_core_reg_read (pmc , map -> etr3_offset );
140
+ reg &= ETR3_CF9GR | ETR3_CF9LOCK ;
141
+ }
154
142
155
143
return sysfs_emit (buf , "0x%08x" , reg );
156
144
}
@@ -401,18 +389,18 @@ static int pmc_core_mphy_pg_show(struct seq_file *s, void *unused)
401
389
mphy_core_reg_low = (SPT_PMC_MPHY_CORE_STS_0 << 16 );
402
390
mphy_core_reg_high = (SPT_PMC_MPHY_CORE_STS_1 << 16 );
403
391
404
- mutex_lock (& pmcdev -> lock );
392
+ guard ( mutex ) (& pmcdev -> lock );
405
393
406
394
err = pmc_core_send_msg (pmc , & mphy_core_reg_low );
407
395
if (err )
408
- goto out_unlock ;
396
+ return err ;
409
397
410
398
msleep (10 );
411
399
val_low = pmc_core_reg_read (pmc , SPT_PMC_MFPMC_OFFSET );
412
400
413
401
err = pmc_core_send_msg (pmc , & mphy_core_reg_high );
414
402
if (err )
415
- goto out_unlock ;
403
+ return err ;
416
404
417
405
msleep (10 );
418
406
val_high = pmc_core_reg_read (pmc , SPT_PMC_MFPMC_OFFSET );
@@ -431,9 +419,7 @@ static int pmc_core_mphy_pg_show(struct seq_file *s, void *unused)
431
419
"Power gated" );
432
420
}
433
421
434
- out_unlock :
435
- mutex_unlock (& pmcdev -> lock );
436
- return err ;
422
+ return 0 ;
437
423
}
438
424
DEFINE_SHOW_ATTRIBUTE (pmc_core_mphy_pg );
439
425
@@ -451,11 +437,11 @@ static int pmc_core_pll_show(struct seq_file *s, void *unused)
451
437
}
452
438
453
439
mphy_common_reg = (SPT_PMC_MPHY_COM_STS_0 << 16 );
454
- mutex_lock (& pmcdev -> lock );
440
+ guard ( mutex ) (& pmcdev -> lock );
455
441
456
442
err = pmc_core_send_msg (pmc , & mphy_common_reg );
457
443
if (err )
458
- goto out_unlock ;
444
+ return err ;
459
445
460
446
/* Observed PMC HW response latency for MTPMC-MFPMC is ~10 ms */
461
447
msleep (10 );
@@ -467,9 +453,7 @@ static int pmc_core_pll_show(struct seq_file *s, void *unused)
467
453
map [index ].bit_mask & val ? "Active" : "Idle" );
468
454
}
469
455
470
- out_unlock :
471
- mutex_unlock (& pmcdev -> lock );
472
- return err ;
456
+ return 0 ;
473
457
}
474
458
DEFINE_SHOW_ATTRIBUTE (pmc_core_pll );
475
459
@@ -508,7 +492,7 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)
508
492
509
493
pr_debug ("ltr_ignore for pmc%d: ltr_index:%d\n" , pmc_index , ltr_index );
510
494
511
- mutex_lock (& pmcdev -> lock );
495
+ guard ( mutex ) (& pmcdev -> lock );
512
496
513
497
reg = pmc_core_reg_read (pmc , map -> ltr_ignore_offset );
514
498
if (ignore )
@@ -517,8 +501,6 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)
517
501
reg &= ~BIT (ltr_index );
518
502
pmc_core_reg_write (pmc , map -> ltr_ignore_offset , reg );
519
503
520
- mutex_unlock (& pmcdev -> lock );
521
-
522
504
return 0 ;
523
505
}
524
506
@@ -566,10 +548,10 @@ static void pmc_core_slps0_dbg_latch(struct pmc_dev *pmcdev, bool reset)
566
548
const struct pmc_reg_map * map = pmc -> map ;
567
549
u32 fd ;
568
550
569
- mutex_lock (& pmcdev -> lock );
551
+ guard ( mutex ) (& pmcdev -> lock );
570
552
571
553
if (!reset && !slps0_dbg_latch )
572
- goto out_unlock ;
554
+ return ;
573
555
574
556
fd = pmc_core_reg_read (pmc , map -> slps0_dbg_offset );
575
557
if (reset )
@@ -579,9 +561,6 @@ static void pmc_core_slps0_dbg_latch(struct pmc_dev *pmcdev, bool reset)
579
561
pmc_core_reg_write (pmc , map -> slps0_dbg_offset , fd );
580
562
581
563
slps0_dbg_latch = false;
582
-
583
- out_unlock :
584
- mutex_unlock (& pmcdev -> lock );
585
564
}
586
565
587
566
static int pmc_core_slps0_dbg_show (struct seq_file * s , void * unused )
@@ -984,26 +963,22 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
984
963
}
985
964
986
965
if (clear ) {
987
- mutex_lock (& pmcdev -> lock );
966
+ guard ( mutex ) (& pmcdev -> lock );
988
967
989
968
reg = pmc_core_reg_read (pmc , pmc -> map -> etr3_offset );
990
969
reg |= ETR3_CLEAR_LPM_EVENTS ;
991
970
pmc_core_reg_write (pmc , pmc -> map -> etr3_offset , reg );
992
971
993
- mutex_unlock (& pmcdev -> lock );
994
-
995
972
return count ;
996
973
}
997
974
998
975
if (c10 ) {
999
- mutex_lock (& pmcdev -> lock );
976
+ guard ( mutex ) (& pmcdev -> lock );
1000
977
1001
978
reg = pmc_core_reg_read (pmc , pmc -> map -> lpm_sts_latch_en_offset );
1002
979
reg &= ~LPM_STS_LATCH_MODE ;
1003
980
pmc_core_reg_write (pmc , pmc -> map -> lpm_sts_latch_en_offset , reg );
1004
981
1005
- mutex_unlock (& pmcdev -> lock );
1006
-
1007
982
return count ;
1008
983
}
1009
984
@@ -1012,9 +987,8 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
1012
987
* and clear everything else.
1013
988
*/
1014
989
reg = LPM_STS_LATCH_MODE | BIT (mode );
1015
- mutex_lock (& pmcdev -> lock );
990
+ guard ( mutex ) (& pmcdev -> lock );
1016
991
pmc_core_reg_write (pmc , pmc -> map -> lpm_sts_latch_en_offset , reg );
1017
- mutex_unlock (& pmcdev -> lock );
1018
992
1019
993
return count ;
1020
994
}
0 commit comments