Skip to content

Commit 6d413a1

Browse files
xpardee-createij-intel
authored andcommitted
platform/x86:intel/pmc: Simplify mutex usage with cleanup helpers
Use macros defined in cleanup.h to automate the mutex lock/unlock flow. Signed-off-by: Xi Pardee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 40fdf3f commit 6d413a1

File tree

1 file changed

+25
-51
lines changed
  • drivers/platform/x86/intel/pmc

1 file changed

+25
-51
lines changed

drivers/platform/x86/intel/pmc/core.c

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -87,35 +87,26 @@ static int set_etr3(struct pmc_dev *pmcdev)
8787
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
8888
const struct pmc_reg_map *map = pmc->map;
8989
u32 reg;
90-
int err;
9190

9291
if (!map->etr3_offset)
9392
return -EOPNOTSUPP;
9493

95-
mutex_lock(&pmcdev->lock);
94+
guard(mutex)(&pmcdev->lock);
9695

9796
/* check if CF9 is locked */
9897
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;
103100

104101
/* write CF9 global reset bit */
105102
reg |= ETR3_CF9GR;
106103
pmc_core_reg_write(pmc, map->etr3_offset, reg);
107104

108105
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;
115108

116-
out_unlock:
117-
mutex_unlock(&pmcdev->lock);
118-
return err;
109+
return 0;
119110
}
120111
static umode_t etr3_is_visible(struct kobject *kobj,
121112
struct attribute *attr,
@@ -127,9 +118,8 @@ static umode_t etr3_is_visible(struct kobject *kobj,
127118
const struct pmc_reg_map *map = pmc->map;
128119
u32 reg;
129120

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);
133123

134124
return reg & ETR3_CF9LOCK ? attr->mode & (SYSFS_PREALLOC | 0444) : attr->mode;
135125
}
@@ -145,12 +135,10 @@ static ssize_t etr3_show(struct device *dev,
145135
if (!map->etr3_offset)
146136
return -EOPNOTSUPP;
147137

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+
}
154142

155143
return sysfs_emit(buf, "0x%08x", reg);
156144
}
@@ -401,18 +389,18 @@ static int pmc_core_mphy_pg_show(struct seq_file *s, void *unused)
401389
mphy_core_reg_low = (SPT_PMC_MPHY_CORE_STS_0 << 16);
402390
mphy_core_reg_high = (SPT_PMC_MPHY_CORE_STS_1 << 16);
403391

404-
mutex_lock(&pmcdev->lock);
392+
guard(mutex)(&pmcdev->lock);
405393

406394
err = pmc_core_send_msg(pmc, &mphy_core_reg_low);
407395
if (err)
408-
goto out_unlock;
396+
return err;
409397

410398
msleep(10);
411399
val_low = pmc_core_reg_read(pmc, SPT_PMC_MFPMC_OFFSET);
412400

413401
err = pmc_core_send_msg(pmc, &mphy_core_reg_high);
414402
if (err)
415-
goto out_unlock;
403+
return err;
416404

417405
msleep(10);
418406
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)
431419
"Power gated");
432420
}
433421

434-
out_unlock:
435-
mutex_unlock(&pmcdev->lock);
436-
return err;
422+
return 0;
437423
}
438424
DEFINE_SHOW_ATTRIBUTE(pmc_core_mphy_pg);
439425

@@ -451,11 +437,11 @@ static int pmc_core_pll_show(struct seq_file *s, void *unused)
451437
}
452438

453439
mphy_common_reg = (SPT_PMC_MPHY_COM_STS_0 << 16);
454-
mutex_lock(&pmcdev->lock);
440+
guard(mutex)(&pmcdev->lock);
455441

456442
err = pmc_core_send_msg(pmc, &mphy_common_reg);
457443
if (err)
458-
goto out_unlock;
444+
return err;
459445

460446
/* Observed PMC HW response latency for MTPMC-MFPMC is ~10 ms */
461447
msleep(10);
@@ -467,9 +453,7 @@ static int pmc_core_pll_show(struct seq_file *s, void *unused)
467453
map[index].bit_mask & val ? "Active" : "Idle");
468454
}
469455

470-
out_unlock:
471-
mutex_unlock(&pmcdev->lock);
472-
return err;
456+
return 0;
473457
}
474458
DEFINE_SHOW_ATTRIBUTE(pmc_core_pll);
475459

@@ -508,7 +492,7 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)
508492

509493
pr_debug("ltr_ignore for pmc%d: ltr_index:%d\n", pmc_index, ltr_index);
510494

511-
mutex_lock(&pmcdev->lock);
495+
guard(mutex)(&pmcdev->lock);
512496

513497
reg = pmc_core_reg_read(pmc, map->ltr_ignore_offset);
514498
if (ignore)
@@ -517,8 +501,6 @@ int pmc_core_send_ltr_ignore(struct pmc_dev *pmcdev, u32 value, int ignore)
517501
reg &= ~BIT(ltr_index);
518502
pmc_core_reg_write(pmc, map->ltr_ignore_offset, reg);
519503

520-
mutex_unlock(&pmcdev->lock);
521-
522504
return 0;
523505
}
524506

@@ -566,10 +548,10 @@ static void pmc_core_slps0_dbg_latch(struct pmc_dev *pmcdev, bool reset)
566548
const struct pmc_reg_map *map = pmc->map;
567549
u32 fd;
568550

569-
mutex_lock(&pmcdev->lock);
551+
guard(mutex)(&pmcdev->lock);
570552

571553
if (!reset && !slps0_dbg_latch)
572-
goto out_unlock;
554+
return;
573555

574556
fd = pmc_core_reg_read(pmc, map->slps0_dbg_offset);
575557
if (reset)
@@ -579,9 +561,6 @@ static void pmc_core_slps0_dbg_latch(struct pmc_dev *pmcdev, bool reset)
579561
pmc_core_reg_write(pmc, map->slps0_dbg_offset, fd);
580562

581563
slps0_dbg_latch = false;
582-
583-
out_unlock:
584-
mutex_unlock(&pmcdev->lock);
585564
}
586565

587566
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,
984963
}
985964

986965
if (clear) {
987-
mutex_lock(&pmcdev->lock);
966+
guard(mutex)(&pmcdev->lock);
988967

989968
reg = pmc_core_reg_read(pmc, pmc->map->etr3_offset);
990969
reg |= ETR3_CLEAR_LPM_EVENTS;
991970
pmc_core_reg_write(pmc, pmc->map->etr3_offset, reg);
992971

993-
mutex_unlock(&pmcdev->lock);
994-
995972
return count;
996973
}
997974

998975
if (c10) {
999-
mutex_lock(&pmcdev->lock);
976+
guard(mutex)(&pmcdev->lock);
1000977

1001978
reg = pmc_core_reg_read(pmc, pmc->map->lpm_sts_latch_en_offset);
1002979
reg &= ~LPM_STS_LATCH_MODE;
1003980
pmc_core_reg_write(pmc, pmc->map->lpm_sts_latch_en_offset, reg);
1004981

1005-
mutex_unlock(&pmcdev->lock);
1006-
1007982
return count;
1008983
}
1009984

@@ -1012,9 +987,8 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
1012987
* and clear everything else.
1013988
*/
1014989
reg = LPM_STS_LATCH_MODE | BIT(mode);
1015-
mutex_lock(&pmcdev->lock);
990+
guard(mutex)(&pmcdev->lock);
1016991
pmc_core_reg_write(pmc, pmc->map->lpm_sts_latch_en_offset, reg);
1017-
mutex_unlock(&pmcdev->lock);
1018992

1019993
return count;
1020994
}

0 commit comments

Comments
 (0)