All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/6] staging: most: sound: change sound card layout
@ 2018-12-17 11:33 Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device Christian Gromm
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

Currently, for every synchronous channel allocated on MOST an extra sound
card is being created and registered with ALSA. From a logical point of
view this fails to reflect the actual condition, as all channels originate
in the same physical device. This patch series introduces a way to map this
layout and creates only one sound card per registered MOST device that has
multiple PCM devices to access the individual MOST channels. To achieve
this a change in the user space API is added that allows to signal the
driver that the configuration is complete and that the new sound card is
ready to be registered with ALSA. 

v2:
	- mention API change in description
v3:
	nothing

Christian Gromm (6):
  staging: most: sound: create one sound card w/ multiple PCM devices
    per MOST device
  staging: most: sound: correct label name
  staging: most: sound: rename variable
  staging: most: sound: use static name for ALSA card
  staging: most: sound: remove channel number from ALSA card's long name
  staging: most: Documentation: add information to driver_usage file

 .../staging/most/Documentation/driver_usage.txt    |  16 ++-
 drivers/staging/most/sound/sound.c                 | 142 ++++++++++++++-------
 2 files changed, 107 insertions(+), 51 deletions(-)

-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  2018-12-17 11:45   ` Dan Carpenter
  2018-12-17 11:33 ` [PATCH v3 2/6] staging: most: sound: correct label name Christian Gromm
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch avoids that a sound card is created and registered with ALSA
every time a channel is being linked. Instead the channels are hooked on
the same card, which is registered not until the final link has been added
to the component. The string provided by user space that used to be the
card name becomes the PCM device name. The user space API to add a link is
being expanded by a "create" flag to trigger the registration.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
	- push audio apdaper to list right afer its initialization

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
	- mention user space API change in description
	- assign value to variable ret before jumping to error handling
	- remove unnecessary variable initializations
	- fix if statements when iterating audio adapter list  
	- use correct variable in sizeof operator
	- store PCM device name
v3:
	- jump to error handling in case snd_card_new() fails 

 drivers/staging/most/sound/sound.c | 129 +++++++++++++++++++++++++------------
 1 file changed, 88 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 89b02fc..cb02590 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/printk.h>
 #include <linux/kernel.h>
+#include <linux/slab.h>
 #include <linux/init.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -20,7 +21,6 @@
 
 #define DRIVER_NAME "sound"
 
-static struct list_head dev_list;
 static struct core_component comp;
 
 /**
@@ -56,6 +56,17 @@ struct channel {
 	void (*copy_fn)(void *alsa, void *most, unsigned int bytes);
 };
 
+struct sound_adapter {
+	struct list_head dev_list;
+	struct most_interface *iface;
+	struct snd_card *card;
+	struct list_head list;
+	bool registered;
+	int pcm_dev_idx;
+};
+
+static struct list_head adpt_list;
+
 #define MOST_PCM_INFO (SNDRV_PCM_INFO_MMAP | \
 		       SNDRV_PCM_INFO_MMAP_VALID | \
 		       SNDRV_PCM_INFO_BATCH | \
@@ -157,9 +168,10 @@ static void most_to_alsa_copy32(void *alsa, void *most, unsigned int bytes)
 static struct channel *get_channel(struct most_interface *iface,
 				   int channel_id)
 {
+	struct sound_adapter *adpt = iface->priv;
 	struct channel *channel, *tmp;
 
-	list_for_each_entry_safe(channel, tmp, &dev_list, list) {
+	list_for_each_entry_safe(channel, tmp, &adpt->dev_list, list) {
 		if ((channel->iface == iface) && (channel->id == channel_id))
 			return channel;
 	}
@@ -460,7 +472,7 @@ static const struct snd_pcm_ops pcm_ops = {
 };
 
 static int split_arg_list(char *buf, char **card_name, u16 *ch_num,
-			  char **sample_res)
+			  char **sample_res, u8 *create)
 {
 	char *num;
 	int ret;
@@ -479,6 +491,9 @@ static int split_arg_list(char *buf, char **card_name, u16 *ch_num,
 	*sample_res = strsep(&buf, ".\n");
 	if (!*sample_res)
 		goto err;
+
+	if (buf && !strcmp(buf, "create"))
+		*create = 1;
 	return 0;
 
 err:
@@ -536,6 +551,19 @@ static int audio_set_hw_params(struct snd_pcm_hardware *pcm_hw,
 	return 0;
 }
 
+static void release_adapter(struct sound_adapter *adpt)
+{
+	struct channel *channel, *tmp;
+
+	list_for_each_entry_safe(channel, tmp, &adpt->dev_list, list) {
+		list_del(&channel->list);
+		kfree(channel);
+	}
+	snd_card_free(adpt->card);
+	list_del(&adpt->list);
+	kfree(adpt);
+}
+
 /**
  * audio_probe_channel - probe function of the driver module
  * @iface: pointer to interface instance
@@ -553,7 +581,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 			       char *arg_list)
 {
 	struct channel *channel;
-	struct snd_card *card;
+	struct sound_adapter *adpt;
 	struct snd_pcm *pcm;
 	int playback_count = 0;
 	int capture_count = 0;
@@ -561,6 +589,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	int direction;
 	char *card_name;
 	u16 ch_num;
+	u8 create = 0;
 	char *sample_res;
 
 	if (!iface)
@@ -571,6 +600,39 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 		return -EINVAL;
 	}
 
+	ret = split_arg_list(arg_list, &card_name, &ch_num, &sample_res,
+			     &create);
+	if (ret < 0)
+		return ret;
+
+	list_for_each_entry(adpt, &adpt_list, list) {
+		if (adpt->iface != iface)
+			continue;
+		if (adpt->registered)
+			return -ENOSPC;
+		adpt->pcm_dev_idx++;
+		goto skip_adpt_alloc;
+	}
+	adpt = kzalloc(sizeof(*adpt), GFP_KERNEL);
+	if (!adpt)
+		return -ENOMEM;
+
+	adpt->iface = iface;
+	INIT_LIST_HEAD(&adpt->dev_list);
+	iface->priv = adpt;
+	list_add_tail(&adpt->list, &adpt_list);
+	ret = snd_card_new(&iface->dev, -1, card_name, THIS_MODULE,
+			   sizeof(*channel), &adpt->card);
+	if (ret < 0)
+		goto err_free_card;
+	snprintf(adpt->card->driver, sizeof(adpt->card->driver),
+		 "%s", DRIVER_NAME);
+	snprintf(adpt->card->shortname, sizeof(adpt->card->shortname),
+		 "Microchip MOST:%d", adpt->card->number);
+	snprintf(adpt->card->longname, sizeof(adpt->card->longname),
+		 "%s at %s, ch %d", adpt->card->shortname, iface->description,
+		 channel_id);
+skip_adpt_alloc:
 	if (get_channel(iface, channel_id)) {
 		pr_err("channel (%s:%d) is already linked\n",
 		       iface->description, channel_id);
@@ -584,53 +646,43 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 		capture_count = 1;
 		direction = SNDRV_PCM_STREAM_CAPTURE;
 	}
-
-	ret = split_arg_list(arg_list, &card_name, &ch_num, &sample_res);
-	if (ret < 0)
-		return ret;
-
-	ret = snd_card_new(&iface->dev, -1, card_name, THIS_MODULE,
-			   sizeof(*channel), &card);
-	if (ret < 0)
-		return ret;
-
-	channel = card->private_data;
-	channel->card = card;
+	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
+	if (!channel) {
+		ret = -ENOMEM;
+		goto err_free_card;
+	}
+	channel->card = adpt->card;
 	channel->cfg = cfg;
 	channel->iface = iface;
 	channel->id = channel_id;
 	init_waitqueue_head(&channel->playback_waitq);
+	list_add_tail(&channel->list, &adpt->dev_list);
 
 	ret = audio_set_hw_params(&channel->pcm_hardware, ch_num, sample_res,
 				  cfg);
 	if (ret)
 		goto err_free_card;
 
-	snprintf(card->driver, sizeof(card->driver), "%s", DRIVER_NAME);
-	snprintf(card->shortname, sizeof(card->shortname), "Microchip MOST:%d",
-		 card->number);
-	snprintf(card->longname, sizeof(card->longname), "%s at %s, ch %d",
-		 card->shortname, iface->description, channel_id);
+	ret = snd_pcm_new(adpt->card, card_name, adpt->pcm_dev_idx,
+			  playback_count, capture_count, &pcm);
 
-	ret = snd_pcm_new(card, card_name, 0, playback_count,
-			  capture_count, &pcm);
 	if (ret < 0)
 		goto err_free_card;
 
 	pcm->private_data = channel;
-
+	snprintf(pcm->name, sizeof(pcm->name), card_name);
 	snd_pcm_set_ops(pcm, direction, &pcm_ops);
 
-	ret = snd_card_register(card);
-	if (ret < 0)
-		goto err_free_card;
-
-	list_add_tail(&channel->list, &dev_list);
-
+	if (create) {
+		ret = snd_card_register(adpt->card);
+		if (ret < 0)
+			goto err_free_card;
+		adpt->registered = true;
+	}
 	return 0;
 
 err_free_card:
-	snd_card_free(card);
+	release_adapter(adpt);
 	return ret;
 }
 
@@ -647,6 +699,7 @@ static int audio_disconnect_channel(struct most_interface *iface,
 				    int channel_id)
 {
 	struct channel *channel;
+	struct sound_adapter *adpt = iface->priv;
 
 	channel = get_channel(iface, channel_id);
 	if (!channel) {
@@ -656,8 +709,10 @@ static int audio_disconnect_channel(struct most_interface *iface,
 	}
 
 	list_del(&channel->list);
-	snd_card_free(channel->card);
 
+	kfree(channel);
+	if (list_empty(&adpt->dev_list))
+		release_adapter(adpt);
 	return 0;
 }
 
@@ -733,22 +788,14 @@ static int __init audio_init(void)
 {
 	pr_info("init()\n");
 
-	INIT_LIST_HEAD(&dev_list);
+	INIT_LIST_HEAD(&adpt_list);
 
 	return most_register_component(&comp);
 }
 
 static void __exit audio_exit(void)
 {
-	struct channel *channel, *tmp;
-
 	pr_info("exit()\n");
-
-	list_for_each_entry_safe(channel, tmp, &dev_list, list) {
-		list_del(&channel->list);
-		snd_card_free(channel->card);
-	}
-
 	most_deregister_component(&comp);
 }
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/6] staging: most: sound: correct label name
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 3/6] staging: most: sound: rename variable Christian Gromm
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch fixes the lable name that is used to jump to error
handling section of function audio_probe_channel() in case
something went wrong.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
	nothing
v3:
	- rename label name of added goto instruction

 drivers/staging/most/sound/sound.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index cb02590..22e106f 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -624,7 +624,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	ret = snd_card_new(&iface->dev, -1, card_name, THIS_MODULE,
 			   sizeof(*channel), &adpt->card);
 	if (ret < 0)
-		goto err_free_card;
+		goto err_free_adpt;
 	snprintf(adpt->card->driver, sizeof(adpt->card->driver),
 		 "%s", DRIVER_NAME);
 	snprintf(adpt->card->shortname, sizeof(adpt->card->shortname),
@@ -649,7 +649,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
 	if (!channel) {
 		ret = -ENOMEM;
-		goto err_free_card;
+		goto err_free_adpt;
 	}
 	channel->card = adpt->card;
 	channel->cfg = cfg;
@@ -661,13 +661,13 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	ret = audio_set_hw_params(&channel->pcm_hardware, ch_num, sample_res,
 				  cfg);
 	if (ret)
-		goto err_free_card;
+		goto err_free_adpt;
 
 	ret = snd_pcm_new(adpt->card, card_name, adpt->pcm_dev_idx,
 			  playback_count, capture_count, &pcm);
 
 	if (ret < 0)
-		goto err_free_card;
+		goto err_free_adpt;
 
 	pcm->private_data = channel;
 	snprintf(pcm->name, sizeof(pcm->name), card_name);
@@ -676,12 +676,12 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	if (create) {
 		ret = snd_card_register(adpt->card);
 		if (ret < 0)
-			goto err_free_card;
+			goto err_free_adpt;
 		adpt->registered = true;
 	}
 	return 0;
 
-err_free_card:
+err_free_adpt:
 	release_adapter(adpt);
 	return ret;
 }
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/6] staging: most: sound: rename variable
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 2/6] staging: most: sound: correct label name Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 4/6] staging: most: sound: use static name for ALSA card Christian Gromm
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

Since the channels of a MOST device are now being represented as
individual PCM devices of one sound card, the variable card_name is not
suitable anymore to describe them. Therefore, this patch renames the
variable to device_name.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
	- remove call to snprintf to store PCM name
v3:
	nothing

 drivers/staging/most/sound/sound.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 22e106f..8d5211d 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -471,14 +471,14 @@ static const struct snd_pcm_ops pcm_ops = {
 	.page       = snd_pcm_lib_get_vmalloc_page,
 };
 
-static int split_arg_list(char *buf, char **card_name, u16 *ch_num,
+static int split_arg_list(char *buf, char **device_name, u16 *ch_num,
 			  char **sample_res, u8 *create)
 {
 	char *num;
 	int ret;
 
-	*card_name = strsep(&buf, ".");
-	if (!*card_name) {
+	*device_name = strsep(&buf, ".");
+	if (!*device_name) {
 		pr_err("Missing sound card name\n");
 		return -EIO;
 	}
@@ -587,7 +587,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	int capture_count = 0;
 	int ret;
 	int direction;
-	char *card_name;
+	char *device_name;
 	u16 ch_num;
 	u8 create = 0;
 	char *sample_res;
@@ -600,7 +600,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 		return -EINVAL;
 	}
 
-	ret = split_arg_list(arg_list, &card_name, &ch_num, &sample_res,
+	ret = split_arg_list(arg_list, &device_name, &ch_num, &sample_res,
 			     &create);
 	if (ret < 0)
 		return ret;
@@ -621,7 +621,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	INIT_LIST_HEAD(&adpt->dev_list);
 	iface->priv = adpt;
 	list_add_tail(&adpt->list, &adpt_list);
-	ret = snd_card_new(&iface->dev, -1, card_name, THIS_MODULE,
+	ret = snd_card_new(&iface->dev, -1, device_name, THIS_MODULE,
 			   sizeof(*channel), &adpt->card);
 	if (ret < 0)
 		goto err_free_adpt;
@@ -663,14 +663,14 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	if (ret)
 		goto err_free_adpt;
 
-	ret = snd_pcm_new(adpt->card, card_name, adpt->pcm_dev_idx,
+	ret = snd_pcm_new(adpt->card, device_name, adpt->pcm_dev_idx,
 			  playback_count, capture_count, &pcm);
 
 	if (ret < 0)
 		goto err_free_adpt;
 
 	pcm->private_data = channel;
-	snprintf(pcm->name, sizeof(pcm->name), card_name);
+	snprintf(pcm->name, sizeof(pcm->name), device_name);
 	snd_pcm_set_ops(pcm, direction, &pcm_ops);
 
 	if (create) {
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 4/6] staging: most: sound: use static name for ALSA card
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
                   ` (2 preceding siblings ...)
  2018-12-17 11:33 ` [PATCH v3 3/6] staging: most: sound: rename variable Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 5/6] staging: most: sound: remove channel number from ALSA card's long name Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 6/6] staging: most: Documentation: add information to driver_usage file Christian Gromm
  5 siblings, 0 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch uses a static name for the sound card's short name and
long name. Having the card names configurable doesn't make sense
anymore, as the card represents the same physical hardware.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
	nothing
v3:
	nothing

 drivers/staging/most/sound/sound.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 8d5211d..9a851e5 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -621,14 +621,14 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	INIT_LIST_HEAD(&adpt->dev_list);
 	iface->priv = adpt;
 	list_add_tail(&adpt->list, &adpt_list);
-	ret = snd_card_new(&iface->dev, -1, device_name, THIS_MODULE,
+	ret = snd_card_new(&iface->dev, -1, "INIC", THIS_MODULE,
 			   sizeof(*channel), &adpt->card);
 	if (ret < 0)
 		goto err_free_adpt;
 	snprintf(adpt->card->driver, sizeof(adpt->card->driver),
 		 "%s", DRIVER_NAME);
 	snprintf(adpt->card->shortname, sizeof(adpt->card->shortname),
-		 "Microchip MOST:%d", adpt->card->number);
+		 "Microchip INIC");
 	snprintf(adpt->card->longname, sizeof(adpt->card->longname),
 		 "%s at %s, ch %d", adpt->card->shortname, iface->description,
 		 channel_id);
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 5/6] staging: most: sound: remove channel number from ALSA card's long name
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
                   ` (3 preceding siblings ...)
  2018-12-17 11:33 ` [PATCH v3 4/6] staging: most: sound: use static name for ALSA card Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  2018-12-17 11:33 ` [PATCH v3 6/6] staging: most: Documentation: add information to driver_usage file Christian Gromm
  5 siblings, 0 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

Adding the channel number to the name of the sound card is wrong,
as the card does not represent a single streaming channel of the
MOST device.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
	nothing
v3:
	nothing

 drivers/staging/most/sound/sound.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c
index 9a851e5..9cac58e 100644
--- a/drivers/staging/most/sound/sound.c
+++ b/drivers/staging/most/sound/sound.c
@@ -630,8 +630,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
 	snprintf(adpt->card->shortname, sizeof(adpt->card->shortname),
 		 "Microchip INIC");
 	snprintf(adpt->card->longname, sizeof(adpt->card->longname),
-		 "%s at %s, ch %d", adpt->card->shortname, iface->description,
-		 channel_id);
+		 "%s at %s", adpt->card->shortname, iface->description);
 skip_adpt_alloc:
 	if (get_channel(iface, channel_id)) {
 		pr_err("channel (%s:%d) is already linked\n",
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 6/6] staging: most: Documentation: add information to driver_usage file
  2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
                   ` (4 preceding siblings ...)
  2018-12-17 11:33 ` [PATCH v3 5/6] staging: most: sound: remove channel number from ALSA card's long name Christian Gromm
@ 2018-12-17 11:33 ` Christian Gromm
  5 siblings, 0 replies; 8+ messages in thread
From: Christian Gromm @ 2018-12-17 11:33 UTC (permalink / raw)
  To: gregkh; +Cc: Christian Gromm, driverdev-devel

This patch updates driver_usage.txt file to reflect the latest changes
that this patch set introduces.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
v2:
	nothing
v3:
	nothing

 drivers/staging/most/Documentation/driver_usage.txt | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/Documentation/driver_usage.txt b/drivers/staging/most/Documentation/driver_usage.txt
index bb9b4e8..da7a8f4 100644
--- a/drivers/staging/most/Documentation/driver_usage.txt
+++ b/drivers/staging/most/Documentation/driver_usage.txt
@@ -142,8 +142,9 @@ Cdev component example:
 
 Sound component example:
 
-The sound component needs an additional parameter to determine the audio
-resolution that is going to be used. The following formats are available:
+The sound component needs additional parameters to determine the audio
+resolution that is going to be used and to trigger the registration of a
+sound card with ALSA. The following audio formats are available:
 
 	- "1x8" (Mono)
 	- "2x16" (16-bit stereo)
@@ -151,9 +152,18 @@ resolution that is going to be used. The following formats are available:
 	- "2x32" (32-bit stereo)
 	- "6x16" (16-bit surround 5.1)
 
-        $ echo "mdev0:ep_81:sound:most51_playback.6x16" >$(DRV_DIR)/add_link
+To make the sound module create a sound card and register it with ALSA the
+string "create" needs to be attached to the module parameter section of the
+configuration string. To create a sound card with with two playback devices
+(linked to channel ep01 and ep02) and one capture device (linked to channel
+ep83) the following is written to the add_link file:
 
+        $ echo "mdev0:ep01:sound:most51_playback.6x16" >$(DRV_DIR)/add_link
+        $ echo "mdev0:ep02:sound:most_playback.2x16" >$(DRV_DIR)/add_link
+        $ echo "mdev0:ep83:sound:most_capture.2x16.create" >$(DRV_DIR)/add_link
 
+The link names (most51_playback, most_playback and most_capture) will
+become the names of the PCM devices of the sound card.
 
 		Section 2.3 USB Padding
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device
  2018-12-17 11:33 ` [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device Christian Gromm
@ 2018-12-17 11:45   ` Dan Carpenter
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2018-12-17 11:45 UTC (permalink / raw)
  To: Christian Gromm; +Cc: gregkh, driverdev-devel

On Mon, Dec 17, 2018 at 12:33:49PM +0100, Christian Gromm wrote:
> +static void release_adapter(struct sound_adapter *adpt)
> +{
> +	struct channel *channel, *tmp;
> +
> +	list_for_each_entry_safe(channel, tmp, &adpt->dev_list, list) {
> +		list_del(&channel->list);
> +		kfree(channel);
> +	}
> +	snd_card_free(adpt->card);

I'm sorry for drawing this out.  I should have seen this problem in the
v2 patch.  snd_card_free() does not take NULL pointers.  We need to
say:

	if (adpt->card)
		snd_card_free(adpt->card);

> +	list_del(&adpt->list);
> +	kfree(adpt);
> +}
> +
>  /**
>   * audio_probe_channel - probe function of the driver module
>   * @iface: pointer to interface instance
> @@ -553,7 +581,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
>  			       char *arg_list)
>  {
>  	struct channel *channel;
> -	struct snd_card *card;
> +	struct sound_adapter *adpt;
>  	struct snd_pcm *pcm;
>  	int playback_count = 0;
>  	int capture_count = 0;
> @@ -561,6 +589,7 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
>  	int direction;
>  	char *card_name;
>  	u16 ch_num;
> +	u8 create = 0;
>  	char *sample_res;
>  
>  	if (!iface)
> @@ -571,6 +600,39 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
>  		return -EINVAL;
>  	}
>  
> +	ret = split_arg_list(arg_list, &card_name, &ch_num, &sample_res,
> +			     &create);
> +	if (ret < 0)
> +		return ret;
> +
> +	list_for_each_entry(adpt, &adpt_list, list) {
> +		if (adpt->iface != iface)
> +			continue;
> +		if (adpt->registered)
> +			return -ENOSPC;
> +		adpt->pcm_dev_idx++;
> +		goto skip_adpt_alloc;
> +	}
> +	adpt = kzalloc(sizeof(*adpt), GFP_KERNEL);
> +	if (!adpt)
> +		return -ENOMEM;
> +
> +	adpt->iface = iface;
> +	INIT_LIST_HEAD(&adpt->dev_list);
> +	iface->priv = adpt;
> +	list_add_tail(&adpt->list, &adpt_list);
> +	ret = snd_card_new(&iface->dev, -1, card_name, THIS_MODULE,
> +			   sizeof(*channel), &adpt->card);
> +	if (ret < 0)
> +		goto err_free_card;

Otherwise this error path will oops.

[ Snip ]

>  err_free_card:
> -	snd_card_free(card);
> +	release_adapter(adpt);
>  	return ret;
>  }

I feel quite bad for making you redo this over and over.  :(

regards,
dan carpenter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-12-17 11:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-17 11:33 [PATCH v3 0/6] staging: most: sound: change sound card layout Christian Gromm
2018-12-17 11:33 ` [PATCH v3 1/6] staging: most: sound: create one sound card w/ multiple PCM devices per MOST device Christian Gromm
2018-12-17 11:45   ` Dan Carpenter
2018-12-17 11:33 ` [PATCH v3 2/6] staging: most: sound: correct label name Christian Gromm
2018-12-17 11:33 ` [PATCH v3 3/6] staging: most: sound: rename variable Christian Gromm
2018-12-17 11:33 ` [PATCH v3 4/6] staging: most: sound: use static name for ALSA card Christian Gromm
2018-12-17 11:33 ` [PATCH v3 5/6] staging: most: sound: remove channel number from ALSA card's long name Christian Gromm
2018-12-17 11:33 ` [PATCH v3 6/6] staging: most: Documentation: add information to driver_usage file Christian Gromm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.