Skip to contentSkip to conversation

ALSA: core: add snd_device_init

RFC PATCH In review [email protected] 4 participants 5 messages Sep 13, 2023 – Sep 14, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 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
index dfef0c9d4b9f7..a4744e142c7e3 100644
@@ -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
index 22c0d217b8608..87b5368d20350 100644
@@ -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.283.g2d96d420d3-goog
#1 lore raw

RFC PATCH v2 2/2 ALSA: core: split control primitives out of snd_card

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.

Change-Id Iecc91a116dfcb5a6364c7e6bdf993949e8542ca1

---
v2:
- Fix leak rnd formatting eported by Takashi
- Collapse snd_ctl_create into snd_control_new to ease memory handling reported by Takashi
- Fix OSS errors reported by kbuild

 include/sound/control.h                  |   1 +
 include/sound/core.h                     |  32 +-
 sound/core/control.c                     | 362 +++++++++++++----------
 sound/core/control_compat.c              |   8 +-
 sound/core/control_led.c                 |  18 +-
 sound/core/init.c                        |  14 +-
 sound/core/oss/mixer_oss.c               |  52 ++--
 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 +-
 11 files changed, 269 insertions(+), 233 deletions(-)
include/sound/control.h +1 -0
index 9a4f4f7138da8..32920f33eb47e 100644
@@ -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 +17 -15
index a4744e142c7e3..263174eea4634 100644
@@ -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,22 @@ 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 +200 -162

819 lines not on this page · raw message

sound/core/control_compat.c +4 -4
index 0e8b1bfb040e0..0e0b555f71537 100644
@@ -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
index a78eb48927c7b..6b53de7660438 100644
@@ -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
index 87b5368d20350..9cd2cb22de728 100644
@@ -328,14 +328,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);
@@ -360,11 +352,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/core/oss/mixer_oss.c +26 -26

180 lines not on this page · raw message

sound/pci/hda/hda_codec.c +2 -1
index 33af707a65ab1..7afc9a29ea9ec 100644
@@ -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
index 38116c7587174..8cd5681de9fbd 100644
@@ -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
index 285ab4c9c7168..1129eb33f78c9 100644
@@ -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
index d48db6f3ae659..5298c2f49a164 100644
@@ -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.283.g2d96d420d3-goog
maintainer Acked-by on v2 2/2
#2 lore raw

Re: [RFC PATCH v2 2/2] ALSA: core: split control primitives out of snd_card

Quoted 6 lines · On Wed, Sep 13, 2023 at 01:07:44PM -0700, [email protected] wrote:

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.

Quoted 1 line

Change-Id: Iecc91a116dfcb5a6364c7e6bdf993949e8542ca1

Please don't put change IDs in upstream submissions (or put them after the --- so they get dropped on application like b4 does in cover letters, it might be good to look at improving the tooling around gerritt to support that since it seems like a pretty good comprimise which would reduce friction).

#3 lore raw

Re: [RFC PATCH v2 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,

[This is a private test report for your RFC patch.] 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 broonie-sound/for-next linus/master v6.6-rc1 next-20230913] [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-split-control-primitives-out-of-snd_card/20230914-041536
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20230913200846.1894258-3-cujomalainey%40chromium.org
patch subject: [RFC PATCH v2 2/2] ALSA: core: split control primitives out of snd_card
config: x86_64-randconfig-001-20230914 (https://download.01.org/0day-ci/archive/20230914/[email protected]/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[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 >>):

In file included from include/linux/kernel.h:21,
from include/linux/interrupt.h:6, from sound/core/control.c:8:
sound/core/control.c: In function 'snd_ctl_find_numid_slow':

>> sound/core/control.c:874:33: error: 'struct snd_card' has no member named 'controls'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |                                 ^~
   include/linux/container_of.h:19:26: note: in definition of macro 'container_of'
      19 |  void *__mptr = (void *)(ptr);     \
         |                          ^~~
   include/linux/list.h:612:2: note: in expansion of macro 'list_entry'
     612 |  list_entry((ptr)->next, type, member)
         |  ^~~~~~~~~~
   include/linux/list.h:770:13: note: in expansion of macro 'list_first_entry'
     770 |  for (pos = list_first_entry(head, typeof(*pos), member); \
         |             ^~~~~~~~~~~~~~~~
   sound/core/control.c:874:2: note: in expansion of macro 'list_for_each_entry'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |  ^~~~~~~~~~~~~~~~~~~
   In file included from include/linux/container_of.h:5,
                    from include/linux/kernel.h:21,
                    from include/linux/interrupt.h:6,
                    from sound/core/control.c:8:
>> sound/core/control.c:874:33: error: 'struct snd_card' has no member named 'controls'
     874 |  list_for_each_entry(kctl, &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:2: note: in expansion of macro 'static_assert'
      20 |  static_assert(__same_type(*(ptr), ((type *)0)->member) || \
         |  ^~~~~~~~~~~~~
   include/linux/container_of.h:20:16: note: in expansion of macro '__same_type'
      20 |  static_assert(__same_type(*(ptr), ((type *)0)->member) || \
         |                ^~~~~~~~~~~
   include/linux/list.h:601:2: note: in expansion of macro 'container_of'
     601 |  container_of(ptr, type, member)
         |  ^~~~~~~~~~~~
   include/linux/list.h:612:2: note: in expansion of macro 'list_entry'
     612 |  list_entry((ptr)->next, type, member)
         |  ^~~~~~~~~~
   include/linux/list.h:770:13: note: in expansion of macro 'list_first_entry'
     770 |  for (pos = list_first_entry(head, typeof(*pos), member); \
         |             ^~~~~~~~~~~~~~~~
   sound/core/control.c:874:2: note: in expansion of macro 'list_for_each_entry'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |  ^~~~~~~~~~~~~~~~~~~
>> sound/core/control.c:874:33: error: 'struct snd_card' has no member named 'controls'
     874 |  list_for_each_entry(kctl, &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:2: note: in expansion of macro 'static_assert'
      20 |  static_assert(__same_type(*(ptr), ((type *)0)->member) || \
         |  ^~~~~~~~~~~~~
   include/linux/container_of.h:21:9: note: in expansion of macro '__same_type'
      21 |         __same_type(*(ptr), void),   \
         |         ^~~~~~~~~~~
   include/linux/list.h:601:2: note: in expansion of macro 'container_of'
     601 |  container_of(ptr, type, member)
         |  ^~~~~~~~~~~~
   include/linux/list.h:612:2: note: in expansion of macro 'list_entry'
     612 |  list_entry((ptr)->next, type, member)
         |  ^~~~~~~~~~
   include/linux/list.h:770:13: note: in expansion of macro 'list_first_entry'
     770 |  for (pos = list_first_entry(head, typeof(*pos), member); \
         |             ^~~~~~~~~~~~~~~~
   sound/core/control.c:874:2: note: in expansion of macro 'list_for_each_entry'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/compiler_types.h:366:27: error: expression in static assertion is not an integer
     366 | #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:2: note: in expansion of macro 'static_assert'
      20 |  static_assert(__same_type(*(ptr), ((type *)0)->member) || \
         |  ^~~~~~~~~~~~~
   include/linux/container_of.h:20:16: note: in expansion of macro '__same_type'
      20 |  static_assert(__same_type(*(ptr), ((type *)0)->member) || \
         |                ^~~~~~~~~~~
   include/linux/list.h:601:2: note: in expansion of macro 'container_of'
     601 |  container_of(ptr, type, member)
         |  ^~~~~~~~~~~~
   include/linux/list.h:612:2: note: in expansion of macro 'list_entry'
     612 |  list_entry((ptr)->next, type, member)
         |  ^~~~~~~~~~
   include/linux/list.h:770:13: note: in expansion of macro 'list_first_entry'
     770 |  for (pos = list_first_entry(head, typeof(*pos), member); \
         |             ^~~~~~~~~~~~~~~~
   sound/core/control.c:874:2: note: in expansion of macro 'list_for_each_entry'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |  ^~~~~~~~~~~~~~~~~~~
   In file included from include/linux/preempt.h:12,
                    from include/linux/percpu.h:6,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/interrupt.h:11,
                    from sound/core/control.c:8:
>> sound/core/control.c:874:33: error: 'struct snd_card' has no member named 'controls'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |                                 ^~
   include/linux/list.h:761:20: note: in definition of macro 'list_entry_is_head'
     761 |  (&pos->member == (head))
         |                    ^~~~
   sound/core/control.c:874:2: note: in expansion of macro 'list_for_each_entry'
     874 |  list_for_each_entry(kctl, &card->controls, list) {
         |  ^~~~~~~~~~~~~~~~~~~

vim +874 sound/core/control.c

966f015fe43291 Maciej S. Szmigiero 2022-10-20  867  
c27e1efb61c545 Takashi Iwai        2022-06-10  868  #ifndef CONFIG_SND_CTL_FAST_LOOKUP
c27e1efb61c545 Takashi Iwai        2022-06-10  869  static struct snd_kcontrol *
c27e1efb61c545 Takashi Iwai        2022-06-10  870  snd_ctl_find_numid_slow(struct snd_card *card, unsigned int numid)
c27e1efb61c545 Takashi Iwai        2022-06-10  871  {
c27e1efb61c545 Takashi Iwai        2022-06-10  872  	struct snd_kcontrol *kctl;
c27e1efb61c545 Takashi Iwai        2022-06-10  873  
c27e1efb61c545 Takashi Iwai        2022-06-10 @874  	list_for_each_entry(kctl, &card->controls, list) {
c27e1efb61c545 Takashi Iwai        2022-06-10  875  		if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
c27e1efb61c545 Takashi Iwai        2022-06-10  876  			return kctl;
c27e1efb61c545 Takashi Iwai        2022-06-10  877  	}
c27e1efb61c545 Takashi Iwai        2022-06-10  878  	return NULL;
c27e1efb61c545 Takashi Iwai        2022-06-10  879  }
c27e1efb61c545 Takashi Iwai        2022-06-10  880  #endif /* !CONFIG_SND_CTL_FAST_LOOKUP */
c27e1efb61c545 Takashi Iwai        2022-06-10  881  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to [email protected]
Quoted 42 lines · On Wed, 13 Sep 2023 22:07:42 +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.

---
 include/sound/core.h |  1 +
 sound/core/init.c    | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
include/sound/core.h +1 -0
index dfef0c9d4b9f7..a4744e142c7e3 100644
@@ -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 +10 -0
index 22c0d217b8608..87b5368d20350 100644
@@ -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

sound/core/init.c int snd_device_alloc(struct device **dev_p, struct snd_card *card) · line 154

Quoted 10 lines
sound/core/init.c +5 -0
+ *
+ * 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;

I'd rather leave release unset here and mention in the function description to set release in each caller side. default_release_alloc() calls kfree(), and certainly it doesn't match with this call.

thanks,

Takashi