Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1570810rwi; Thu, 20 Oct 2022 14:20:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7PIzrYucWHZsOgL/Hkur7MigESlMx0KRG92fJaHT1ptB0PYauy+ptJsX0JSd50GqH8eAkJ X-Received: by 2002:a05:6402:90e:b0:443:ec4b:2b03 with SMTP id g14-20020a056402090e00b00443ec4b2b03mr13862227edz.71.1666300811531; Thu, 20 Oct 2022 14:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666300811; cv=none; d=google.com; s=arc-20160816; b=JmgdCstDp3q42ar+Hx59aRTZsMWuGi+dxjN+vuq7vqCGYIez4WRaeQrGGMsykA/xJS jwB2fe4x6TtGUy9eG8KsC97J40C8AZTsQKBY7kb6o0OVxqwgLVfVHgEW3t0baE9hwlDB lQda/ybuJuRlfnKU0q5JkjvHILgaTwGFEuWk7zDAuEn9GidqySqGL361jikgcaDXUG33 fdWCmmXgpayxYG2X1O4fLNAMmrJl8Xor3xh2DqP1M47/wl6GdTgh+6hRt3kS7Pv2Epgx hZbUu73JbmB6DPv82/5gXd2caCmu6jTbNXh6GUvpZ1J9dsKwQeExvEmlZ0X+7E8/NhzW rnZg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn41-20020a1709070d2900b0078b3edae43asi18992056ejc.50.2022.10.20.14.19.43; Thu, 20 Oct 2022 14:20:11 -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 Content-Transfer-Encoding: 8bit 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 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;