@@ -1167,9 +1167,7 @@ static int __snd_ctl_elem_info(struct snd_card *card,
1167
1167
#ifdef CONFIG_SND_DEBUG
1168
1168
info -> access = 0 ;
1169
1169
#endif
1170
- result = snd_power_ref_and_wait (card );
1171
- if (!result )
1172
- result = kctl -> info (kctl , info );
1170
+ result = kctl -> info (kctl , info );
1173
1171
snd_power_unref (card );
1174
1172
if (result >= 0 ) {
1175
1173
snd_BUG_ON (info -> access );
@@ -1208,12 +1206,17 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
1208
1206
static int snd_ctl_elem_info_user (struct snd_ctl_file * ctl ,
1209
1207
struct snd_ctl_elem_info __user * _info )
1210
1208
{
1209
+ struct snd_card * card = ctl -> card ;
1211
1210
struct snd_ctl_elem_info info ;
1212
1211
int result ;
1213
1212
1214
1213
if (copy_from_user (& info , _info , sizeof (info )))
1215
1214
return - EFAULT ;
1215
+ result = snd_power_ref_and_wait (card );
1216
+ if (result )
1217
+ return result ;
1216
1218
result = snd_ctl_elem_info (ctl , & info );
1219
+ snd_power_unref (card );
1217
1220
if (result < 0 )
1218
1221
return result ;
1219
1222
/* drop internal access flags */
@@ -1257,10 +1260,7 @@ static int snd_ctl_elem_read(struct snd_card *card,
1257
1260
1258
1261
if (!snd_ctl_skip_validation (& info ))
1259
1262
fill_remaining_elem_value (control , & info , pattern );
1260
- ret = snd_power_ref_and_wait (card );
1261
- if (!ret )
1262
- ret = kctl -> get (kctl , control );
1263
- snd_power_unref (card );
1263
+ ret = kctl -> get (kctl , control );
1264
1264
if (ret < 0 )
1265
1265
return ret ;
1266
1266
if (!snd_ctl_skip_validation (& info ) &&
@@ -1285,7 +1285,11 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
1285
1285
if (IS_ERR (control ))
1286
1286
return PTR_ERR (no_free_ptr (control ));
1287
1287
1288
+ result = snd_power_ref_and_wait (card );
1289
+ if (result )
1290
+ return result ;
1288
1291
result = snd_ctl_elem_read (card , control );
1292
+ snd_power_unref (card );
1289
1293
if (result < 0 )
1290
1294
return result ;
1291
1295
@@ -1300,7 +1304,7 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
1300
1304
struct snd_kcontrol * kctl ;
1301
1305
struct snd_kcontrol_volatile * vd ;
1302
1306
unsigned int index_offset ;
1303
- int result ;
1307
+ int result = 0 ;
1304
1308
1305
1309
down_write (& card -> controls_rwsem );
1306
1310
kctl = snd_ctl_find_id_locked (card , & control -> id );
@@ -1318,9 +1322,8 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
1318
1322
}
1319
1323
1320
1324
snd_ctl_build_ioff (& control -> id , kctl , index_offset );
1321
- result = snd_power_ref_and_wait (card );
1322
1325
/* validate input values */
1323
- if (IS_ENABLED (CONFIG_SND_CTL_INPUT_VALIDATION ) && ! result ) {
1326
+ if (IS_ENABLED (CONFIG_SND_CTL_INPUT_VALIDATION )) {
1324
1327
struct snd_ctl_elem_info info ;
1325
1328
1326
1329
memset (& info , 0 , sizeof (info ));
@@ -1332,7 +1335,6 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
1332
1335
}
1333
1336
if (!result )
1334
1337
result = kctl -> put (kctl , control );
1335
- snd_power_unref (card );
1336
1338
if (result < 0 ) {
1337
1339
up_write (& card -> controls_rwsem );
1338
1340
return result ;
@@ -1361,7 +1363,11 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
1361
1363
return PTR_ERR (no_free_ptr (control ));
1362
1364
1363
1365
card = file -> card ;
1366
+ result = snd_power_ref_and_wait (card );
1367
+ if (result < 0 )
1368
+ return result ;
1364
1369
result = snd_ctl_elem_write (card , file , control );
1370
+ snd_power_unref (card );
1365
1371
if (result < 0 )
1366
1372
return result ;
1367
1373
@@ -1830,7 +1836,7 @@ static int call_tlv_handler(struct snd_ctl_file *file, int op_flag,
1830
1836
{SNDRV_CTL_TLV_OP_CMD , SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND },
1831
1837
};
1832
1838
struct snd_kcontrol_volatile * vd = & kctl -> vd [snd_ctl_get_ioff (kctl , id )];
1833
- int i , ret ;
1839
+ int i ;
1834
1840
1835
1841
/* Check support of the request for this element. */
1836
1842
for (i = 0 ; i < ARRAY_SIZE (pairs ); ++ i ) {
@@ -1848,11 +1854,7 @@ static int call_tlv_handler(struct snd_ctl_file *file, int op_flag,
1848
1854
vd -> owner != NULL && vd -> owner != file )
1849
1855
return - EPERM ;
1850
1856
1851
- ret = snd_power_ref_and_wait (file -> card );
1852
- if (!ret )
1853
- ret = kctl -> tlv .c (kctl , op_flag , size , buf );
1854
- snd_power_unref (file -> card );
1855
- return ret ;
1857
+ return kctl -> tlv .c (kctl , op_flag , size , buf );
1856
1858
}
1857
1859
1858
1860
static int read_tlv_buf (struct snd_kcontrol * kctl , struct snd_ctl_elem_id * id ,
@@ -1965,16 +1967,28 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
1965
1967
case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS :
1966
1968
return snd_ctl_subscribe_events (ctl , ip );
1967
1969
case SNDRV_CTL_IOCTL_TLV_READ :
1968
- scoped_guard (rwsem_read , & ctl -> card -> controls_rwsem )
1970
+ err = snd_power_ref_and_wait (card );
1971
+ if (err < 0 )
1972
+ return err ;
1973
+ scoped_guard (rwsem_read , & card -> controls_rwsem )
1969
1974
err = snd_ctl_tlv_ioctl (ctl , argp , SNDRV_CTL_TLV_OP_READ );
1975
+ snd_power_unref (card );
1970
1976
return err ;
1971
1977
case SNDRV_CTL_IOCTL_TLV_WRITE :
1972
- scoped_guard (rwsem_write , & ctl -> card -> controls_rwsem )
1978
+ err = snd_power_ref_and_wait (card );
1979
+ if (err < 0 )
1980
+ return err ;
1981
+ scoped_guard (rwsem_write , & card -> controls_rwsem )
1973
1982
err = snd_ctl_tlv_ioctl (ctl , argp , SNDRV_CTL_TLV_OP_WRITE );
1983
+ snd_power_unref (card );
1974
1984
return err ;
1975
1985
case SNDRV_CTL_IOCTL_TLV_COMMAND :
1976
- scoped_guard (rwsem_write , & ctl -> card -> controls_rwsem )
1986
+ err = snd_power_ref_and_wait (card );
1987
+ if (err < 0 )
1988
+ return err ;
1989
+ scoped_guard (rwsem_write , & card -> controls_rwsem )
1977
1990
err = snd_ctl_tlv_ioctl (ctl , argp , SNDRV_CTL_TLV_OP_CMD );
1991
+ snd_power_unref (card );
1978
1992
return err ;
1979
1993
case SNDRV_CTL_IOCTL_POWER :
1980
1994
return - ENOPROTOOPT ;
0 commit comments