2929 ErrKeyExist = errors .New ("key already exists" )
3030 ErrIterationAborted = errors .New ("iteration aborted" )
3131 ErrMapIncompatible = errors .New ("map spec is incompatible with existing map" )
32- errMapNoBTFValue = errors .New ("map spec does not contain a BTF Value" )
3332
3433 // pre-allocating these errors here since they may get called in hot code paths
3534 // and cause unnecessary memory allocations
@@ -187,32 +186,23 @@ func (spec *MapSpec) fixupMagicFields() (*MapSpec, error) {
187186 return spec , nil
188187}
189188
190- // dataSection returns the contents and BTF Datasec descriptor of the spec.
191- func (ms * MapSpec ) dataSection () ([]byte , * btf.Datasec , error ) {
192- if ms .Value == nil {
193- return nil , nil , errMapNoBTFValue
194- }
195-
196- ds , ok := ms .Value .(* btf.Datasec )
197- if ! ok {
198- return nil , nil , fmt .Errorf ("map value BTF is a %T, not a *btf.Datasec" , ms .Value )
199- }
200-
189+ // dataSection returns the contents of a datasec if the MapSpec represents one.
190+ func (ms * MapSpec ) dataSection () ([]byte , error ) {
201191 if n := len (ms .Contents ); n != 1 {
202- return nil , nil , fmt .Errorf ("expected one key, found %d" , n )
192+ return nil , fmt .Errorf ("expected one key, found %d" , n )
203193 }
204194
205195 kv := ms .Contents [0 ]
206196 if key , ok := ms .Contents [0 ].Key .(uint32 ); ! ok || key != 0 {
207- return nil , nil , fmt .Errorf ("expected contents to have key 0" )
197+ return nil , fmt .Errorf ("expected contents to have key 0" )
208198 }
209199
210200 value , ok := kv .Value .([]byte )
211201 if ! ok {
212- return nil , nil , fmt .Errorf ("value at first map key is %T, not []byte" , kv .Value )
202+ return nil , fmt .Errorf ("value at first map key is %T, not []byte" , kv .Value )
213203 }
214204
215- return value , ds , nil
205+ return value , nil
216206}
217207
218208// updateDataSection copies the values of variables into MapSpec.Contents[0].Value.
@@ -232,7 +222,7 @@ func (ms *MapSpec) updateDataSection(vars map[string]*VariableSpec, sectionName
232222 return nil
233223 }
234224
235- data , _ , err := ms .dataSection ()
225+ data , err := ms .dataSection ()
236226 if err != nil {
237227 return err
238228 }
0 commit comments