From patchwork Thu Oct 20 20:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej S. Szmigiero" X-Patchwork-Id: 6398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp319300wrr; Thu, 20 Oct 2022 13:58:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EpN1wROeRhdlxV/AgByeUD9eId1W2SX0ogIWOn1bZs52XtUiHQjsjEqs6qChq9PhzR4KB X-Received: by 2002:a05:6402:3806:b0:450:bad8:8cd5 with SMTP id es6-20020a056402380600b00450bad88cd5mr14412239edb.305.1666299510634; Thu, 20 Oct 2022 13:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666299510; cv=none; d=google.com; s=arc-20160816; b=dtEgdB4tw1odxjB9m9pGUskVFfmvOHqbnc1lHkCgX+R0DrEsL70k4zWxRmuIKbgaQh Rg39zm8mqFV/MqRpVmmia7/f5Ys2IFR9fiIrrqTRMwBxg6GOlV8IYmGSZ7mRmEZX+2H1 a1loevb/sCW5xlMVnTHgQY+wS9YOQP7+wRTx2OCeuSVzizvjbUfXYa1yj653SvioUJU/ yft1Sr04fNOqfyTC1aiw8l4cqSuPQsv+kwJXvn0I88EOC7Vtx9C+4yfwD4/JPqlAqtw7 ti4KcWDKK5A/orSwqFD9zDNPb4ytAQ0jr+qK/YrNRG8J8Cbs1W1CXA6ItRAg6zd8Tp/g GtnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=verngwKXvaugahFxwVn6wZIK3S9n5X4DmomiiARplns=; b=so6XT+VFrwe65q4NG7oGeAk9GK6Edd6SMvqjatK97CCudnatm0cK0QSui/hRkIrEpv 3T8Xu7Ym/FGHIkpy0uvF8udnLy0qIGJ5fv/StO4Lx5n05dTn6k0HN7sLEfLzEWkdADUs 0UlFNjDur0zYtfN7xMys2B4ucAkLqEciIU0z4Ch6uR8Foepmq5IZ8LR259hIsyqcxbJ4 yq6zZD42oKN63WDOvt7EVyb+wWV7XdgpaCKJPhjQfahJC6q+lRVyom54cNCIlZH6ffqk Rco4JEbV+IGDDxviQ09p1wkKjue45n2EUsJnIDPdpioT5hkBRya5EHAo1DEaxgyufU/P yDRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020aa7c947000000b00459400b7ae0si15353710edt.613.2022.10.20.13.58.05; Thu, 20 Oct 2022 13:58:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbiJTUsB (ORCPT + 99 others); Thu, 20 Oct 2022 16:48:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbiJTUrx (ORCPT ); Thu, 20 Oct 2022 16:47:53 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBD6F1B2338 for ; Thu, 20 Oct 2022 13:47:36 -0700 (PDT) Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1olcRU-0007Vc-JN; Thu, 20 Oct 2022 22:47:04 +0200 From: "Maciej S. Szmigiero" To: Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] ALSA: ac97: Use snd_ctl_rename() to rename a control Date: Thu, 20 Oct 2022 22:46:26 +0200 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747241675371631235?= X-GMAIL-MSGID: =?utf-8?q?1747241675371631235?= From: "Maciej S. Szmigiero" With the recent addition of hashed controls lookup it's not enough to just update the control name field, the hash entries for the modified control have to be updated too. snd_ctl_rename() takes care of that, so use it instead of directly modifying the control name. While we are at it, check also that the new control name doesn't accidentally overwrite the available buffer space. Fixes: c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups") Cc: stable@vger.kernel.org Signed-off-by: Maciej S. Szmigiero --- sound/pci/ac97/ac97_codec.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index ceead55f13ab1..ff685321f1a11 100644 --- a/sound/pci/ac97/ac97_codec.c +++ b/sound/pci/ac97/ac97_codec.c @@ -2656,11 +2656,18 @@ EXPORT_SYMBOL(snd_ac97_resume); */ static void set_ctl_name(char *dst, const char *src, const char *suffix) { - if (suffix) - sprintf(dst, "%s %s", src, suffix); - else - strcpy(dst, src); -} + const size_t msize = SNDRV_CTL_ELEM_ID_NAME_MAXLEN; + + if (suffix) { + if (snprintf(dst, msize, "%s %s", src, suffix) >= msize) + pr_warn("ALSA: AC97 control name '%s %s' truncated to '%s'\n", + src, suffix, dst); + } else { + if (strscpy(dst, src, msize) < 0) + pr_warn("ALSA: AC97 control name '%s' truncated to '%s'\n", + src, dst); + } +} /* remove the control with the given name and optional suffix */ static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name, @@ -2687,8 +2694,11 @@ static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src, const char *dst, const char *suffix) { struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix); + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + if (kctl) { - set_ctl_name(kctl->id.name, dst, suffix); + set_ctl_name(name, dst, suffix); + snd_ctl_rename(ac97->bus->card, kctl, name); return 0; } return -ENOENT; @@ -2707,11 +2717,17 @@ static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, const char *s2, const char *suffix) { struct snd_kcontrol *kctl1, *kctl2; + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + kctl1 = ctl_find(ac97, s1, suffix); kctl2 = ctl_find(ac97, s2, suffix); if (kctl1 && kctl2) { - set_ctl_name(kctl1->id.name, s2, suffix); - set_ctl_name(kctl2->id.name, s1, suffix); + set_ctl_name(name, s2, suffix); + snd_ctl_rename(ac97->bus->card, kctl1, name); + + set_ctl_name(name, s1, suffix); + snd_ctl_rename(ac97->bus->card, kctl2, name); + return 0; } return -ENOENT;