Commit e35ee8ee authored by Ilpo Järvinen's avatar Ilpo Järvinen Committed by Hans de Goede

platform/x86: intel/pmc: Remove unused param idx from pmc_for_each_mode()

pmc_for_each_mode() takes i (index) variable name as a parameter but
the loop index is not used by any of the callers. Make the index
variable internal to pmc_for_each_mode().

This also changes the loop logic such that ->lpm_en_modes[] is never
read beyond num_lpm_modes.
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240806083047.1562-1-ilpo.jarvinen@linux.intel.comReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 6c1fa8ed
...@@ -728,12 +728,11 @@ static int pmc_core_substate_res_show(struct seq_file *s, void *unused) ...@@ -728,12 +728,11 @@ static int pmc_core_substate_res_show(struct seq_file *s, void *unused)
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN]; struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
const int lpm_adj_x2 = pmc->map->lpm_res_counter_step_x2; const int lpm_adj_x2 = pmc->map->lpm_res_counter_step_x2;
u32 offset = pmc->map->lpm_residency_offset; u32 offset = pmc->map->lpm_residency_offset;
unsigned int i;
int mode; int mode;
seq_printf(s, "%-10s %-15s\n", "Substate", "Residency"); seq_printf(s, "%-10s %-15s\n", "Substate", "Residency");
pmc_for_each_mode(i, mode, pmcdev) { pmc_for_each_mode(mode, pmcdev) {
seq_printf(s, "%-10s %-15llu\n", pmc_lpm_modes[mode], seq_printf(s, "%-10s %-15llu\n", pmc_lpm_modes[mode],
adjust_lpm_residency(pmc, offset + (4 * mode), lpm_adj_x2)); adjust_lpm_residency(pmc, offset + (4 * mode), lpm_adj_x2));
} }
...@@ -787,11 +786,10 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_l_sts_regs); ...@@ -787,11 +786,10 @@ DEFINE_SHOW_ATTRIBUTE(pmc_core_substate_l_sts_regs);
static void pmc_core_substate_req_header_show(struct seq_file *s, int pmc_index) static void pmc_core_substate_req_header_show(struct seq_file *s, int pmc_index)
{ {
struct pmc_dev *pmcdev = s->private; struct pmc_dev *pmcdev = s->private;
unsigned int i;
int mode; int mode;
seq_printf(s, "%30s |", "Element"); seq_printf(s, "%30s |", "Element");
pmc_for_each_mode(i, mode, pmcdev) pmc_for_each_mode(mode, pmcdev)
seq_printf(s, " %9s |", pmc_lpm_modes[mode]); seq_printf(s, " %9s |", pmc_lpm_modes[mode]);
seq_printf(s, " %9s |", "Status"); seq_printf(s, " %9s |", "Status");
...@@ -837,14 +835,14 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused) ...@@ -837,14 +835,14 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused)
u32 lpm_status; u32 lpm_status;
u32 lpm_status_live; u32 lpm_status_live;
const struct pmc_bit_map *map; const struct pmc_bit_map *map;
int mode, idx, i, len = 32; int mode, i, len = 32;
/* /*
* Capture the requirements and create a mask so that we only * Capture the requirements and create a mask so that we only
* show an element if it's required for at least one of the * show an element if it's required for at least one of the
* enabled low power modes * enabled low power modes
*/ */
pmc_for_each_mode(idx, mode, pmcdev) pmc_for_each_mode(mode, pmcdev)
req_mask |= lpm_req_regs[mp + (mode * num_maps)]; req_mask |= lpm_req_regs[mp + (mode * num_maps)];
/* Get the last latched status for this map */ /* Get the last latched status for this map */
...@@ -870,7 +868,7 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused) ...@@ -870,7 +868,7 @@ static int pmc_core_substate_req_regs_show(struct seq_file *s, void *unused)
seq_printf(s, "pmc%d: %26s |", pmc_index, map[i].name); seq_printf(s, "pmc%d: %26s |", pmc_index, map[i].name);
/* Loop over the enabled states and display if required */ /* Loop over the enabled states and display if required */
pmc_for_each_mode(idx, mode, pmcdev) { pmc_for_each_mode(mode, pmcdev) {
bool required = lpm_req_regs[mp + (mode * num_maps)] & bool required = lpm_req_regs[mp + (mode * num_maps)] &
bit_mask; bit_mask;
seq_printf(s, " %9s |", required ? "Required" : " "); seq_printf(s, " %9s |", required ? "Required" : " ");
...@@ -935,7 +933,6 @@ static int pmc_core_lpm_latch_mode_show(struct seq_file *s, void *unused) ...@@ -935,7 +933,6 @@ static int pmc_core_lpm_latch_mode_show(struct seq_file *s, void *unused)
{ {
struct pmc_dev *pmcdev = s->private; struct pmc_dev *pmcdev = s->private;
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN]; struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
unsigned int idx;
bool c10; bool c10;
u32 reg; u32 reg;
int mode; int mode;
...@@ -949,7 +946,7 @@ static int pmc_core_lpm_latch_mode_show(struct seq_file *s, void *unused) ...@@ -949,7 +946,7 @@ static int pmc_core_lpm_latch_mode_show(struct seq_file *s, void *unused)
c10 = true; c10 = true;
} }
pmc_for_each_mode(idx, mode, pmcdev) { pmc_for_each_mode(mode, pmcdev) {
if ((BIT(mode) & reg) && !c10) if ((BIT(mode) & reg) && !c10)
seq_printf(s, " [%s]", pmc_lpm_modes[mode]); seq_printf(s, " [%s]", pmc_lpm_modes[mode]);
else else
...@@ -970,7 +967,6 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file, ...@@ -970,7 +967,6 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN]; struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
bool clear = false, c10 = false; bool clear = false, c10 = false;
unsigned char buf[8]; unsigned char buf[8];
unsigned int idx;
int m, mode; int m, mode;
u32 reg; u32 reg;
...@@ -989,7 +985,7 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file, ...@@ -989,7 +985,7 @@ static ssize_t pmc_core_lpm_latch_mode_write(struct file *file,
mode = sysfs_match_string(pmc_lpm_modes, buf); mode = sysfs_match_string(pmc_lpm_modes, buf);
/* Check string matches enabled mode */ /* Check string matches enabled mode */
pmc_for_each_mode(idx, m, pmcdev) pmc_for_each_mode(m, pmcdev)
if (mode == m) if (mode == m)
break; break;
......
...@@ -604,10 +604,12 @@ int lnl_core_init(struct pmc_dev *pmcdev); ...@@ -604,10 +604,12 @@ int lnl_core_init(struct pmc_dev *pmcdev);
void cnl_suspend(struct pmc_dev *pmcdev); void cnl_suspend(struct pmc_dev *pmcdev);
int cnl_resume(struct pmc_dev *pmcdev); int cnl_resume(struct pmc_dev *pmcdev);
#define pmc_for_each_mode(i, mode, pmcdev) \ #define pmc_for_each_mode(mode, pmcdev) \
for (i = 0, mode = pmcdev->lpm_en_modes[i]; \ for (unsigned int __i = 0, __cond; \
i < pmcdev->num_lpm_modes; \ __cond = __i < (pmcdev)->num_lpm_modes, \
i++, mode = pmcdev->lpm_en_modes[i]) __cond && ((mode) = (pmcdev)->lpm_en_modes[__i]), \
__cond; \
__i++)
#define DEFINE_PMC_CORE_ATTR_WRITE(__name) \ #define DEFINE_PMC_CORE_ATTR_WRITE(__name) \
static int __name ## _open(struct inode *inode, struct file *file) \ static int __name ## _open(struct inode *inode, struct file *file) \
......
...@@ -45,7 +45,7 @@ static int pmc_core_get_lpm_req(struct pmc_dev *pmcdev, struct pmc *pmc) ...@@ -45,7 +45,7 @@ static int pmc_core_get_lpm_req(struct pmc_dev *pmcdev, struct pmc *pmc)
struct telem_endpoint *ep; struct telem_endpoint *ep;
const u8 *lpm_indices; const u8 *lpm_indices;
int num_maps, mode_offset = 0; int num_maps, mode_offset = 0;
int ret, mode, i; int ret, mode;
int lpm_size; int lpm_size;
u32 guid; u32 guid;
...@@ -116,7 +116,7 @@ static int pmc_core_get_lpm_req(struct pmc_dev *pmcdev, struct pmc *pmc) ...@@ -116,7 +116,7 @@ static int pmc_core_get_lpm_req(struct pmc_dev *pmcdev, struct pmc *pmc)
* *
*/ */
mode_offset = LPM_HEADER_OFFSET + LPM_MODE_OFFSET; mode_offset = LPM_HEADER_OFFSET + LPM_MODE_OFFSET;
pmc_for_each_mode(i, mode, pmcdev) { pmc_for_each_mode(mode, pmcdev) {
u32 *req_offset = pmc->lpm_req_regs + (mode * num_maps); u32 *req_offset = pmc->lpm_req_regs + (mode * num_maps);
int m; int m;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment