ASoC: improve the DMI long card code in asoc-core
Add append_dmi_string() function and make the code more readable. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20191120174435.30920-1-perex@perex.cz Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Родитель
3efd723305
Коммит
4e01e5dbba
|
@ -1718,6 +1718,23 @@ static int is_dmi_valid(const char *field)
|
||||||
return 1;
|
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
|
* snd_soc_set_dmi_name() - Register DMI names to card
|
||||||
* @card: The card to register DMI names
|
* @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)
|
int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
|
||||||
{
|
{
|
||||||
const char *vendor, *product, *product_version, *board;
|
const char *vendor, *product, *product_version, *board;
|
||||||
size_t longname_buf_size = sizeof(card->snd_card->longname);
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (card->long_name)
|
if (card->long_name)
|
||||||
return 0; /* long name already set by driver or from DMI */
|
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);
|
vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
|
||||||
if (!vendor || !is_dmi_valid(vendor)) {
|
if (!vendor || !is_dmi_valid(vendor)) {
|
||||||
dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
|
dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
|
snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
|
||||||
"%s", vendor);
|
|
||||||
cleanup_dmi_name(card->dmi_longname);
|
cleanup_dmi_name(card->dmi_longname);
|
||||||
|
|
||||||
product = dmi_get_system_info(DMI_PRODUCT_NAME);
|
product = dmi_get_system_info(DMI_PRODUCT_NAME);
|
||||||
if (product && is_dmi_valid(product)) {
|
if (product && is_dmi_valid(product)) {
|
||||||
len = strlen(card->dmi_longname);
|
append_dmi_string(card, product);
|
||||||
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);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* some vendors like Lenovo may only put a self-explanatory
|
* some vendors like Lenovo may only put a self-explanatory
|
||||||
* name in the product version field
|
* name in the product version field
|
||||||
*/
|
*/
|
||||||
product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
|
product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
|
||||||
if (product_version && is_dmi_valid(product_version)) {
|
if (product_version && is_dmi_valid(product_version))
|
||||||
len = strlen(card->dmi_longname);
|
append_dmi_string(card, product_version);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
board = dmi_get_system_info(DMI_BOARD_NAME);
|
board = dmi_get_system_info(DMI_BOARD_NAME);
|
||||||
if (board && is_dmi_valid(board)) {
|
if (board && is_dmi_valid(board)) {
|
||||||
len = strlen(card->dmi_longname);
|
append_dmi_string(card, board);
|
||||||
snprintf(card->dmi_longname + len,
|
|
||||||
longname_buf_size - len,
|
|
||||||
"-%s", board);
|
|
||||||
|
|
||||||
len++;
|
|
||||||
if (len < longname_buf_size)
|
|
||||||
cleanup_dmi_name(card->dmi_longname + len);
|
|
||||||
} else if (!product) {
|
} else if (!product) {
|
||||||
/* fall back to using legacy name */
|
/* fall back to using legacy name */
|
||||||
dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
|
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 */
|
/* Add flavour to dmi long name */
|
||||||
if (flavour) {
|
if (flavour)
|
||||||
len = strlen(card->dmi_longname);
|
append_dmi_string(card, flavour);
|
||||||
snprintf(card->dmi_longname + len,
|
|
||||||
longname_buf_size - len,
|
|
||||||
"-%s", flavour);
|
|
||||||
|
|
||||||
len++;
|
|
||||||
if (len < longname_buf_size)
|
|
||||||
cleanup_dmi_name(card->dmi_longname + len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the card long name */
|
/* set the card long name */
|
||||||
card->long_name = card->dmi_longname;
|
card->long_name = card->dmi_longname;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче