@@ -363,9 +363,7 @@ static void free_msi_irqs(struct pci_dev *dev)
363
363
{
364
364
struct list_head * msi_list = dev_to_msi_list (& dev -> dev );
365
365
struct msi_desc * entry , * tmp ;
366
- struct attribute * * msi_attrs ;
367
- struct device_attribute * dev_attr ;
368
- int i , count = 0 ;
366
+ int i ;
369
367
370
368
for_each_pci_msi_entry (entry , dev )
371
369
if (entry -> irq )
@@ -385,18 +383,7 @@ static void free_msi_irqs(struct pci_dev *dev)
385
383
}
386
384
387
385
if (dev -> msi_irq_groups ) {
388
- sysfs_remove_groups (& dev -> dev .kobj , dev -> msi_irq_groups );
389
- msi_attrs = dev -> msi_irq_groups [0 ]-> attrs ;
390
- while (msi_attrs [count ]) {
391
- dev_attr = container_of (msi_attrs [count ],
392
- struct device_attribute , attr );
393
- kfree (dev_attr -> attr .name );
394
- kfree (dev_attr );
395
- ++ count ;
396
- }
397
- kfree (msi_attrs );
398
- kfree (dev -> msi_irq_groups [0 ]);
399
- kfree (dev -> msi_irq_groups );
386
+ msi_destroy_sysfs (& dev -> dev , dev -> msi_irq_groups );
400
387
dev -> msi_irq_groups = NULL ;
401
388
}
402
389
}
@@ -476,102 +463,6 @@ void pci_restore_msi_state(struct pci_dev *dev)
476
463
}
477
464
EXPORT_SYMBOL_GPL (pci_restore_msi_state );
478
465
479
- static ssize_t msi_mode_show (struct device * dev , struct device_attribute * attr ,
480
- char * buf )
481
- {
482
- struct msi_desc * entry ;
483
- unsigned long irq ;
484
- int retval ;
485
-
486
- retval = kstrtoul (attr -> attr .name , 10 , & irq );
487
- if (retval )
488
- return retval ;
489
-
490
- entry = irq_get_msi_desc (irq );
491
- if (!entry )
492
- return - ENODEV ;
493
-
494
- return sysfs_emit (buf , "%s\n" ,
495
- entry -> msi_attrib .is_msix ? "msix" : "msi" );
496
- }
497
-
498
- static int populate_msi_sysfs (struct pci_dev * pdev )
499
- {
500
- struct attribute * * msi_attrs ;
501
- struct attribute * msi_attr ;
502
- struct device_attribute * msi_dev_attr ;
503
- struct attribute_group * msi_irq_group ;
504
- const struct attribute_group * * msi_irq_groups ;
505
- struct msi_desc * entry ;
506
- int ret = - ENOMEM ;
507
- int num_msi = 0 ;
508
- int count = 0 ;
509
- int i ;
510
-
511
- /* Determine how many msi entries we have */
512
- for_each_pci_msi_entry (entry , pdev )
513
- num_msi += entry -> nvec_used ;
514
- if (!num_msi )
515
- return 0 ;
516
-
517
- /* Dynamically create the MSI attributes for the PCI device */
518
- msi_attrs = kcalloc (num_msi + 1 , sizeof (void * ), GFP_KERNEL );
519
- if (!msi_attrs )
520
- return - ENOMEM ;
521
- for_each_pci_msi_entry (entry , pdev ) {
522
- for (i = 0 ; i < entry -> nvec_used ; i ++ ) {
523
- msi_dev_attr = kzalloc (sizeof (* msi_dev_attr ), GFP_KERNEL );
524
- if (!msi_dev_attr )
525
- goto error_attrs ;
526
- msi_attrs [count ] = & msi_dev_attr -> attr ;
527
-
528
- sysfs_attr_init (& msi_dev_attr -> attr );
529
- msi_dev_attr -> attr .name = kasprintf (GFP_KERNEL , "%d" ,
530
- entry -> irq + i );
531
- if (!msi_dev_attr -> attr .name )
532
- goto error_attrs ;
533
- msi_dev_attr -> attr .mode = S_IRUGO ;
534
- msi_dev_attr -> show = msi_mode_show ;
535
- ++ count ;
536
- }
537
- }
538
-
539
- msi_irq_group = kzalloc (sizeof (* msi_irq_group ), GFP_KERNEL );
540
- if (!msi_irq_group )
541
- goto error_attrs ;
542
- msi_irq_group -> name = "msi_irqs" ;
543
- msi_irq_group -> attrs = msi_attrs ;
544
-
545
- msi_irq_groups = kcalloc (2 , sizeof (void * ), GFP_KERNEL );
546
- if (!msi_irq_groups )
547
- goto error_irq_group ;
548
- msi_irq_groups [0 ] = msi_irq_group ;
549
-
550
- ret = sysfs_create_groups (& pdev -> dev .kobj , msi_irq_groups );
551
- if (ret )
552
- goto error_irq_groups ;
553
- pdev -> msi_irq_groups = msi_irq_groups ;
554
-
555
- return 0 ;
556
-
557
- error_irq_groups :
558
- kfree (msi_irq_groups );
559
- error_irq_group :
560
- kfree (msi_irq_group );
561
- error_attrs :
562
- count = 0 ;
563
- msi_attr = msi_attrs [count ];
564
- while (msi_attr ) {
565
- msi_dev_attr = container_of (msi_attr , struct device_attribute , attr );
566
- kfree (msi_attr -> name );
567
- kfree (msi_dev_attr );
568
- ++ count ;
569
- msi_attr = msi_attrs [count ];
570
- }
571
- kfree (msi_attrs );
572
- return ret ;
573
- }
574
-
575
466
static struct msi_desc *
576
467
msi_setup_entry (struct pci_dev * dev , int nvec , struct irq_affinity * affd )
577
468
{
@@ -667,9 +558,11 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
667
558
if (ret )
668
559
goto err ;
669
560
670
- ret = populate_msi_sysfs (dev );
671
- if (ret )
561
+ dev -> msi_irq_groups = msi_populate_sysfs (& dev -> dev );
562
+ if (IS_ERR (dev -> msi_irq_groups )) {
563
+ ret = PTR_ERR (dev -> msi_irq_groups );
672
564
goto err ;
565
+ }
673
566
674
567
/* Set MSI enabled bits */
675
568
pci_intx_for_msi (dev , 0 );
@@ -834,9 +727,11 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
834
727
835
728
msix_update_entries (dev , entries );
836
729
837
- ret = populate_msi_sysfs (dev );
838
- if (ret )
730
+ dev -> msi_irq_groups = msi_populate_sysfs (& dev -> dev );
731
+ if (IS_ERR (dev -> msi_irq_groups )) {
732
+ ret = PTR_ERR (dev -> msi_irq_groups );
839
733
goto out_free ;
734
+ }
840
735
841
736
/* Set MSI-X enabled bits and unmask the function */
842
737
pci_intx_for_msi (dev , 0 );
0 commit comments