• Takashi Sakamoto's avatar
    ALSA: control: code refactoring for ELEM_READ/ELEM_WRITE operations · becf9e5d
    Takashi Sakamoto authored
    ALSA control core handles ELEM_READ/ELEM_WRITE requests within lock
    acquisition of a counting semaphore. The lock is acquired in helper
    functions in the end of call path before calling implementations of each
    driver.
    
    ioctl(2) with SNDRV_CTL_ELEM_READ
    ...
    ->snd_ctl_ioctl()
      ->snd_ctl_elem_read_user()
        ->snd_ctl_elem_read()
          ->down_read(controls_rwsem)
          ->snd_ctl_find_id()
          ->struct snd_kcontrol.get()
          ->up_read(controls_rwsem)
    
    ioctl(2) with SNDRV_CTL_ELEM_WRITE
    ...
    ->snd_ctl_ioctl()
      ->snd_ctl_elem_write_user()
        ->snd_ctl_elem_write()
          ->down_read(controls_rwsem)
          ->snd_ctl_find_id()
          ->struct snd_kcontrol.put()
          ->up_read(controls_rwsem)
    
    This commit moves the lock acquisition to middle of the call graph to
    simplify the helper functions. As a result:
    
    ioctl(2) with SNDRV_CTL_ELEM_READ
    ...
    ->snd_ctl_ioctl()
      ->snd_ctl_elem_read_user()
        ->down_read(controls_rwsem)
        ->snd_ctl_elem_read()
          ->snd_ctl_find_id()
          ->struct snd_kcontrol.get()
        ->up_read(controls_rwsem)
    
    ioctl(2) with SNDRV_CTL_ELEM_WRITE
    ...
    ->snd_ctl_ioctl()
      ->snd_ctl_elem_write_user()
        ->down_read(controls_rwsem)
        ->snd_ctl_elem_write()
          ->snd_ctl_find_id()
          ->struct snd_kcontrol.put()
        ->up_read(controls_rwsem)
    Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
    Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
    becf9e5d
control.c 50.8 KB