Skip to contentSkip to conversation

ASoC: improve the DMI long card code in asoc-core

PATCH In review Jaroslav Kysela 3 participants 8 messages Nov 20, 2019 – Nov 22, 2019

Subsystems (2)
lore
Share & tools
lore

Jaroslav Kysela

author maintainer
#0 lore raw

PATCH v2 1/2 ASoC: improve the DMI long card code in asoc-core

Add append_dmi_string() function and make the code more readable.

Cc Mark Brown <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
---
 sound/soc/soc-core.c | 66 +++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 41 deletions(-)
sound/soc/soc-core.c +25 -41
index b4683d4588ee..db56507174bd 100644
@@ -1755,6 +1755,23 @@ static int is_dmi_valid(const char *field)
 	return 1;
 }
 
+/*
+ * Append a string to card->dmi_longname with character cleanups.
+ */
+static void append_dmi_string(struct snd_soc_card *card, const char *str)
+{
+	char *dst = card->dmi_longname;
+	size_t dst_len = sizeof(card->dmi_longname);
+	size_t len;
+
+	len = strlen(dst);
+	snprintf(dst + len, dst_len - len, "-%s", str);
+
+	len++;	/* skip the separator "-" */
+	if (len < dst_len)
+		cleanup_dmi_name(dst + len);
+}
+
 /**
  * snd_soc_set_dmi_name() - Register DMI names to card
  * @card: The card to register DMI names
@@ -1789,61 +1806,36 @@ static int is_dmi_valid(const char *field)
 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 {
 	const char *vendor, *product, *product_version, *board;
-	size_t longname_buf_size = sizeof(card->snd_card->longname);
-	size_t len;
 
 	if (card->long_name)
 		return 0; /* long name already set by driver or from DMI */
 
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */
 	vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
 	if (!vendor || !is_dmi_valid(vendor)) {
 		dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
 		return 0;
 	}
 
-	snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
-			 "%s", vendor);
+	snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
 	cleanup_dmi_name(card->dmi_longname);
 
 	product = dmi_get_system_info(DMI_PRODUCT_NAME);
 	if (product && is_dmi_valid(product)) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", product);
-
-		len++;	/* skip the separator "-" */
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
+		append_dmi_string(card, product);
 
 		/*
 		 * some vendors like Lenovo may only put a self-explanatory
 		 * name in the product version field
 		 */
 		product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
-		if (product_version && is_dmi_valid(product_version)) {
-			len = strlen(card->dmi_longname);
-			snprintf(card->dmi_longname + len,
-				 longname_buf_size - len,
-				 "-%s", product_version);
-
-			len++;
-			if (len < longname_buf_size)
-				cleanup_dmi_name(card->dmi_longname + len);
-		}
+		if (product_version && is_dmi_valid(product_version))
+			append_dmi_string(card, product_version);
 	}
 
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 	if (board && is_dmi_valid(board)) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", board);
-
-		len++;
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
+		append_dmi_string(card, board);
 	} else if (!product) {
 		/* fall back to using legacy name */
 		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
@@ -1851,16 +1843,8 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 	}
 
 	/* Add flavour to dmi long name */
-	if (flavour) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", flavour);
-
-		len++;
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
-	}
+	if (flavour)
+		append_dmi_string(card, flavour);
 
 	/* set the card long name */
 	card->long_name = card->dmi_longname;
Signature · 5 lines
2.20.1
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
author maintainer
#1 lore raw

PATCH v2 2/2 ASoC: DMI long name - avoid to add board name if matches with product name

Current code:

LENOVO-20QE000VMC-ThinkPadX1Carbon7th-20QE000VMC

With the patch:

LENOVO-20QE000VMC-ThinkPadX1Carbon7th

---
 sound/soc/soc-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/soc-core.c +2 -1
index db56507174bd..ace7e518bc5a 100644
@@ -1835,7 +1835,8 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 	if (board && is_dmi_valid(board)) {
-		append_dmi_string(card, board);
+		if (!product || strcasecmp(board, product))
+			append_dmi_string(card, board);
 	} else if (!product) {
 		/* fall back to using legacy name */
 		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
Signature · 5 lines
2.20.1
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#2 lore raw

[alsa-devel] Applied "ASoC: DMI long name - avoid to add board name if matches with product name" to the asoc tree

The patch

ASoC: DMI long name - avoid to add board name if matches with product name

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From 39870b0dec68ed7dd814beb697e541670975c7d8 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 20 Nov 2019 18:44:35 +0100
Subject: [PATCH] ASoC: DMI long name - avoid to add board name if matches with
product name

Current code:

LENOVO-20QE000VMC-ThinkPadX1Carbon7th-20QE000VMC

With the patch:

LENOVO-20QE000VMC-ThinkPadX1Carbon7th

---
 sound/soc/soc-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/soc-core.c +2 -1
index a1f4d64a0a18..062653ab03a3 100644
@@ -1798,7 +1798,8 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 	if (board && is_dmi_valid(board)) {
-		append_dmi_string(card, board);
+		if (!product || strcasecmp(board, product))
+			append_dmi_string(card, board);
 	} else if (!product) {
 		/* fall back to using legacy name */
 		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
Signature · 6 lines
2.20.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#3 lore raw
In reply to Jaroslav Kysela

sound/soc/soc-core.c static int is_dmi_valid(const char *field) · line 1813

Quoted 2 lines · Jaroslav Kysela
sound/soc/soc-core.c +1 -1
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */

I'm worried about this from an ABI point of view with people's UCM files. But perhaps I'm worrying about nothing?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author maintainer
#4 lore raw

Dne 21. 11. 19 v 12:51 Mark Brown napsal(a):

Quoted 7 lines · Jaroslav Kysela

sound/soc/soc-core.c static int is_dmi_valid(const char *field) · line 1813

Quoted 3 lines
sound/soc/soc-core.c +1 -1
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */

I'm worried about this from an ABI point of view with people's UCM files. But perhaps I'm worrying about nothing?

Mark,

this is just the C comment fix. The long name is already in
vendor-product-version-board - no dots as delimiters (but does are allowed in the fields like version strings). This code improvement does not change the format of the generated long name string from the DMI information.

Just see the examples in the soc-core.c comment for snd_soc_set_dmi_name():

* Possible card long names may be:
* DellInc.-XPS139343-01-0310JH
* ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
* Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX

Jaroslav

Signature · 6 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#5 lore raw
Quoted 9 lines · Jaroslav Kysela

Dne 21. 11. 19 v 12:51 Mark Brown napsal(a):

Quoted 7 lines · Jaroslav Kysela

sound/soc/soc-core.c static int is_dmi_valid(const char *field) · line 1813

Quoted 3 lines
sound/soc/soc-core.c +1 -1
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */

I'm worried about this from an ABI point of view with people's UCM files. But perhaps I'm worrying about nothing?

Quoted 4 lines

this is just the C comment fix. The long name is already in
vendor-product-version-board - no dots as delimiters (but does are allowed in the fields like version strings). This code improvement does not change the format of the generated long name string from the DMI information.

Ah, it looked from my initial scan like it was being changed as a result of the factoring out of the append code.

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw
Quoted 10 lines · Mark Brown
Quoted 8 lines · Jaroslav Kysela

Dne 21. 11. 19 v 12:51 Mark Brown napsal(a):

Quoted 7 lines · Jaroslav Kysela

sound/soc/soc-core.c static int is_dmi_valid(const char *field) · line 1813

Quoted 3 lines
sound/soc/soc-core.c +1 -1
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */

I'm worried about this from an ABI point of view with people's UCM files. But perhaps I'm worrying about nothing?

Quoted 7 lines
Quoted 4 lines

this is just the C comment fix. The long name is already in
vendor-product-version-board - no dots as delimiters (but does are allowed in the fields like version strings). This code improvement does not change the format of the generated long name string from the DMI information.

Ah, it looked from my initial scan like it was being changed as a result of the factoring out of the append code.

I had the same reaction on v1, it's just cleaning up a bad comment indeed.

This looks good to me, especially the removal of redundant parts, so for the patch 1..2

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

maintainer
#7 lore raw

[alsa-devel] Applied "ASoC: improve the DMI long card code in asoc-core" to the asoc tree

In reply to Jaroslav Kysela

The patch

ASoC: improve the DMI long card code in asoc-core

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From 4e01e5dbba96f731119f3f1a6bf51b54c98c5940 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <[email protected]>
Date: Wed, 20 Nov 2019 18:44:34 +0100
Subject: [PATCH] ASoC: improve the DMI long card code in asoc-core

Add append_dmi_string() function and make the code more readable.

---
 sound/soc/soc-core.c | 66 +++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 41 deletions(-)
sound/soc/soc-core.c +25 -41
index cc0ef0fcc005..a1f4d64a0a18 100644
@@ -1718,6 +1718,23 @@ static int is_dmi_valid(const char *field)
 	return 1;
 }
 
+/*
+ * Append a string to card->dmi_longname with character cleanups.
+ */
+static void append_dmi_string(struct snd_soc_card *card, const char *str)
+{
+	char *dst = card->dmi_longname;
+	size_t dst_len = sizeof(card->dmi_longname);
+	size_t len;
+
+	len = strlen(dst);
+	snprintf(dst + len, dst_len - len, "-%s", str);
+
+	len++;	/* skip the separator "-" */
+	if (len < dst_len)
+		cleanup_dmi_name(dst + len);
+}
+
 /**
  * snd_soc_set_dmi_name() - Register DMI names to card
  * @card: The card to register DMI names
@@ -1752,61 +1769,36 @@ static int is_dmi_valid(const char *field)
 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 {
 	const char *vendor, *product, *product_version, *board;
-	size_t longname_buf_size = sizeof(card->snd_card->longname);
-	size_t len;
 
 	if (card->long_name)
 		return 0; /* long name already set by driver or from DMI */
 
-	/* make up dmi long name as: vendor.product.version.board */
+	/* make up dmi long name as: vendor-product-version-board */
 	vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
 	if (!vendor || !is_dmi_valid(vendor)) {
 		dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
 		return 0;
 	}
 
-	snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
-			 "%s", vendor);
+	snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
 	cleanup_dmi_name(card->dmi_longname);
 
 	product = dmi_get_system_info(DMI_PRODUCT_NAME);
 	if (product && is_dmi_valid(product)) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", product);
-
-		len++;	/* skip the separator "-" */
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
+		append_dmi_string(card, product);
 
 		/*
 		 * some vendors like Lenovo may only put a self-explanatory
 		 * name in the product version field
 		 */
 		product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
-		if (product_version && is_dmi_valid(product_version)) {
-			len = strlen(card->dmi_longname);
-			snprintf(card->dmi_longname + len,
-				 longname_buf_size - len,
-				 "-%s", product_version);
-
-			len++;
-			if (len < longname_buf_size)
-				cleanup_dmi_name(card->dmi_longname + len);
-		}
+		if (product_version && is_dmi_valid(product_version))
+			append_dmi_string(card, product_version);
 	}
 
 	board = dmi_get_system_info(DMI_BOARD_NAME);
 	if (board && is_dmi_valid(board)) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", board);
-
-		len++;
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
+		append_dmi_string(card, board);
 	} else if (!product) {
 		/* fall back to using legacy name */
 		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
@@ -1814,16 +1806,8 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
 	}
 
 	/* Add flavour to dmi long name */
-	if (flavour) {
-		len = strlen(card->dmi_longname);
-		snprintf(card->dmi_longname + len,
-			 longname_buf_size - len,
-			 "-%s", flavour);
-
-		len++;
-		if (len < longname_buf_size)
-			cleanup_dmi_name(card->dmi_longname + len);
-	}
+	if (flavour)
+		append_dmi_string(card, flavour);
 
 	/* set the card long name */
 	card->long_name = card->dmi_longname;
Signature · 6 lines
2.20.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel