Skip to content

Commit fe2f325

Browse files
committed
address review comments
Signed-off-by: Varun Ramachandra Sekar <[email protected]>
1 parent 30bc37a commit fe2f325

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

pkg/nvlib/device/mig_profile.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (d *devicelib) NewMigProfile(giProfileID, ciProfileID, ciEngProfileID int,
145145

146146
// AssertValidMigProfileFormat checks if the string is in the proper format to represent a MIG profile.
147147
func (d *devicelib) AssertValidMigProfileFormat(profile string) error {
148-
_, _, _, _, _, err := parseMigProfile(profile)
148+
_, err := parseMigProfile(profile)
149149
return err
150150
}
151151

@@ -211,23 +211,23 @@ func (p MigProfileInfo) Equals(other MigProfile) bool {
211211

212212
// Matches checks if a MigProfile matches the string passed in.
213213
func (p MigProfileInfo) Matches(profile string) bool {
214-
c, g, gb, attrs, negAttrs, err := parseMigProfile(profile)
214+
migProfileInfo, err := parseMigProfile(profile)
215215
if err != nil {
216216
return false
217217
}
218-
if c != p.C {
218+
if migProfileInfo.C != p.C {
219219
return false
220220
}
221-
if g != p.G {
221+
if migProfileInfo.G != p.G {
222222
return false
223223
}
224-
if gb != p.GB {
224+
if migProfileInfo.GB != p.GB {
225225
return false
226226
}
227-
if !matchAttributes(attrs, p.Attributes) {
227+
if !matchAttributes(migProfileInfo.Attributes, p.Attributes) {
228228
return false
229229
}
230-
if !matchAttributes(negAttrs, p.NegAttributes) {
230+
if !matchAttributes(migProfileInfo.NegAttributes, p.NegAttributes) {
231231
return false
232232
}
233233
return true
@@ -247,18 +247,18 @@ func matchAttributes(attrs1, attrs2 []string) bool {
247247
return true
248248
}
249249

250-
func parseMigProfile(profile string) (int, int, int, []string, []string, error) {
250+
func parseMigProfile(profile string) (*MigProfileInfo, error) {
251251
// If we are handed the empty string, we cannot parse it.
252252
if profile == "" {
253-
return -1, -1, -1, nil, nil, fmt.Errorf("profile is the empty string")
253+
return nil, fmt.Errorf("profile is the empty string")
254254
}
255255

256256
// Split by +/- to separate out attributes.
257257
split := strings.SplitN(profile, "+", 2)
258258
negsplit := strings.SplitN(profile, "-", 2)
259259
// Make sure we don't get both positive and negative attributes.
260260
if len(split) == 2 && len(negsplit) == 2 {
261-
return -1, -1, -1, nil, nil, fmt.Errorf("cannot parse profile '%v'", profile)
261+
return nil, fmt.Errorf("profile '%v' contains both '+/-' attributes", profile)
262262
}
263263

264264
if len(split) == 1 {
@@ -268,25 +268,32 @@ func parseMigProfile(profile string) (int, int, int, []string, []string, error)
268268
// Check to make sure the c, g, and gb values match.
269269
c, g, gb, err := parseMigProfileFields(split[0])
270270
if err != nil {
271-
return -1, -1, -1, nil, nil, fmt.Errorf("cannot parse fields of '%v': %v", profile, err)
271+
return nil, fmt.Errorf("cannot parse fields of '%v': %v", profile, err)
272272
}
273273

274+
migProfileInfo := &MigProfileInfo{
275+
C: c,
276+
G: g,
277+
GB: gb,
278+
}
274279
// If we have no attributes we are done.
275280
if len(split) == 1 {
276-
return c, g, gb, nil, nil, nil
281+
return migProfileInfo, nil
277282
}
278283

279284
// Make sure we have the same set of attributes.
280285
attrs, err := parseMigProfileAttributes(split[1])
281286
if err != nil {
282-
return -1, -1, -1, nil, nil, fmt.Errorf("cannot parse attributes of '%v': %v", profile, err)
287+
return nil, fmt.Errorf("cannot parse attributes of '%v': %v", profile, err)
283288
}
284289

285290
if len(negsplit) == 2 {
286-
return c, g, gb, nil, attrs, nil
291+
migProfileInfo.NegAttributes = attrs
292+
return migProfileInfo, nil
287293
}
288294

289-
return c, g, gb, attrs, nil, nil
295+
migProfileInfo.Attributes = attrs
296+
return migProfileInfo, nil
290297
}
291298

292299
func parseMigProfileField(s string, field string) (int, error) {

0 commit comments

Comments
 (0)