From patchwork Tue Feb 11 03:12:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Wang X-Patchwork-Id: 1236136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GnsZ491pz9sRR; Tue, 11 Feb 2020 14:13:20 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1j1Lz9-000198-ME; Tue, 11 Feb 2020 03:13:15 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1Lz7-00018F-Os for kernel-team@lists.ubuntu.com; Tue, 11 Feb 2020 03:13:13 +0000 Received: from [114.254.46.93] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1Lz6-0005pj-V0 for kernel-team@lists.ubuntu.com; Tue, 11 Feb 2020 03:13:13 +0000 From: Hui Wang To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 1/3] ASoC: improve the DMI long card code in asoc-core Date: Tue, 11 Feb 2020 11:12:50 +0800 Message-Id: <20200211031252.6620-2-hui.wang@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200211031252.6620-1-hui.wang@canonical.com> References: <20200211031252.6620-1-hui.wang@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jaroslav Kysela BugLink: https://launchpad.net/bugs/1862712 Add append_dmi_string() function and make the code more readable. Signed-off-by: Jaroslav Kysela Reviewed-by: Pierre-Louis Bossart Link: https://lore.kernel.org/r/20191120174435.30920-1-perex@perex.cz Signed-off-by: Mark Brown (cherry picked from commit 4e01e5dbba96f731119f3f1a6bf51b54c98c5940) Signed-off-by: Hui Wang --- sound/soc/soc-core.c | 66 +++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 88978a3036c4..c57363059f89 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1729,6 +1729,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 @@ -1763,61 +1780,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"); @@ -1825,16 +1817,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; From patchwork Tue Feb 11 03:12:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Wang X-Patchwork-Id: 1236134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GnsZ4zf5z9sRX; Tue, 11 Feb 2020 14:13:20 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1j1LzB-00019x-01; Tue, 11 Feb 2020 03:13:16 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1Lz9-000192-98 for kernel-team@lists.ubuntu.com; Tue, 11 Feb 2020 03:13:15 +0000 Received: from [114.254.46.93] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1Lz8-0005pj-Fu for kernel-team@lists.ubuntu.com; Tue, 11 Feb 2020 03:13:15 +0000 From: Hui Wang To: kernel-team@lists.ubuntu.com Subject: [SRU][Focal][PATCH 2/3] ASoC: DMI long name - avoid to add board name if matches with product name Date: Tue, 11 Feb 2020 11:12:51 +0800 Message-Id: <20200211031252.6620-3-hui.wang@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200211031252.6620-1-hui.wang@canonical.com> References: <20200211031252.6620-1-hui.wang@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jaroslav Kysela BugLink: https://launchpad.net/bugs/1862712 Current code: LENOVO-20QE000VMC-ThinkPadX1Carbon7th-20QE000VMC With the patch: LENOVO-20QE000VMC-ThinkPadX1Carbon7th Signed-off-by: Jaroslav Kysela Link: https://lore.kernel.org/r/20191120174435.30920-2-perex@perex.cz Reviewed-by: Pierre-Louis Bossart Signed-off-by: Mark Brown (cherry picked from commit 39870b0dec68ed7dd814beb697e541670975c7d8) Signed-off-by: Hui Wang --- sound/soc/soc-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c57363059f89..423e59ea2069 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1809,7 +1809,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");