Skip to content

Commit 066450b

Browse files
committed
perf/x86/intel/pt: Clean up the control flow in pt_pmu_hw_init()
Dan Carpenter pointed out that the control flow in pt_pmu_hw_init() is a bit messy: for example the kfree(de_attrs) is entirely superfluous. Another problem is the inconsistent mixing of label based and direct return error handling. Add modern, label based error handling instead and clean up the code a bit as well. Note that we'll still do a kfree(NULL) in the normal case - this does not matter as this is an init path and kfree() returns early if it sees a NULL. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/20150409090805.GG17605@mwanda Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5dafd7c commit 066450b

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

‎arch/x86/kernel/cpu/perf_event_intel_pt.c‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,48 +119,55 @@ static int __init pt_pmu_hw_init(void)
119119
struct dev_ext_attribute *de_attrs;
120120
struct attribute **attrs;
121121
size_t size;
122+
int ret;
122123
long i;
123124

124-
if (test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT)) {
125-
for (i = 0; i < PT_CPUID_LEAVES; i++)
126-
cpuid_count(20, i,
127-
&pt_pmu.caps[CR_EAX + i * 4],
128-
&pt_pmu.caps[CR_EBX + i * 4],
129-
&pt_pmu.caps[CR_ECX + i * 4],
130-
&pt_pmu.caps[CR_EDX + i * 4]);
131-
} else {
132-
return -ENODEV;
125+
attrs = NULL;
126+
ret = -ENODEV;
127+
if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
128+
goto fail;
129+
130+
for (i = 0; i < PT_CPUID_LEAVES; i++) {
131+
cpuid_count(20, i,
132+
&pt_pmu.caps[CR_EAX + i*4],
133+
&pt_pmu.caps[CR_EBX + i*4],
134+
&pt_pmu.caps[CR_ECX + i*4],
135+
&pt_pmu.caps[CR_EDX + i*4]);
133136
}
134137

135-
size = sizeof(struct attribute *) * (ARRAY_SIZE(pt_caps) + 1);
138+
ret = -ENOMEM;
139+
size = sizeof(struct attribute *) * (ARRAY_SIZE(pt_caps)+1);
136140
attrs = kzalloc(size, GFP_KERNEL);
137141
if (!attrs)
138-
goto err_attrs;
142+
goto fail;
139143

140-
size = sizeof(struct dev_ext_attribute) * (ARRAY_SIZE(pt_caps) + 1);
144+
size = sizeof(struct dev_ext_attribute) * (ARRAY_SIZE(pt_caps)+1);
141145
de_attrs = kzalloc(size, GFP_KERNEL);
142146
if (!de_attrs)
143-
goto err_de_attrs;
147+
goto fail;
144148

145149
for (i = 0; i < ARRAY_SIZE(pt_caps); i++) {
146-
de_attrs[i].attr.attr.name = pt_caps[i].name;
150+
struct dev_ext_attribute *de_attr = de_attrs + i;
151+
152+
de_attr->attr.attr.name = pt_caps[i].name;
153+
154+
sysfs_attr_init(&de_attrs->attr.attr);
147155

148-
sysfs_attr_init(&de_attrs[i].attr.attr);
149-
de_attrs[i].attr.attr.mode = S_IRUGO;
150-
de_attrs[i].attr.show = pt_cap_show;
151-
de_attrs[i].var = (void *)i;
152-
attrs[i] = &de_attrs[i].attr.attr;
156+
de_attr->attr.attr.mode = S_IRUGO;
157+
de_attr->attr.show = pt_cap_show;
158+
de_attr->var = (void *)i;
159+
160+
attrs[i] = &de_attr->attr.attr;
153161
}
154162

155163
pt_cap_group.attrs = attrs;
164+
156165
return 0;
157166

158-
err_de_attrs:
159-
kfree(de_attrs);
160-
err_attrs:
167+
fail:
161168
kfree(attrs);
162169

163-
return -ENOMEM;
170+
return ret;
164171
}
165172

166173
#define PT_CONFIG_MASK (RTIT_CTL_TSC_EN | RTIT_CTL_DISRETC)

0 commit comments

Comments
 (0)