Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3990853rwd; Tue, 23 May 2023 01:12:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5q5ikWOAagE21qJY1ZfV81Di/AGOQMIWbLVuNTHcd8sVc/wtJ0MPfmTpSzGk6NgmczOAdq X-Received: by 2002:a17:90a:c692:b0:24d:f113:2e2c with SMTP id n18-20020a17090ac69200b0024df1132e2cmr14267379pjt.16.1684829527932; Tue, 23 May 2023 01:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684829527; cv=none; d=google.com; s=arc-20160816; b=f1skc5XnQrZ7cdzmyjcOc4xAqU9S1fN64OamX/krE8JvDCtnFYB5sj6uzRnXqDbX9M sDCazX1BFWqGLGxK3DPH2p90cUcwhElw6M+Eshl/QKOMrltouezQ5uDJoPJ3nn26cyyp UwCJHnyEKegeOG1scZDFUlIXG2mO6wcw6nPzyJSMNtL+MOWeUjvim504aHa5irjpbxOD YEO742auVgPk/VfxHwTw7WgqiT+U3OHg54Wr8buoFmiBkAdeVWCwoZkp8qmWmYTSdkpV LWTKV+laJ+Zs/K1mxuOfzm3eI+IdDnlHk6nigocdLbIkoQWJZxbFPJf3IB3LzSKtHYHj Al+Q== 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 :dkim-signature:dkim-signature; bh=DHrx6V+uewqzX9UqFfIqqGA6/p4XBbhXfx4OFs0RTCU=; b=JfjywD756XmJSHE2mhyzizwMQA8RIx2SDVRv1HwM5E8fmpA4sByRKqD4np/8ftiSkL JlUBXzOTfsKtjx77J57lZN2MhNPp/kF+Yr3KpOBTag1fZlbuSyb+SD215e1RQXCzvrb8 0E7YD/1uMjcVa4NznWzxiABTseOuZgonOoUp3JpuvwUzmt2y31nPSP3K+9Uj+XzHkXDf NT1wAsyrWi1Bo7vK9Fc5DwqKgAedVPbCQ8b5qtT/Y5mlvZjizAGA+c8LCA6f9+j2XqHu lQAAYjGHNoDF7+RwOpdr3ImVcSdG+szzVtlT11516/iiUrGKZa8VweTHZg8keCLTvNuc 8m5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xJlS6E9i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="tA9lxT/A"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oc9-20020a17090b1c0900b0024de687d6e3si4052502pjb.111.2023.05.23.01.11.56; Tue, 23 May 2023 01:12:07 -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; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xJlS6E9i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="tA9lxT/A"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235944AbjEWH4c (ORCPT + 99 others); Tue, 23 May 2023 03:56:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235370AbjEWHym (ORCPT ); Tue, 23 May 2023 03:54:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795A610D4 for ; Tue, 23 May 2023 00:54:23 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C53762191A; Tue, 23 May 2023 07:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684828445; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DHrx6V+uewqzX9UqFfIqqGA6/p4XBbhXfx4OFs0RTCU=; b=xJlS6E9iJ2EFF+DymKFeMpQ084cBqDmConz1kdV5Oas2qUnII0Td6kqFhGtxhT3q/nIEiA 7WEBLg1sbVGSTQGaA8kChbcSa5XUk+R6g/q6ALltoeQC8lh4GuKbFgXiPsyk9DmeEJPZJw E5mmWBD9QxU+IV3Pa1DWkEhYNLKkVlY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684828445; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DHrx6V+uewqzX9UqFfIqqGA6/p4XBbhXfx4OFs0RTCU=; b=tA9lxT/AZ2PkzccDo0UI9LUOktfO0xARmOgHdxDdUqhMB7w+OR7HwmCgcric2OLX4uy7fE e72T7+Pt15xOh7Bw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8D04313588; Tue, 23 May 2023 07:54:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KAROIR1xbGT4KgAAMHmgww (envelope-from ); Tue, 23 May 2023 07:54:05 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 10/37] ALSA: usb-audio: Get UMP EP name string from USB interface Date: Tue, 23 May 2023 09:53:31 +0200 Message-Id: <20230523075358.9672-11-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523075358.9672-1-tiwai@suse.de> References: <20230523075358.9672-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 USB descriptor may provide a nicer name for USB interface, and we may take it as the UMP Endpoint name. The UMP EP name is copied as the rawmidi name, too. Also, fill the UMP block product_id field from the iSerialNumber string of the USB device descriptor as a recommended unique id, too. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- sound/usb/midi2.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/sound/usb/midi2.c b/sound/usb/midi2.c index 7b4cfbaf2ec0..2ac3f96216bc 100644 --- a/sound/usb/midi2.c +++ b/sound/usb/midi2.c @@ -892,15 +892,39 @@ static int set_altset(struct snd_usb_midi2_interface *umidi) umidi->hostif->desc.bAlternateSetting); } +/* fill UMP Endpoint name string from USB descriptor */ +static void fill_ump_ep_name(struct snd_ump_endpoint *ump, + struct usb_device *dev, int id) +{ + usb_string(dev, id, ump->info.name, sizeof(ump->info.name)); +} + /* fill the fallback name string for each rawmidi instance */ static void set_fallback_rawmidi_names(struct snd_usb_midi2_interface *umidi) { + struct usb_device *dev = umidi->chip->dev; struct snd_usb_midi2_ump *rmidi; + struct snd_ump_endpoint *ump; list_for_each_entry(rmidi, &umidi->rawmidi_list, list) { - if (!*rmidi->ump->core.name) - sprintf(rmidi->ump->core.name, "USB MIDI %d", - rmidi->index); + ump = rmidi->ump; + /* fill UMP EP name from USB descriptors */ + if (!*ump->info.name && umidi->hostif->desc.iInterface) + fill_ump_ep_name(ump, dev, umidi->hostif->desc.iInterface); + else if (!*ump->info.name && dev->descriptor.iProduct) + fill_ump_ep_name(ump, dev, dev->descriptor.iProduct); + /* fill fallback name */ + if (!*ump->info.name) + sprintf(ump->info.name, "USB MIDI %d", rmidi->index); + /* copy as rawmidi name if not set */ + if (!*ump->core.name) + strscpy(ump->core.name, ump->info.name, + sizeof(ump->core.name)); + /* use serial number string as unique UMP product id */ + if (!*ump->info.product_id && dev->descriptor.iSerialNumber) + usb_string(dev, dev->descriptor.iSerialNumber, + ump->info.product_id, + sizeof(ump->info.product_id)); } } -- 2.35.3