Refactor snd primitives refcounters
Subsystems (3)
cover Refactor snd primitives refcounters
From: Curtis Malainey <[email protected]>
As previously identified in [1] there are some issues with how kobjs are handled in sound/core. The solution provided in [2] is a workaround for the issues to fix the failures.
This series is a first attempt at the larger refactor needed to properly handle the objects.
[1] https://mailman.alsa-project.org/hyperkitty/list/[email protected]/message/3B2VMPFATCJCRD76DM36LZAICPDP2R6A/
[2] https://mailman.alsa-project.org/hyperkitty/list/[email protected]/message/JZIPB4OIC3OK6YAGTPMAEKXMLUWM5PTA/
Curtis Malainey (2):
ALSA: core: add snd_device_init
ALSA: core: split control primitives out of snd_card
include/sound/control.h | 1 + include/sound/core.h | 34 +-- sound/core/control.c | 330 +++++++++++++---------- sound/core/control_compat.c | 8 +- sound/core/control_led.c | 18 +- sound/core/init.c | 33 +-- sound/pci/hda/hda_codec.c | 3 +- sound/soc/intel/atom/sst-atom-controls.c | 8 +- sound/soc/soc-card.c | 2 +- sound/usb/media.c | 2 +- 10 files changed, 249 insertions(+), 190 deletions(-)
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
PATCH 1/2 ALSA: core: add snd_device_init
From: Curtis Malainey <[email protected]>
Begin allowing refactored modules to allocate their own device but use a common initialization procedure for their devices.
--- include/sound/core.h | 1 + sound/core/init.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)
include/sound/core.h +1 -0
@@ -240,6 +240,7 @@ extern struct dentry *sound_debugfs_root;void snd_request_card (int card);int snd_device_alloc (struct device **dev_p,struct snd_card *card); +void snd_device_init (struct device *dev,struct snd_card *card); int snd_register_device(int type, struct snd_card *card, int dev, const struct file_operations *f_ops,
sound/core/init.c +16 -3
@@ -132,15 +132,28 @@ int snd_device_alloc(struct device **dev_p, struct snd_card *card) dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev)return -ENOMEM ; +snd_device_init (dev, card); + *dev_p = dev; +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_device_alloc); + +/** +* snd_device_init - Initialize struct device for sound devices +* @dev_p: pointer to store the allocated device +* @card: card to assign, optional +* +* For releasing the allocated device, call put_device(). +*/ +void snd_device_init (struct device *dev,struct snd_card *card) +{device_initialize (dev);if (card) dev->parent = &card->card_dev; dev->class = &sound_class; dev->release = default_release_alloc; - *dev_p = dev; -return 0 ; } -EXPORT_SYMBOL_GPL (snd_device_alloc); +EXPORT_SYMBOL_GPL (snd_device_init); static int snd_card_init(struct snd_card *card, struct device *parent, int idx, const char *xid, struct module *module,
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
kernel test robot
build botRe: [PATCH 1/2] ALSA: core: add snd_device_init
kernel test robot noticed the following build warnings:
Hi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on next-20230824]
[cannot apply to tiwai-sound/for-linus broonie-sound/for-next linus/master v6.5-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/cujomalainey-chromium-org/ALSA-core-add-snd_device_init/20230825-050745 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20230824210339.1126993-2-cujomalainey%40chromium.org patch subject: [PATCH 1/2] ALSA: core: add snd_device_init config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20230825/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230825/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> sound/core/init.c:149: warning: Function parameter or member 'dev' not described in 'snd_device_init' >> sound/core/init.c:149: warning: Excess function parameter 'dev_p' description in 'snd_device_init'
vim +149 sound/core/init.c
140
141 /**
142 * snd_device_init - Initialize struct device for sound devices
143 * @dev_p: pointer to store the allocated device
144 * @card: card to assign, optional
145 *
146 * For releasing the allocated device, call put_device().
147 */
148 void snd_device_init(struct device *dev, struct snd_card *card)
> 149 { 150 device_initialize(dev);
151 if (card)
152 dev->parent = &card->card_dev;
153 dev->class = &sound_class;
154 dev->release = default_release_alloc;
155 }
156 EXPORT_SYMBOL_GPL(snd_device_init);
157
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/2] ALSA: core: add snd_device_init
In reply to [email protected]Quoted 47 lines · On Thu, 24 Aug 2023 23:02:52 +0200, [email protected] wrote:
From: Curtis Malainey <[email protected]>
Begin allowing refactored modules to allocate their own device but use a common initialization procedure for their devices.
Signed-off-by Curtis Malainey <[email protected]>--- include/sound/core.h | 1 + sound/core/init.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)include/sound/core.h +1
-0@@ -240,6 +240,7 @@ extern struct dentry *sound_debugfs_root;void snd_request_card (int card);int snd_device_alloc (struct device **dev_p,struct snd_card *card); +void snd_device_init (struct device *dev,struct snd_card *card); int snd_register_device(int type, struct snd_card *card, int dev, const struct file_operations *f_ops,sound/core/init.c +15
-0@@ -132,15 +132,28 @@ int snd_device_alloc(struct device **dev_p, struct snd_card *card) dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev)return -ENOMEM ; +snd_device_init (dev, card); + *dev_p = dev; +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_device_alloc); + +/** +* snd_device_init - Initialize struct device for sound devices +* @dev_p: pointer to store the allocated device +* @card: card to assign, optional +* +* For releasing the allocated device, call put_device(). +*/ +void snd_device_init (struct device *dev,struct snd_card *card) +{
sound/core/init.c int snd_device_alloc(struct device **dev_p, struct snd_card *card) · line 156
Quoted 10 lines
sound/core/init.c +1
-3device_initialize (dev);if (card) dev->parent = &card->card_dev; dev->class = &sound_class; dev->release = default_release_alloc; - *dev_p = dev; -return 0 ; } -EXPORT_SYMBOL_GPL (snd_device_alloc); +EXPORT_SYMBOL_GPL (snd_device_init);
This will call kfree() at the default release. It should be avoided for this case, no?
Also, it's worth that this practically a kind of revive of the old API that was dropped in the commit 01ed7f3535a2.
thanks,
Takashi
PATCH 2/2 ALSA: core: split control primitives out of snd_card
In reply to [email protected]From: Curtis Malainey <[email protected]>
Having two kobj in the same struct is broken at its core. This splits card_dev from ctl_dev so they can properly refcount and release on their own schedules without the workaround of having them being just a pointer.
--- include/sound/control.h | 1 + include/sound/core.h | 33 +-- sound/core/control.c | 330 +++++++++++++---------- sound/core/control_compat.c | 8 +- sound/core/control_led.c | 18 +- sound/core/init.c | 14 +- sound/pci/hda/hda_codec.c | 3 +- sound/soc/intel/atom/sst-atom-controls.c | 8 +- sound/soc/soc-card.c | 2 +- sound/usb/media.c | 2 +- 10 files changed, 232 insertions(+), 187 deletions(-)
include/sound/control.h +1 -0
@@ -128,6 +128,7 @@ typedef int (*snd_kctl_ioctl_func_t) (struct snd_card * card,struct snd_ctl_file * control, unsigned int cmd, unsigned long arg); +int snd_control_new (struct snd_card * card);void snd_ctl_notify (struct snd_card * card,unsigned int mask,struct snd_ctl_elem_id * id);void snd_ctl_notify_one (struct snd_card * card,unsigned int mask,struct snd_kcontrol * kctl,unsigned int ioff);
include/sound/core.h +18 -15
@@ -95,21 +95,7 @@ struct snd_card {void (*private_free) (struct snd_card *card);/* callback for freeing of private data */ struct list_head devices;/* devices */ - -struct device *ctl_dev;/* control device */ -unsigned int last_numid;/* last used numeric ID */ -struct rw_semaphore controls_rwsem;/* controls lock (list and values) */ -rwlock_t ctl_files_rwlock;/* ctl_files list lock */ -int controls_count;/* count of all controls */ -size_t user_ctl_alloc_size;// current memory allocation by user controls. -struct list_head controls;/* all controls for this card */ -struct list_head ctl_files;/* active control files */ -#ifdef CONFIG_SND_CTL_FAST_LOOKUP -struct xarray ctl_numids;/* hash table for numids */ -struct xarray ctl_hash;/* hash table for ctl id matching */ -bool ctl_hash_collision;/* ctl_hash collision seen? */ -#endif - +struct snd_control *ctl;/* control devices */ struct snd_info_entry *proc_root;/* root for soundcard specific files */ struct proc_dir_entry *proc_root_link;/* number link to real id */
@@ -147,6 +133,23 @@ struct snd_card {#endif }; +struct snd_control +{ +struct device dev;/* control device */ +struct rw_semaphore controls_rwsem;/* controls lock (list and values) */ +rwlock_t files_rwlock;/* ctl_files list lock */ +int controls_count;/* count of all controls */ +size_t user_ctl_alloc_size;// current memory allocation by user controls. +struct list_head controls;/* all controls for this card */ +struct list_head files;/* active control files */ +unsigned int last_numid;/* last used numeric ID */ +#ifdef CONFIG_SND_CTL_FAST_LOOKUP +struct xarray numids;/* hash table for numids */ +struct xarray hash;/* hash table for ctl id matching */ +bool hash_collision;/* ctl_hash collision seen? */ +#endif +}; +#define dev_to_snd_card (p) container_of(p, struct snd_card, card_dev)#ifdef CONFIG_PM
sound/core/control.c +188 -142
800 lines not on this page · raw message
sound/core/control_compat.c +4 -4
@@ -172,15 +172,15 @@ static int get_ctl_type(struct snd_card *card, struct snd_ctl_elem_id *id,struct snd_ctl_elem_info *info;int err; -down_read (&card->controls_rwsem); +down_read (&card->ctl->controls_rwsem); kctl =snd_ctl_find_id_locked (card, id);if (! kctl) { -up_read (&card->controls_rwsem); +up_read (&card->ctl->controls_rwsem);return -ENOENT ; } info =kzalloc (sizeof (*info),GFP_KERNEL );if (info ==NULL ) { -up_read (&card->controls_rwsem); +up_read (&card->ctl->controls_rwsem);return -ENOMEM ; } info->id = *id;
@@ -188,7 +188,7 @@ static int get_ctl_type(struct snd_card *card, struct snd_ctl_elem_id *id,if (!err) err = kctl->info (kctl, info);snd_power_unref (card); -up_read (&card->controls_rwsem); +up_read (&card->ctl->controls_rwsem);if (err >=0 ) { err = info->type; *countp = info->count;
sound/core/control_led.c +11 -7
@@ -243,6 +243,7 @@ static int snd_ctl_led_set_id(int card_number, struct snd_ctl_elem_id *id, unsigned int group, bool set) {struct snd_card *card; +struct snd_control *ctl;struct snd_kcontrol *kctl;struct snd_kcontrol_volatile *vd;unsigned int ioff, access, new_access;
@@ -250,7 +251,8 @@ static int snd_ctl_led_set_id(int card_number, struct snd_ctl_elem_id *id, card =snd_card_ref (card_number);if (card) { -down_write (&card->controls_rwsem); + ctl = card->ctl; +down_write (&ctl->controls_rwsem); kctl =snd_ctl_find_id_locked (card, id);if (kctl) { ioff =snd_ctl_get_ioff (kctl, id);
@@ -271,7 +273,7 @@ static int snd_ctl_led_set_id(int card_number, struct snd_ctl_elem_id *id, err = -ENOENT ; } unlock: -up_write (&card->controls_rwsem); +up_write (&ctl->controls_rwsem);snd_card_unref (card); }else { err = -ENXIO ;
@@ -357,7 +359,7 @@ static void snd_ctl_led_register(struct snd_card *card) snd_ctl_led_card_valid[card->number] = true;mutex_unlock (&snd_ctl_led_mutex);/* the register callback is already called with held card->controls_rwsem */ -list_for_each_entry (kctl, &card->controls, list) +list_for_each_entry (kctl, &card->ctl->controls, list)for (ioff =0 ; ioff < kctl->count; ioff++)snd_ctl_led_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , kctl, ioff);snd_ctl_led_refresh ();
@@ -617,12 +619,14 @@ static ssize_t list_show(struct device *dev, struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);struct snd_card *card;struct snd_ctl_led_ctl *lctl; +struct snd_control *ctl;size_t l =0 ; card =snd_card_ref (led_card->number);if (!card)return -ENXIO ; -down_read (&card->controls_rwsem); + ctl = card->ctl; +down_read (&ctl->controls_rwsem);mutex_lock (&snd_ctl_led_mutex);if (snd_ctl_led_card_valid[led_card->number]) {list_for_each_entry (lctl, &led_card->led->controls, list) {
@@ -635,7 +639,7 @@ static ssize_t list_show(struct device *dev, } }mutex_unlock (&snd_ctl_led_mutex); -up_read (&card->controls_rwsem); +up_read (&ctl->controls_rwsem);snd_card_unref (card);return l; }
@@ -688,7 +692,7 @@ static void snd_ctl_led_sysfs_add(struct snd_card *card) goto cerr; led->cards[card->number] = led_card;snprintf (link_name,sizeof (link_name),"led-%s" , led->name); -WARN (sysfs_create_link (&card->ctl_dev->kobj, &led_card->dev.kobj, link_name), +WARN (sysfs_create_link (&card->ctl->dev.kobj, &led_card->dev.kobj, link_name),"can't create symlink to controlC%i device\n" , card->number);WARN (sysfs_create_link (&led_card->dev.kobj, &card->card_dev.kobj,"card" ),"can't create symlink to card%i\n" , card->number);
@@ -714,7 +718,7 @@ static void snd_ctl_led_sysfs_remove(struct snd_card *card)if (!led_card)continue ;snprintf (link_name,sizeof (link_name),"led-%s" , led->name); -sysfs_remove_link (&card->ctl_dev->kobj, link_name); +sysfs_remove_link (&card->ctl->dev.kobj, link_name);sysfs_remove_link (&led_card->dev.kobj,"card" );device_unregister (&led_card->dev); led->cards[card->number] =NULL ;
sound/core/init.c +2 -12
@@ -331,14 +331,6 @@ static int snd_card_init(struct snd_card *card, struct device *parent, card->module = module;#endif INIT_LIST_HEAD (&card->devices); -init_rwsem (&card->controls_rwsem); -rwlock_init (&card->ctl_files_rwlock); -INIT_LIST_HEAD (&card->controls); -INIT_LIST_HEAD (&card->ctl_files); -#ifdef CONFIG_SND_CTL_FAST_LOOKUP -xa_init (&card->ctl_numids); -xa_init (&card->ctl_hash); -#endif spin_lock_init (&card->files_lock);INIT_LIST_HEAD (&card->files_list);mutex_init (&card->memory_mutex);
@@ -363,11 +355,9 @@ static int snd_card_init(struct snd_card *card, struct device *parent,snprintf (card->irq_descr,sizeof (card->irq_descr),"%s:%s" ,dev_driver_string (card->dev),dev_name (&card->card_dev)); -/* the control interface cannot be accessed from the user space until */ -/* snd_cards_bitmask and snd_cards are set with snd_card_register */ - err =snd_ctl_create (card); + err =snd_control_new (card);if (err <0 ) { -dev_err (parent,"unable to register control minors\n" ); +dev_err (parent,"unable to create controls and register\n" ); goto __error; } err =snd_info_card_create (card);
sound/pci/hda/hda_codec.c +2 -1
@@ -1784,13 +1784,14 @@ void snd_hda_ctls_clear(struct hda_codec *codec)int snd_hda_lock_devices (struct hda_bus *bus) {struct snd_card *card = bus->card; +struct snd_control *ctl = card->ctl;struct hda_codec *codec;spin_lock (&card->files_lock);if (card->shutdown) goto err_unlock; card->shutdown =1 ; -if (!list_empty (&card->ctl_files)) +if (!list_empty (&ctl->files)) goto err_clear;list_for_each_codec (codec, bus) {
sound/soc/intel/atom/sst-atom-controls.c +4 -4
@@ -1434,9 +1434,9 @@ static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,struct snd_card *card = component->card->snd_card;char *idx; -down_read (&card->controls_rwsem); +down_read (&card->ctl->controls_rwsem); -list_for_each_entry (kctl, &card->controls, list) { +list_for_each_entry (kctl, &card->ctl->controls, list) { idx =strchr (kctl->id.name,' ' );if (idx ==NULL )continue ;
@@ -1469,12 +1469,12 @@ static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w, }if (ret <0 ) { -up_read (&card->controls_rwsem); +up_read (&card->ctl->controls_rwsem);return ret; } } -up_read (&card->controls_rwsem); +up_read (&card->ctl->controls_rwsem);return 0 ; }
sound/soc/soc-card.c +1 -1
@@ -35,7 +35,7 @@ struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,if (unlikely (!name))return NULL ; -list_for_each_entry (kctl, &card->controls, list) +list_for_each_entry (kctl, &card->ctl->controls, list)if (!strncmp (kctl->id.name, name,sizeof (kctl->id.name)))return kctl;return NULL ;
sound/usb/media.c +1 -1
@@ -163,7 +163,7 @@ void snd_media_stop_pipeline(struct snd_usb_substream *subs)static int snd_media_mixer_init (struct snd_usb_audio *chip) { -struct device *ctl_dev = chip->card->ctl_dev; +struct device *ctl_dev = &chip->card->ctl->dev;struct media_intf_devnode *ctl_intf;struct usb_mixer_interface *mixer;struct media_device *mdev = chip->media_dev;
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
Re: [PATCH 2/2] ALSA: core: split control primitives out of snd_card
Quoted 6 lines · On Thu, Aug 24, 2023 at 02:02:53PM -0700, [email protected] wrote:
From: Curtis Malainey <[email protected]>
Having two kobj in the same struct is broken at its core. This splits
card_devfromctl_devso they can properly refcount and release on their own schedules without the workaround of having them being just a pointer.
Re: [PATCH 2/2] ALSA: core: split control primitives out of snd_card
In reply to [email protected]include/sound/core.h struct snd_card { · line 137
Quoted 3 lines · On Thu, 24 Aug 2023 23:02:53 +0200, [email protected] wrote:
include/sound/core.h +2
-0+struct snd_control +{
The open brace should be at the line above.
include/sound/core.h struct snd_card { · line 142
Quoted 5 lines
include/sound/core.h +5
-0+struct device dev;/* control device */ +struct rw_semaphore controls_rwsem;/* controls lock (list and values) */ +rwlock_t files_rwlock;/* ctl_files list lock */ +int controls_count;/* count of all controls */ +size_t user_ctl_alloc_size;// current memory allocation by user controls.
Better to have the same comment style if we move the whole stuff.
Quoted 1 line
+int
snd_control_new(struct snd_card *card)
....
sound/core/control.c static struct snd_ctl_layer_ops *snd_ctl_layer; · line 56
Quoted 6 lines
sound/core/control.c +6
-0+{ +struct snd_control *ctl =kzalloc (sizeof (*ctl),GFP_KERNEL ); +int err; + +if (snd_BUG_ON (!card)) +return -EINVAL ;
This may leak the memory allocated in the above.
sound/core/control.c static struct snd_ctl_layer_ops *snd_ctl_layer; · line 75
Quoted 7 lines
sound/core/control.c +7
-0+/* the control interface cannot be accessed from the user space until */ +/* snd_cards_bitmask and snd_cards are set with snd_card_register */ + err =snd_ctl_create (card); +if (err <0 ) { +dev_err (card->dev,"unable to register control minors\n" ); +kfree (ctl); +return err;
This needs a more care. snd_ctl_create() calls put_device() when snd_device_new() fails, and this already does kfree(). OTOH, the error path before that point doesn't release the object.
sound/core/control.c static struct snd_ctl_layer_ops *snd_ctl_layer; · line 79
Quoted 4 lines
sound/core/control.c +4
-0+ } +return 0 ; +} +EXPORT_SYMBOL (snd_control_new);
This is never called from the driver but only from snd_card_new() & co, so no need to export.
thanks,
Takashi
kernel test robot
build botRe: [PATCH 2/2] ALSA: core: split control primitives out of snd_card
In reply to [email protected]kernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on tiwai-sound/for-next]
[also build test ERROR on tiwai-sound/for-linus linus/master next-20230831] [cannot apply to broonie-sound/for-next v6.5]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/cujomalainey-chromium-org/ALSA-core-add-snd_device_init/20230825-050745 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20230824210339.1126993-3-cujomalainey%40chromium.org patch subject: [PATCH 2/2] ALSA: core: split control primitives out of snd_card config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230904/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230904/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_get_volume1_vol':
>> sound/core/oss/mixer_oss.c:542:24: error: 'struct snd_card' has no member named 'controls_rwsem'
542 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:545:30: error: 'struct snd_card' has no member named 'controls_rwsem'
545 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:563:22: error: 'struct snd_card' has no member named 'controls_rwsem'
563 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_get_volume1_sw':
sound/core/oss/mixer_oss.c:581:24: error: 'struct snd_card' has no member named 'controls_rwsem'
581 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:584:30: error: 'struct snd_card' has no member named 'controls_rwsem'
584 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:603:22: error: 'struct snd_card' has no member named 'controls_rwsem'
603 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_put_volume1_vol':
sound/core/oss/mixer_oss.c:647:24: error: 'struct snd_card' has no member named 'controls_rwsem'
647 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:650:30: error: 'struct snd_card' has no member named 'controls_rwsem'
650 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:671:22: error: 'struct snd_card' has no member named 'controls_rwsem'
671 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_put_volume1_sw':
sound/core/oss/mixer_oss.c:690:24: error: 'struct snd_card' has no member named 'controls_rwsem'
690 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:693:30: error: 'struct snd_card' has no member named 'controls_rwsem'
693 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:718:22: error: 'struct snd_card' has no member named 'controls_rwsem'
718 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_get_recsrc2':
sound/core/oss/mixer_oss.c:835:24: error: 'struct snd_card' has no member named 'controls_rwsem'
835 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:863:22: error: 'struct snd_card' has no member named 'controls_rwsem'
863 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_put_recsrc2':
sound/core/oss/mixer_oss.c:888:24: error: 'struct snd_card' has no member named 'controls_rwsem'
888 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:919:22: error: 'struct snd_card' has no member named 'controls_rwsem'
919 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_build_test':
sound/core/oss/mixer_oss.c:939:24: error: 'struct snd_card' has no member named 'controls_rwsem'
939 | down_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:942:30: error: 'struct snd_card' has no member named 'controls_rwsem'
942 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:947:30: error: 'struct snd_card' has no member named 'controls_rwsem'
947 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:952:30: error: 'struct snd_card' has no member named 'controls_rwsem'
952 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:957:22: error: 'struct snd_card' has no member named 'controls_rwsem'
957 | up_read(&card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_build_input':
sound/core/oss/mixer_oss.c:1071:31: error: 'struct snd_card' has no member named 'controls_rwsem'
1071 | down_read(&mixer->card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:1080:45: error: 'struct snd_card' has no member named 'controls_rwsem'
1080 | up_read(&mixer->card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:1085:45: error: 'struct snd_card' has no member named 'controls_rwsem'
1085 | up_read(&mixer->card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:1101:61: error: 'struct snd_card' has no member named 'controls_rwsem'
1101 | up_read(&mixer->card->controls_rwsem);
| ^~
sound/core/oss/mixer_oss.c:1113:29: error: 'struct snd_card' has no member named 'controls_rwsem'
1113 | up_read(&mixer->card->controls_rwsem);
| ^~
--
In file included from include/linux/kernel.h:21,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/current.h:10,
from include/linux/sched.h:12,
from include/linux/ratelimit.h:6,
from include/linux/dev_printk.h:16,
from include/linux/device.h:15,
from include/linux/pm_runtime.h:11,
from sound/soc/intel/catpt/pcm.c:8:
sound/soc/intel/catpt/pcm.c: In function 'catpt_dai_apply_usettings':
>> sound/soc/intel/catpt/pcm.c:357:60: error: 'struct snd_card' has no member named 'controls'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/intel/catpt/pcm.c:357:9: note: in expansion of macro 'list_for_each_entry'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/bits.h:21,
from include/linux/ratelimit_types.h:5,
from include/linux/ratelimit.h:5:
>> sound/soc/intel/catpt/pcm.c:357:60: error: 'struct snd_card' has no member named 'controls'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/intel/catpt/pcm.c:357:9: note: in expansion of macro 'list_for_each_entry'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
>> sound/soc/intel/catpt/pcm.c:357:60: error: 'struct snd_card' has no member named 'controls'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
21 | __same_type(*(ptr), void), \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/intel/catpt/pcm.c:357:9: note: in expansion of macro 'list_for_each_entry'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:338:27: error: expression in static assertion is not an integer
338 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/intel/catpt/pcm.c:357:9: note: in expansion of macro 'list_for_each_entry'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/rculist.h:10,
from include/linux/pid.h:5,
from include/linux/sched.h:14:
>> sound/soc/intel/catpt/pcm.c:357:60: error: 'struct snd_card' has no member named 'controls'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~
include/linux/list.h:680:27: note: in definition of macro 'list_entry_is_head'
680 | (&pos->member == (head))
| ^~~~
sound/soc/intel/catpt/pcm.c:357:9: note: in expansion of macro 'list_for_each_entry'
357 | list_for_each_entry(pos, &component->card->snd_card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
sound/soc/intel/catpt/pcm.c:362:63: error: 'struct snd_card' has no member named 'controls'
362 | if (list_entry_is_head(pos, &component->card->snd_card->controls, list))
| ^~
include/linux/list.h:680:27: note: in definition of macro 'list_entry_is_head'
680 | (&pos->member == (head))
| ^~~~
--
In file included from include/linux/kernel.h:21,
from arch/x86/include/asm/percpu.h:27,
from arch/x86/include/asm/current.h:10,
from include/linux/sched.h:12,
from include/linux/ratelimit.h:6,
from include/linux/dev_printk.h:16,
from include/linux/device.h:15,
from include/linux/pm_runtime.h:11,
from sound/soc/sh/rcar/core.c:93:
sound/soc/sh/rcar/core.c: In function 'rsnd_kctrl_new':
>> sound/soc/sh/rcar/core.c:1813:41: error: 'struct snd_card' has no member named 'controls'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/sh/rcar/core.c:1813:9: note: in expansion of macro 'list_for_each_entry'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/bits.h:21,
from include/linux/ratelimit_types.h:5,
from include/linux/ratelimit.h:5:
>> sound/soc/sh/rcar/core.c:1813:41: error: 'struct snd_card' has no member named 'controls'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/sh/rcar/core.c:1813:9: note: in expansion of macro 'list_for_each_entry'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
>> sound/soc/sh/rcar/core.c:1813:41: error: 'struct snd_card' has no member named 'controls'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
21 | __same_type(*(ptr), void), \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/sh/rcar/core.c:1813:9: note: in expansion of macro 'list_for_each_entry'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:338:27: error: expression in static assertion is not an integer
338 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
include/linux/list.h:520:9: note: in expansion of macro 'container_of'
520 | container_of(ptr, type, member)
| ^~~~~~~~~~~~
include/linux/list.h:531:9: note: in expansion of macro 'list_entry'
531 | list_entry((ptr)->next, type, member)
| ^~~~~~~~~~
include/linux/list.h:689:20: note: in expansion of macro 'list_first_entry'
689 | for (pos = list_first_entry(head, typeof(*pos), member); \
| ^~~~~~~~~~~~~~~~
sound/soc/sh/rcar/core.c:1813:9: note: in expansion of macro 'list_for_each_entry'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~
In file included from include/linux/rculist.h:10,
from include/linux/pid.h:5,
from include/linux/sched.h:14:
>> sound/soc/sh/rcar/core.c:1813:41: error: 'struct snd_card' has no member named 'controls'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~
include/linux/list.h:680:27: note: in definition of macro 'list_entry_is_head'
680 | (&pos->member == (head))
| ^~~~
sound/soc/sh/rcar/core.c:1813:9: note: in expansion of macro 'list_for_each_entry'
1813 | list_for_each_entry(kctrl, &card->controls, list) {
| ^~~~~~~~~~~~~~~~~~~vim +542 sound/core/oss/mixer_oss.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 529
f956b4a3ae790e Takashi Iwai 2005-11-17 530 static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
f956b4a3ae790e Takashi Iwai 2005-11-17 531 struct snd_mixer_oss_slot *pslot,
^1da177e4c3f41 Linus Torvalds 2005-04-16 532 unsigned int numid,
^1da177e4c3f41 Linus Torvalds 2005-04-16 533 int *left, int *right)
^1da177e4c3f41 Linus Torvalds 2005-04-16 534 {
f956b4a3ae790e Takashi Iwai 2005-11-17 535 struct snd_ctl_elem_info *uinfo;
f956b4a3ae790e Takashi Iwai 2005-11-17 536 struct snd_ctl_elem_value *uctl;
f956b4a3ae790e Takashi Iwai 2005-11-17 537 struct snd_kcontrol *kctl;
f956b4a3ae790e Takashi Iwai 2005-11-17 538 struct snd_card *card = fmixer->card;
^1da177e4c3f41 Linus Torvalds 2005-04-16 539
^1da177e4c3f41 Linus Torvalds 2005-04-16 540 if (numid == ID_UNKNOWN)
^1da177e4c3f41 Linus Torvalds 2005-04-16 541 return;
^1da177e4c3f41 Linus Torvalds 2005-04-16 @542 down_read(&card->controls_rwsem);
b1e055f67611da Takashi Iwai 2023-07-18 543 kctl = snd_ctl_find_numid_locked(card, numid);
51c816fdd17c63 Takashi Iwai 2021-06-08 544 if (!kctl) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 545 up_read(&card->controls_rwsem);
^1da177e4c3f41 Linus Torvalds 2005-04-16 546 return;
^1da177e4c3f41 Linus Torvalds 2005-04-16 547 }
ca2c0966562cfb Takashi Iwai 2005-09-09 548 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
ca2c0966562cfb Takashi Iwai 2005-09-09 549 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
^1da177e4c3f41 Linus Torvalds 2005-04-16 550 if (uinfo == NULL || uctl == NULL)
^1da177e4c3f41 Linus Torvalds 2005-04-16 551 goto __unalloc;
7c22f1aaa23370 Takashi Iwai 2005-10-10 552 if (kctl->info(kctl, uinfo))
7c22f1aaa23370 Takashi Iwai 2005-10-10 553 goto __unalloc;
7c22f1aaa23370 Takashi Iwai 2005-10-10 554 if (kctl->get(kctl, uctl))
7c22f1aaa23370 Takashi Iwai 2005-10-10 555 goto __unalloc;
7c22f1aaa23370 Takashi Iwai 2005-10-10 556 if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
7c22f1aaa23370 Takashi Iwai 2005-10-10 557 uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
7c22f1aaa23370 Takashi Iwai 2005-10-10 558 goto __unalloc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 559 *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
^1da177e4c3f41 Linus Torvalds 2005-04-16 560 if (uinfo->count > 1)
^1da177e4c3f41 Linus Torvalds 2005-04-16 561 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
^1da177e4c3f41 Linus Torvalds 2005-04-16 562 __unalloc:
^1da177e4c3f41 Linus Torvalds 2005-04-16 563 up_read(&card->controls_rwsem);
^1da177e4c3f41 Linus Torvalds 2005-04-16 564 kfree(uctl);
^1da177e4c3f41 Linus Torvalds 2005-04-16 565 kfree(uinfo);
^1da177e4c3f41 Linus Torvalds 2005-04-16 566 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 567 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 10 lines · On Thu, 24 Aug 2023 23:02:51 +0200, [email protected] wrote:
From: Curtis Malainey <[email protected]>
As previously identified in [1] there are some issues with how kobjs are handled in
sound/core. The solution provided in [2] is a workaround for the issues to fix the failures.This series is a first attempt at the larger refactor needed to properly handle the objects.
Quoted 6 lines
[1] https://mailman.alsa-project.org/hyperkitty/list/[email protected]/message/3B2VMPFATCJCRD76DM36LZAICPDP2R6A/
[2] https://mailman.alsa-project.org/hyperkitty/list/[email protected]/message/JZIPB4OIC3OK6YAGTPMAEKXMLUWM5PTA/Curtis Malainey (2):
ALSA: core: addsnd_device_init
ALSA: core: split control primitives out ofsnd_card
Thanks for the patches. But, as the 6.6 merge window open is pretty close, I'd postpone those unless it's urgently needed.
Also, before moving the resource tied with the device object, we'll need a refcount to the ctl dev from pcm dev, as PCM does release chmap at its free path (calling free_chmap()). Otherwise it'll lead to another UAF, if both objects releases are done asynchronously without dependency.
BTW, the cover letter and the subject prefix of the patches don't match, and also the cover letter didn't include Cc. Please try to make both cover letter and patches sent properly.
thanks,
Takashi
Quoted 3 lines · Takashi Iwai
Thanks for the patches. But, as the 6.6 merge window open is pretty close, I'd postpone those unless it's urgently needed.
I have no timeline since we have the workaround in, hence the RFC
Quoted 6 lines
Also, before moving the resource tied with the device object, we'll need a refcount to the ctl dev from pcm dev, as PCM does release chmap at its free path (calling
free_chmap()). Otherwise it'll lead to another UAF, if both objects releases are done asynchronously without dependency.
Got it, thanks.
Quoted 5 lines
BTW, the cover letter and the subject prefix of the patches don't match, and also the cover letter didn't include Cc. Please try to make both cover letter and patches sent properly.
Thanks for catching that, I was struggling getting cc to copy across with git from get_maintainers. I will give it another shot with v2.
Curtis
Quoted 6 lines
thanks,
Takashi