From patchwork Thu Oct 20 20:46:21 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: 6393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp316043wrr; Thu, 20 Oct 2022 13:48:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/3Devuknf910Fw4Jh6nT51v/vn9Ft8zFSXveQVBMi42/QRCBHSTbDP0yngUIy7Z+CXc4k X-Received: by 2002:a17:907:6d27:b0:78d:46f6:c59e with SMTP id sa39-20020a1709076d2700b0078d46f6c59emr12349663ejc.30.1666298911529; Thu, 20 Oct 2022 13:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666298911; cv=none; d=google.com; s=arc-20160816; b=vfml9B+Gf+0bXlb6E10mqPe44XX9Y0PEXIbvzXJDbQ6t+7pfcMXDFRa6e0bkusBvOi 3md6E1pzECisfhwMu8V/NLT3wnVwgnR9KEbMeB/SHl5p18Tsz6ssKx9zYcIzcZcOp2Y1 JfAkY1n0cBwTSFHnc/48eWFmtZt5wc05sIVG6HpZfqdwAxBFMWOrBLKEn6SMtGNRp1cI HR+3sxE7HwXQ5V9gdOVB086v0nvKeasls7rbLWBctoBhNzfiFQg/guPE8NNPFrJ7uPCZ CSrTHGbVQOKI2LGRRlpbefvOHQXPCKTopDeZ9MJQIkJxNfBVPVhNJE2gqfN0JZXVzAAm NUGA== 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=Dtd57xMd2zyxu82Sf0qwTa41GDz4tMf3CL4dxGtITlY=; b=iA72Z0NT67+zStG9mWCKlYZZd00jecyHyifaG1xGtyuwttBLFxhTbTmrg32aA71con xtZYvTpXstE6+7+uCvU/3y73HxOcenR0ZIY2a+T0bF7JQ8ckmxWa3qKfaZON4LuWivQR /s2Lj5+lv9mTX1YIGU6+ABohGxP279Qg9I5Fd2CrZyV1s8AUgMH8OYF4vR4z/R/d86ki /1HJ7Zv9w3gwkKG40m2e9rEYqCV8lPkU5qjB/EolGWpfr82qqGU3OOz37P7xWwNRqdp/ F0Dl1marxcXOK/nhGWrCFT0k20N2/L7xg831t+VRNVWBQ+Sl1YPDWYhOV68O0ROukXAK CPlQ== 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 bx20-20020a170906a1d400b0078d40f7ef1fsi16143432ejb.330.2022.10.20.13.48.07; Thu, 20 Oct 2022 13:48:31 -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 S229768AbiJTUri (ORCPT + 99 others); Thu, 20 Oct 2022 16:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbiJTUrd (ORCPT ); Thu, 20 Oct 2022 16:47:33 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01835170448 for ; Thu, 20 Oct 2022 13:47:20 -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 1olcR3-0007Ue-TS; Thu, 20 Oct 2022 22:46:37 +0200 From: "Maciej S. Szmigiero" To: Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] ALSA: control: add snd_ctl_rename() Date: Thu, 20 Oct 2022 22:46:21 +0200 Message-Id: <4170b71117ea81357a4f7eb8410f7cde20836c70.1666296963.git.maciej.szmigiero@oracle.com> 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?1747241047661116840?= X-GMAIL-MSGID: =?utf-8?q?1747241047661116840?= From: "Maciej S. Szmigiero" Add a snd_ctl_rename() function that takes care of updating the control hash entries for callers that already have the relevant struct snd_kcontrol at hand and hold the control write lock (or simply haven't registered the card yet). Fixes: c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups") Cc: stable@vger.kernel.org Signed-off-by: Maciej S. Szmigiero --- include/sound/control.h | 1 + sound/core/control.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sound/control.h b/include/sound/control.h index eae443ba79ba5..cc3dcc6cfb0f2 100644 --- a/include/sound/control.h +++ b/include/sound/control.h @@ -138,6 +138,7 @@ int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol); int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, bool add_on_replace); int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id); int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id); +void snd_ctl_rename(struct snd_card *card, struct snd_kcontrol *kctl, const char *name); int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, int active); struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid); struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id); diff --git a/sound/core/control.c b/sound/core/control.c index a7271927d875f..50e7ba66f1876 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -753,6 +753,29 @@ int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id, } EXPORT_SYMBOL(snd_ctl_rename_id); +/** + * snd_ctl_rename - rename the control on the card + * @card: the card instance + * @kctl: the control to rename + * @name: the new name + * + * Renames the specified control on the card to the new name. + * + * Make sure to take the control write lock - down_write(&card->controls_rwsem). + */ +void snd_ctl_rename(struct snd_card *card, struct snd_kcontrol *kctl, + const char *name) +{ + remove_hash_entries(card, kctl); + + if (strscpy(kctl->id.name, name, sizeof(kctl->id.name)) < 0) + pr_warn("ALSA: Renamed control new name '%s' truncated to '%s'\n", + name, kctl->id.name); + + add_hash_entries(card, kctl); +} +EXPORT_SYMBOL(snd_ctl_rename); + #ifndef CONFIG_SND_CTL_FAST_LOOKUP static struct snd_kcontrol * snd_ctl_find_numid_slow(struct snd_card *card, unsigned int numid)