@@ -822,11 +822,6 @@ static ssize_t i915_pmu_event_show(struct device *dev,
822
822
return sprintf (buf , "config=0x%lx\n" , eattr -> val );
823
823
}
824
824
825
- static struct attribute_group i915_pmu_events_attr_group = {
826
- .name = "events" ,
827
- /* Patch in attrs at runtime. */
828
- };
829
-
830
825
static ssize_t
831
826
i915_pmu_get_attr_cpumask (struct device * dev ,
832
827
struct device_attribute * attr ,
@@ -846,13 +841,6 @@ static const struct attribute_group i915_pmu_cpumask_attr_group = {
846
841
.attrs = i915_cpumask_attrs ,
847
842
};
848
843
849
- static const struct attribute_group * i915_pmu_attr_groups [] = {
850
- & i915_pmu_format_attr_group ,
851
- & i915_pmu_events_attr_group ,
852
- & i915_pmu_cpumask_attr_group ,
853
- NULL
854
- };
855
-
856
844
#define __event (__config , __name , __unit ) \
857
845
{ \
858
846
.config = (__config), \
@@ -1026,16 +1014,16 @@ err:;
1026
1014
1027
1015
static void free_event_attributes (struct i915_pmu * pmu )
1028
1016
{
1029
- struct attribute * * attr_iter = i915_pmu_events_attr_group .attrs ;
1017
+ struct attribute * * attr_iter = pmu -> events_attr_group .attrs ;
1030
1018
1031
1019
for (; * attr_iter ; attr_iter ++ )
1032
1020
kfree ((* attr_iter )-> name );
1033
1021
1034
- kfree (i915_pmu_events_attr_group .attrs );
1022
+ kfree (pmu -> events_attr_group .attrs );
1035
1023
kfree (pmu -> i915_attr );
1036
1024
kfree (pmu -> pmu_attr );
1037
1025
1038
- i915_pmu_events_attr_group .attrs = NULL ;
1026
+ pmu -> events_attr_group .attrs = NULL ;
1039
1027
pmu -> i915_attr = NULL ;
1040
1028
pmu -> pmu_attr = NULL ;
1041
1029
}
@@ -1117,6 +1105,13 @@ static bool is_igp(struct drm_i915_private *i915)
1117
1105
void i915_pmu_register (struct drm_i915_private * i915 )
1118
1106
{
1119
1107
struct i915_pmu * pmu = & i915 -> pmu ;
1108
+ const struct attribute_group * attr_groups [] = {
1109
+ & i915_pmu_format_attr_group ,
1110
+ & pmu -> events_attr_group ,
1111
+ & i915_pmu_cpumask_attr_group ,
1112
+ NULL
1113
+ };
1114
+
1120
1115
int ret = - ENOMEM ;
1121
1116
1122
1117
if (INTEL_GEN (i915 ) <= 2 ) {
@@ -1143,11 +1138,16 @@ void i915_pmu_register(struct drm_i915_private *i915)
1143
1138
if (!pmu -> name )
1144
1139
goto err ;
1145
1140
1146
- i915_pmu_events_attr_group .attrs = create_event_attributes (pmu );
1147
- if (!i915_pmu_events_attr_group .attrs )
1141
+ pmu -> events_attr_group .name = "events" ;
1142
+ pmu -> events_attr_group .attrs = create_event_attributes (pmu );
1143
+ if (!pmu -> events_attr_group .attrs )
1148
1144
goto err_name ;
1149
1145
1150
- pmu -> base .attr_groups = i915_pmu_attr_groups ;
1146
+ pmu -> base .attr_groups = kmemdup (attr_groups , sizeof (attr_groups ),
1147
+ GFP_KERNEL );
1148
+ if (!pmu -> base .attr_groups )
1149
+ goto err_attr ;
1150
+
1151
1151
pmu -> base .task_ctx_nr = perf_invalid_context ;
1152
1152
pmu -> base .event_init = i915_pmu_event_init ;
1153
1153
pmu -> base .add = i915_pmu_event_add ;
@@ -1159,7 +1159,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
1159
1159
1160
1160
ret = perf_pmu_register (& pmu -> base , pmu -> name , -1 );
1161
1161
if (ret )
1162
- goto err_attr ;
1162
+ goto err_groups ;
1163
1163
1164
1164
ret = i915_pmu_register_cpuhp_state (pmu );
1165
1165
if (ret )
@@ -1169,6 +1169,8 @@ void i915_pmu_register(struct drm_i915_private *i915)
1169
1169
1170
1170
err_unreg :
1171
1171
perf_pmu_unregister (& pmu -> base );
1172
+ err_groups :
1173
+ kfree (pmu -> base .attr_groups );
1172
1174
err_attr :
1173
1175
pmu -> base .event_init = NULL ;
1174
1176
free_event_attributes (pmu );
@@ -1194,6 +1196,7 @@ void i915_pmu_unregister(struct drm_i915_private *i915)
1194
1196
1195
1197
perf_pmu_unregister (& pmu -> base );
1196
1198
pmu -> base .event_init = NULL ;
1199
+ kfree (pmu -> base .attr_groups );
1197
1200
if (!is_igp (i915 ))
1198
1201
kfree (pmu -> name );
1199
1202
free_event_attributes (pmu );
0 commit comments