@@ -157,49 +157,41 @@ func (m *Manager) parseDevice(dev *pb.CDIDevice, all []string) ([]string, error)
157
157
158
158
kind , name , _ := strings .Cut (dev .Name , "=" )
159
159
160
- // validate kind
161
- if vendor , class := parser .ParseQualifier (kind ); vendor == "" {
162
- return nil , errors .Errorf ("invalid device %q" , dev .Name )
163
- } else if err := parser .ValidateVendorName (vendor ); err != nil {
164
- return nil , errors .Wrapf (err , "invalid device %q" , dev .Name )
165
- } else if err := parser .ValidateClassName (class ); err != nil {
166
- return nil , errors .Wrapf (err , "invalid device %q" , dev .Name )
167
- }
168
-
169
- switch name {
170
- case "" :
171
- // first device of kind if no name is specified
172
- for _ , d := range all {
173
- if strings .HasPrefix (d , kind + "=" ) {
174
- out = append (out , d )
175
- break
176
- }
177
- }
178
- case "*" :
179
- // all devices of kind if the name is a wildcard
180
- for _ , d := range all {
181
- if strings .HasPrefix (d , kind + "=" ) {
182
- out = append (out , d )
160
+ vendor , _ := parser .ParseQualifier (kind )
161
+ if vendor != "" {
162
+ switch name {
163
+ case "" :
164
+ // first device of kind if no name is specified
165
+ for _ , d := range all {
166
+ if strings .HasPrefix (d , kind + "=" ) {
167
+ out = append (out , d )
168
+ break
169
+ }
183
170
}
184
- }
185
- default :
186
- // the specified device
187
- for _ , d := range all {
188
- if d == dev .Name {
189
- out = append (out , d )
190
- break
171
+ case "*" :
172
+ // all devices of kind if the name is a wildcard
173
+ for _ , d := range all {
174
+ if strings .HasPrefix (d , kind + "=" ) {
175
+ out = append (out , d )
176
+ }
191
177
}
192
- }
193
- if len (out ) == 0 {
194
- // check class annotation if name unknown
178
+ default :
179
+ // the specified device
195
180
for _ , d := range all {
196
- if ! strings .HasPrefix (d , kind + "=" ) {
197
- continue
181
+ if d == dev .Name {
182
+ out = append (out , d )
183
+ break
198
184
}
199
- if a := deviceAnnotations (m .cache .GetDevice (d )); a != nil {
200
- if class , ok := a [deviceAnnotationClass ]; ok && class == name {
201
- out = append (out , d )
202
- }
185
+ }
186
+ }
187
+ }
188
+
189
+ // check class annotation if device qualifier invalid or no device found
190
+ if vendor == "" || len (out ) == 0 {
191
+ for _ , d := range all {
192
+ if a := deviceAnnotations (m .cache .GetDevice (d )); a != nil {
193
+ if class , ok := a [deviceAnnotationClass ]; ok && class == dev .Name {
194
+ out = append (out , d )
203
195
}
204
196
}
205
197
}
0 commit comments