From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Cc: Curtis Malainey <cujomalainey@google.com>
Subject: [PATCH RFC 1/9] ALSA: core: Introduce snd_device_alloc()
Date: Wed, 16 Aug 2023 18:02:44 +0200 [thread overview]
Message-ID: <20230816160252.23396-2-tiwai@suse.de> (raw)
In-Reply-To: <20230816160252.23396-1-tiwai@suse.de>
Introduce a new helper, snd_device_alloc(), for allocating a struct
device that is bound with the sound class. It's a replacement of
snd_device_initialize().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
include/sound/core.h | 1 +
sound/core/init.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/include/sound/core.h b/include/sound/core.h
index f6e0dd648b80..f986fcc5f18f 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -239,6 +239,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_initialize(struct device *dev, struct snd_card *card);
int snd_register_device(int type, struct snd_card *card, int dev,
diff --git a/sound/core/init.c b/sound/core/init.c
index baef2688d0cf..a4de9f00d90f 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -134,6 +134,37 @@ void snd_device_initialize(struct device *dev, struct snd_card *card)
}
EXPORT_SYMBOL_GPL(snd_device_initialize);
+/* the default release callback set in snd_device_alloc() */
+static void default_release_alloc(struct device *dev)
+{
+ kfree(dev);
+}
+
+/**
+ * snd_device_alloc - Allocate and 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().
+ */
+int snd_device_alloc(struct device **dev_p, struct snd_card *card)
+{
+ struct device *dev;
+
+ *dev_p = NULL;
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return -ENOMEM;
+ 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);
+
static int snd_card_init(struct snd_card *card, struct device *parent,
int idx, const char *xid, struct module *module,
size_t extra_size);
--
2.35.3
next prev parent reply other threads:[~2023-08-16 16:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 16:02 [PATCH RFC 0/9] ALSA: Don't embed struct devices Takashi Iwai
2023-08-16 16:02 ` Takashi Iwai [this message]
2023-08-16 16:02 ` [PATCH RFC 2/9] ALSA: control: Don't embed ctl_dev Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 3/9] ALSA: pcm: Don't embed device Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 4/9] ALSA: hwdep: " Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 5/9] ALSA: rawmidi: " Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 6/9] ALSA: compress: " Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 7/9] ALSA: timer: Create device with snd_device_alloc() Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 8/9] ALSA: seq: " Takashi Iwai
2023-08-16 16:02 ` [PATCH RFC 9/9] ALSA: core: Drop snd_device_initialize() Takashi Iwai
2023-08-16 16:45 ` [PATCH RFC 0/9] ALSA: Don't embed struct devices Jaroslav Kysela
2023-08-16 22:18 ` Curtis Malainey
2023-08-17 7:27 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230816160252.23396-2-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=cujomalainey@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox