Skip to content

Commit f2adfe1

Browse files
anjutsudhakargregkh
authored andcommitted
powerpc/powernv: Avoid re-registration of imc debugfs directory
[ Upstream commit 48e626a ] export_imc_mode_and_cmd() function which creates the debugfs interface for imc-mode and imc-command, is invoked when each nest pmu units is registered. When the first nest pmu unit is registered, export_imc_mode_and_cmd() creates 'imc' directory under `/debug/powerpc/`. In the subsequent invocations debugfs_create_dir() function returns, since the directory already exists. The recent commit <c33d442328f55> (debugfs: make error message a bit more verbose), throws a warning if we try to invoke `debugfs_create_dir()` with an already existing directory name. Address this warning by making the debugfs directory registration in the opal_imc_counters_probe() function, i.e invoke export_imc_mode_and_cmd() function from the probe function. Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com> Tested-by: Nageswara R Sastry <nasastry@in.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20191127072035.4283-1-anju@linux.vnet.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a293045 commit f2adfe1

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

‎arch/powerpc/platforms/powernv/opal-imc.c‎

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ static void export_imc_mode_and_cmd(struct device_node *node,
5959

6060
imc_debugfs_parent = debugfs_create_dir("imc", powerpc_debugfs_root);
6161

62-
/*
63-
* Return here, either because 'imc' directory already exists,
64-
* Or failed to create a new one.
65-
*/
6662
if (!imc_debugfs_parent)
6763
return;
6864

@@ -135,7 +131,6 @@ static int imc_get_mem_addr_nest(struct device_node *node,
135131
}
136132

137133
pmu_ptr->imc_counter_mmaped = true;
138-
export_imc_mode_and_cmd(node, pmu_ptr);
139134
kfree(base_addr_arr);
140135
kfree(chipid_arr);
141136
return 0;
@@ -151,35 +146,31 @@ static int imc_get_mem_addr_nest(struct device_node *node,
151146
* and domain as the inputs.
152147
* Allocates memory for the struct imc_pmu, sets up its domain, size and offsets
153148
*/
154-
static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain)
149+
static struct imc_pmu *imc_pmu_create(struct device_node *parent, int pmu_index, int domain)
155150
{
156151
int ret = 0;
157152
struct imc_pmu *pmu_ptr;
158153
u32 offset;
159154

160155
/* Return for unknown domain */
161156
if (domain < 0)
162-
return -EINVAL;
157+
return NULL;
163158

164159
/* memory for pmu */
165160
pmu_ptr = kzalloc(sizeof(*pmu_ptr), GFP_KERNEL);
166161
if (!pmu_ptr)
167-
return -ENOMEM;
162+
return NULL;
168163

169164
/* Set the domain */
170165
pmu_ptr->domain = domain;
171166

172167
ret = of_property_read_u32(parent, "size", &pmu_ptr->counter_mem_size);
173-
if (ret) {
174-
ret = -EINVAL;
168+
if (ret)
175169
goto free_pmu;
176-
}
177170

178171
if (!of_property_read_u32(parent, "offset", &offset)) {
179-
if (imc_get_mem_addr_nest(parent, pmu_ptr, offset)) {
180-
ret = -EINVAL;
172+
if (imc_get_mem_addr_nest(parent, pmu_ptr, offset))
181173
goto free_pmu;
182-
}
183174
}
184175

185176
/* Function to register IMC pmu */
@@ -190,14 +181,14 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain)
190181
if (pmu_ptr->domain == IMC_DOMAIN_NEST)
191182
kfree(pmu_ptr->mem_info);
192183
kfree(pmu_ptr);
193-
return ret;
184+
return NULL;
194185
}
195186

196-
return 0;
187+
return pmu_ptr;
197188

198189
free_pmu:
199190
kfree(pmu_ptr);
200-
return ret;
191+
return NULL;
201192
}
202193

203194
static void disable_nest_pmu_counters(void)
@@ -254,6 +245,7 @@ int get_max_nest_dev(void)
254245
static int opal_imc_counters_probe(struct platform_device *pdev)
255246
{
256247
struct device_node *imc_dev = pdev->dev.of_node;
248+
struct imc_pmu *pmu;
257249
int pmu_count = 0, domain;
258250
bool core_imc_reg = false, thread_imc_reg = false;
259251
u32 type;
@@ -269,6 +261,7 @@ static int opal_imc_counters_probe(struct platform_device *pdev)
269261
}
270262

271263
for_each_compatible_node(imc_dev, NULL, IMC_DTB_UNIT_COMPAT) {
264+
pmu = NULL;
272265
if (of_property_read_u32(imc_dev, "type", &type)) {
273266
pr_warn("IMC Device without type property\n");
274267
continue;
@@ -300,20 +293,20 @@ static int opal_imc_counters_probe(struct platform_device *pdev)
300293
break;
301294
}
302295

303-
if (!imc_pmu_create(imc_dev, pmu_count, domain)) {
304-
if (domain == IMC_DOMAIN_NEST)
296+
pmu = imc_pmu_create(imc_dev, pmu_count, domain);
297+
if (pmu != NULL) {
298+
if (domain == IMC_DOMAIN_NEST) {
299+
if (!imc_debugfs_parent)
300+
export_imc_mode_and_cmd(imc_dev, pmu);
305301
pmu_count++;
302+
}
306303
if (domain == IMC_DOMAIN_CORE)
307304
core_imc_reg = true;
308305
if (domain == IMC_DOMAIN_THREAD)
309306
thread_imc_reg = true;
310307
}
311308
}
312309

313-
/* If none of the nest units are registered, remove debugfs interface */
314-
if (pmu_count == 0)
315-
debugfs_remove_recursive(imc_debugfs_parent);
316-
317310
/* If core imc is not registered, unregister thread-imc */
318311
if (!core_imc_reg && thread_imc_reg)
319312
unregister_thread_imc();

0 commit comments

Comments
 (0)