@@ -1515,91 +1515,97 @@ static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *ti
1515
1515
id -> subdevice = timer -> tmr_subdevice ;
1516
1516
}
1517
1517
1518
- static int snd_timer_user_next_device (struct snd_timer_id __user * _tid )
1518
+ static void get_next_device (struct snd_timer_id * id )
1519
1519
{
1520
- struct snd_timer_id id ;
1521
1520
struct snd_timer * timer ;
1522
1521
struct list_head * p ;
1523
1522
1524
- if (copy_from_user (& id , _tid , sizeof (id )))
1525
- return - EFAULT ;
1526
- guard (mutex )(& register_mutex );
1527
- if (id .dev_class < 0 ) { /* first item */
1523
+ if (id -> dev_class < 0 ) { /* first item */
1528
1524
if (list_empty (& snd_timer_list ))
1529
- snd_timer_user_zero_id (& id );
1525
+ snd_timer_user_zero_id (id );
1530
1526
else {
1531
1527
timer = list_entry (snd_timer_list .next ,
1532
1528
struct snd_timer , device_list );
1533
- snd_timer_user_copy_id (& id , timer );
1529
+ snd_timer_user_copy_id (id , timer );
1534
1530
}
1535
1531
} else {
1536
- switch (id . dev_class ) {
1532
+ switch (id -> dev_class ) {
1537
1533
case SNDRV_TIMER_CLASS_GLOBAL :
1538
- id . device = id . device < 0 ? 0 : id . device + 1 ;
1534
+ id -> device = id -> device < 0 ? 0 : id -> device + 1 ;
1539
1535
list_for_each (p , & snd_timer_list ) {
1540
1536
timer = list_entry (p , struct snd_timer , device_list );
1541
1537
if (timer -> tmr_class > SNDRV_TIMER_CLASS_GLOBAL ) {
1542
- snd_timer_user_copy_id (& id , timer );
1538
+ snd_timer_user_copy_id (id , timer );
1543
1539
break ;
1544
1540
}
1545
- if (timer -> tmr_device >= id . device ) {
1546
- snd_timer_user_copy_id (& id , timer );
1541
+ if (timer -> tmr_device >= id -> device ) {
1542
+ snd_timer_user_copy_id (id , timer );
1547
1543
break ;
1548
1544
}
1549
1545
}
1550
1546
if (p == & snd_timer_list )
1551
- snd_timer_user_zero_id (& id );
1547
+ snd_timer_user_zero_id (id );
1552
1548
break ;
1553
1549
case SNDRV_TIMER_CLASS_CARD :
1554
1550
case SNDRV_TIMER_CLASS_PCM :
1555
- if (id . card < 0 ) {
1556
- id . card = 0 ;
1551
+ if (id -> card < 0 ) {
1552
+ id -> card = 0 ;
1557
1553
} else {
1558
- if (id . device < 0 ) {
1559
- id . device = 0 ;
1554
+ if (id -> device < 0 ) {
1555
+ id -> device = 0 ;
1560
1556
} else {
1561
- if (id . subdevice < 0 )
1562
- id . subdevice = 0 ;
1563
- else if (id . subdevice < INT_MAX )
1564
- id . subdevice ++ ;
1557
+ if (id -> subdevice < 0 )
1558
+ id -> subdevice = 0 ;
1559
+ else if (id -> subdevice < INT_MAX )
1560
+ id -> subdevice ++ ;
1565
1561
}
1566
1562
}
1567
1563
list_for_each (p , & snd_timer_list ) {
1568
1564
timer = list_entry (p , struct snd_timer , device_list );
1569
- if (timer -> tmr_class > id . dev_class ) {
1570
- snd_timer_user_copy_id (& id , timer );
1565
+ if (timer -> tmr_class > id -> dev_class ) {
1566
+ snd_timer_user_copy_id (id , timer );
1571
1567
break ;
1572
1568
}
1573
- if (timer -> tmr_class < id . dev_class )
1569
+ if (timer -> tmr_class < id -> dev_class )
1574
1570
continue ;
1575
- if (timer -> card -> number > id . card ) {
1576
- snd_timer_user_copy_id (& id , timer );
1571
+ if (timer -> card -> number > id -> card ) {
1572
+ snd_timer_user_copy_id (id , timer );
1577
1573
break ;
1578
1574
}
1579
- if (timer -> card -> number < id . card )
1575
+ if (timer -> card -> number < id -> card )
1580
1576
continue ;
1581
- if (timer -> tmr_device > id . device ) {
1582
- snd_timer_user_copy_id (& id , timer );
1577
+ if (timer -> tmr_device > id -> device ) {
1578
+ snd_timer_user_copy_id (id , timer );
1583
1579
break ;
1584
1580
}
1585
- if (timer -> tmr_device < id . device )
1581
+ if (timer -> tmr_device < id -> device )
1586
1582
continue ;
1587
- if (timer -> tmr_subdevice > id . subdevice ) {
1588
- snd_timer_user_copy_id (& id , timer );
1583
+ if (timer -> tmr_subdevice > id -> subdevice ) {
1584
+ snd_timer_user_copy_id (id , timer );
1589
1585
break ;
1590
1586
}
1591
- if (timer -> tmr_subdevice < id . subdevice )
1587
+ if (timer -> tmr_subdevice < id -> subdevice )
1592
1588
continue ;
1593
- snd_timer_user_copy_id (& id , timer );
1589
+ snd_timer_user_copy_id (id , timer );
1594
1590
break ;
1595
1591
}
1596
1592
if (p == & snd_timer_list )
1597
- snd_timer_user_zero_id (& id );
1593
+ snd_timer_user_zero_id (id );
1598
1594
break ;
1599
1595
default :
1600
- snd_timer_user_zero_id (& id );
1596
+ snd_timer_user_zero_id (id );
1601
1597
}
1602
1598
}
1599
+ }
1600
+
1601
+ static int snd_timer_user_next_device (struct snd_timer_id __user * _tid )
1602
+ {
1603
+ struct snd_timer_id id ;
1604
+
1605
+ if (copy_from_user (& id , _tid , sizeof (id )))
1606
+ return - EFAULT ;
1607
+ scoped_guard (mutex , & register_mutex )
1608
+ get_next_device (& id );
1603
1609
if (copy_to_user (_tid , & id , sizeof (* _tid )))
1604
1610
return - EFAULT ;
1605
1611
return 0 ;
@@ -1620,23 +1626,24 @@ static int snd_timer_user_ginfo(struct file *file,
1620
1626
tid = ginfo -> tid ;
1621
1627
memset (ginfo , 0 , sizeof (* ginfo ));
1622
1628
ginfo -> tid = tid ;
1623
- guard (mutex )(& register_mutex );
1624
- t = snd_timer_find (& tid );
1625
- if (!t )
1626
- return - ENODEV ;
1627
- ginfo -> card = t -> card ? t -> card -> number : -1 ;
1628
- if (t -> hw .flags & SNDRV_TIMER_HW_SLAVE )
1629
- ginfo -> flags |= SNDRV_TIMER_FLG_SLAVE ;
1630
- strscpy (ginfo -> id , t -> id , sizeof (ginfo -> id ));
1631
- strscpy (ginfo -> name , t -> name , sizeof (ginfo -> name ));
1632
- scoped_guard (spinlock_irq , & t -> lock )
1633
- ginfo -> resolution = snd_timer_hw_resolution (t );
1634
- if (t -> hw .resolution_min > 0 ) {
1635
- ginfo -> resolution_min = t -> hw .resolution_min ;
1636
- ginfo -> resolution_max = t -> hw .resolution_max ;
1637
- }
1638
- list_for_each (p , & t -> open_list_head ) {
1639
- ginfo -> clients ++ ;
1629
+ scoped_guard (mutex , & register_mutex ) {
1630
+ t = snd_timer_find (& tid );
1631
+ if (!t )
1632
+ return - ENODEV ;
1633
+ ginfo -> card = t -> card ? t -> card -> number : -1 ;
1634
+ if (t -> hw .flags & SNDRV_TIMER_HW_SLAVE )
1635
+ ginfo -> flags |= SNDRV_TIMER_FLG_SLAVE ;
1636
+ strscpy (ginfo -> id , t -> id , sizeof (ginfo -> id ));
1637
+ strscpy (ginfo -> name , t -> name , sizeof (ginfo -> name ));
1638
+ scoped_guard (spinlock_irq , & t -> lock )
1639
+ ginfo -> resolution = snd_timer_hw_resolution (t );
1640
+ if (t -> hw .resolution_min > 0 ) {
1641
+ ginfo -> resolution_min = t -> hw .resolution_min ;
1642
+ ginfo -> resolution_max = t -> hw .resolution_max ;
1643
+ }
1644
+ list_for_each (p , & t -> open_list_head ) {
1645
+ ginfo -> clients ++ ;
1646
+ }
1640
1647
}
1641
1648
if (copy_to_user (_ginfo , ginfo , sizeof (* ginfo )))
1642
1649
return - EFAULT ;
@@ -1674,31 +1681,31 @@ static int snd_timer_user_gstatus(struct file *file,
1674
1681
struct snd_timer_gstatus gstatus ;
1675
1682
struct snd_timer_id tid ;
1676
1683
struct snd_timer * t ;
1677
- int err = 0 ;
1678
1684
1679
1685
if (copy_from_user (& gstatus , _gstatus , sizeof (gstatus )))
1680
1686
return - EFAULT ;
1681
1687
tid = gstatus .tid ;
1682
1688
memset (& gstatus , 0 , sizeof (gstatus ));
1683
1689
gstatus .tid = tid ;
1684
- guard (mutex )(& register_mutex );
1685
- t = snd_timer_find (& tid );
1686
- if (t != NULL ) {
1687
- guard (spinlock_irq )(& t -> lock );
1688
- gstatus .resolution = snd_timer_hw_resolution (t );
1689
- if (t -> hw .precise_resolution ) {
1690
- t -> hw .precise_resolution (t , & gstatus .resolution_num ,
1691
- & gstatus .resolution_den );
1690
+ scoped_guard (mutex , & register_mutex ) {
1691
+ t = snd_timer_find (& tid );
1692
+ if (t != NULL ) {
1693
+ guard (spinlock_irq )(& t -> lock );
1694
+ gstatus .resolution = snd_timer_hw_resolution (t );
1695
+ if (t -> hw .precise_resolution ) {
1696
+ t -> hw .precise_resolution (t , & gstatus .resolution_num ,
1697
+ & gstatus .resolution_den );
1698
+ } else {
1699
+ gstatus .resolution_num = gstatus .resolution ;
1700
+ gstatus .resolution_den = 1000000000uL ;
1701
+ }
1692
1702
} else {
1693
- gstatus .resolution_num = gstatus .resolution ;
1694
- gstatus .resolution_den = 1000000000uL ;
1703
+ return - ENODEV ;
1695
1704
}
1696
- } else {
1697
- err = - ENODEV ;
1698
1705
}
1699
- if (err >= 0 && copy_to_user (_gstatus , & gstatus , sizeof (gstatus )))
1700
- err = - EFAULT ;
1701
- return err ;
1706
+ if (copy_to_user (_gstatus , & gstatus , sizeof (gstatus )))
1707
+ return - EFAULT ;
1708
+ return 0 ;
1702
1709
}
1703
1710
1704
1711
static int snd_timer_user_tselect (struct file * file ,
0 commit comments