From patchwork Sat Mar 23 06:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 782238 Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 323A246A0; Sat, 23 Mar 2024 06:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.27 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177053; cv=none; b=T0FKJjlpqJqp48IELSKuX1LQAjvPeLg3DNubdLDUPk4PiZhPbXEeydsNegBX/Ie6Hb21XHNH7+5fvIw1WmobzwXxS6mAQfGa0p2MYHm/YL0FDHWFBo/5p2rEnOiIysnuS0GghAcfDQSvYLHms8m85NZ1hOqFvhXIe7GQupGz0D8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177053; c=relaxed/simple; bh=Voz19KYzQOltPtFam3tB/1mEVOfoTTWvRX0X9iZJcNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LPQhHLvG3jQXzHsstPTgr7rE94Nq63/9XSM5llwpccBNqNt1fPScG39Oc8wBOM7Bt+aW7DQcSOmMQdgXzrRGE3D7qaFQ9b2R5mhOxuNP0vWvLbVzsdNfK7hXxg2Fk8L5khR+F2gi2Gt2by2RIhd6JOP9+sfD08G5KuGG0X45GLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=VnG+P5F6; arc=none smtp.client-ip=80.12.242.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="VnG+P5F6" Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id nvJZrKeyIixjunvJhrMrfQ; Sat, 23 Mar 2024 07:57:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1711177041; bh=wUyvvyJdTx1/XQHU+I6I8DZSGJvicxz4iaZppevGwzg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VnG+P5F6DWNNqpoxfOdkl4yZLmfzeYi2LOnaowgKoaw3uou81NL+bv2B6dHJ3sv19 yUPV3RBm7Gz+iOvf5r1Mqpk8pNZgHrHzRlkzKAHBwQGeK8lrApU7m1hdwiTR3qppSM /YMKBxwTBId1cs9QxyuGgMvh9l30ceTUtRM0PzJDccmZ6b/QVbhh66r6RX8fji/9hc 16m5Qvj1TavkranrLpR9QmRi7pOgx1ZDMGVZJw1ULYOKiSBt0FIGGxc+kFKTx9KWyC r7m+YtXjd8EIoz+Q14s62wLCRWGntV+UjvBKOZOWCHBx8ZafKac6UfTs3aNdfAlFvQ zNAPR2EVhD6NQ== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 23 Mar 2024 07:57:21 +0100 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: gregkh@linuxfoundation.org, jbrunet@baylibre.com, ruslan.bilovol@gmail.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call Date: Sat, 23 Mar 2024 07:57:03 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The size given to strscpy() is not consistent with the destination buffer that is used. The size is related to 'driver' and the buffer is 'mixername'. sizeof(card->mixername) is 80 and sizeof(card->driver) is 16, so in theory this could lead to unneeded string truncation. In practice, this is not the case because g_audio_setup() has only 2 callers. 'card_name' is either "UAC1_Gadget" or "UAC2_Gadget". Anyway, using the correct size is cleaner and more future proof. In order to be less verbose, use the new 2-argument version of strscpy() which computes auto-magically the size of the destination. Signed-off-by: Christophe JAILLET --- Compile tested only. As this doesn't fix anything in the real world, no Fixes tag is provided. Should one not agree with me, it is: Fixes: e89bb4288378 ("usb: gadget: u_audio: add real feedback implementation") --- drivers/usb/gadget/function/u_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 4a42574b4a7f..00ff623b4ebb 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -1257,7 +1257,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, if ((c_chmask && g_audio->in_ep_fback) || (p_chmask && params->p_fu.id) || (c_chmask && params->c_fu.id)) - strscpy(card->mixername, card_name, sizeof(card->driver)); + strscpy(card->mixername, card_name); if (c_chmask && g_audio->in_ep_fback) { kctl = snd_ctl_new1(&u_audio_controls[UAC_FBACK_CTRL], From patchwork Sat Mar 23 06:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 782572 Received: from smtp.smtpout.orange.fr (smtp-28.smtpout.orange.fr [80.12.242.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 800EC4C6B; Sat, 23 Mar 2024 06:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177055; cv=none; b=REWIheXR0HSIPaHau+DzQcNYmPMVAQ6IK7+0ydOwUVTB9YA77Iu49ojWc0soY6QaYlwFIUEqOxB6FY0I5du5FkxaNfxzdugmK1bpop3KwiBd158QrA0VzvbN/Pe7zs51w6qhSJerpvunSNV7Y2jOKg/JgCfku6ZC+T7JE/HZhHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177055; c=relaxed/simple; bh=Vepnq6HR03my19K7lEmsnKur7lcLWcR+/WSr2aInfXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFs7hNJouKmJ22GgDVC5VVOK4Yx0c9l3hvmrxi+SFIHnEGSzUaJIRvHtWWs7XJZCenahL5gh6yZ8bEcSvd4RoW+xSmQxTPUA1s8Ts4FsNpSkGShLp5G5JFEbRWHOyCEMLZ4NxujttdGeRCUQdO9SzjrZ37bb/KLH6F4vjKPZ+uA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=o96+n8a/; arc=none smtp.client-ip=80.12.242.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="o96+n8a/" Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id nvJZrKeyIixjunvJkrMrfv; Sat, 23 Mar 2024 07:57:25 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1711177045; bh=VPQNyHwgvojt0bPFXEppRTGCqNsSKPdraCVqPoBN/Ps=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=o96+n8a/XbwTAnqQHGJHBCurGcWzgxVSnMoFmYgfAYMqUmr45BOaVcAkScFXRNsHI RkmMVQIzUbDsmVDNb8PPXdSeuf7/1pVkRwwsBx0OjsNptTPsdu9QeB1bEY907MJw/x 6jNck/9jaaeFn9Ehh7vXT/QfNc1zrGJgXX8d7Z7yw08mIeDSc2y9SuIXcAAuOaXREv y8Y8brk0/H2HlcCetHNMR6E6tetvDFqZ8LJE6+Sa1xhG7KXLJR1DUZFYVtw1y/ZKOq W5Uxa3b2hsV2zeN9qA/zkxaLbTbiBdz8FHW556KABQtlA+X/BNfDoV0LGWIIC752Db svaGJ7QGHL05w== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 23 Mar 2024 07:57:25 +0100 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: gregkh@linuxfoundation.org, jbrunet@baylibre.com, ruslan.bilovol@gmail.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/3] usb: gadget: u_audio: Use the 2-argument version of strscpy() Date: Sat, 23 Mar 2024 07:57:04 +0100 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to be consistent with other strscpy() usage in this file and less verbose, use the new 2-argument version of strscpy() which computes auto-magically the size of the destination. Signed-off-by: Christophe JAILLET --- Compile tested only --- drivers/usb/gadget/function/u_audio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 00ff623b4ebb..5dba7ed9b0a1 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -1243,7 +1243,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, if (err < 0) goto snd_fail; - strscpy(pcm->name, pcm_name, sizeof(pcm->name)); + strscpy(pcm->name, pcm_name); pcm->private_data = uac; uac->pcm = pcm; @@ -1386,8 +1386,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->snd_kctl_rate = kctl; } - strscpy(card->driver, card_name, sizeof(card->driver)); - strscpy(card->shortname, card_name, sizeof(card->shortname)); + strscpy(card->driver, card_name); + strscpy(card->shortname, card_name); sprintf(card->longname, "%s %i", card_name, card->dev->id); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, From patchwork Sat Mar 23 06:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 782237 Received: from smtp.smtpout.orange.fr (smtp-28.smtpout.orange.fr [80.12.242.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F01ECA6F; Sat, 23 Mar 2024 06:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177057; cv=none; b=OdrAM9SPG6KHkLpqokOxLw3lNSNYzAkT7QYs5BtdfqUFTwS4fQzVv7lz3JzVjx6NQk9q5Kkwt4XXa/DcWFVJMfXKON99PSbqlT4vF30rOomnpTqb+Hq6lH/CD+39/mqa79rwk9EJKcrFgTg3APO1HR2PXWTkeDZLe70KpU0Ldd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711177057; c=relaxed/simple; bh=y2BUhWyG2HK6NoiwSsb///Wz9WQ5PTYaMBs7R+bsQKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a6aW6dtC8smoTq2g8O7Q9j9H2YhldHLJFtlnXAlKEJ7VRUbmeOgarhQTOPub5lEUN1bk/0MHaY0iLMcWgj4rg/GxNzFLsnwmc58HpAMAKt61E8vR9HDuEpR9KxSvTwodcur3ai9vxXAnf+sr1LqHouTqfYtASjI04D4rrH78CEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=XHrfy2Kv; arc=none smtp.client-ip=80.12.242.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="XHrfy2Kv" Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id nvJZrKeyIixjunvJnrMrik; Sat, 23 Mar 2024 07:57:27 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1711177047; bh=GqVTzgUhSwxWnPsMh7JKr/v6dWRM2rIpiyLhxqJvIk4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XHrfy2KvjpqI2gsrxiQRiC5mc3PqShjlMeYJXhoH60ZzN62+0BZ9tFIHYZVOPYB9A DzRU4dISD/6Hqn4JIf+QAX/5N8gxmfiO31dJepjEYciQI0TYbNFORTbRODUUAalg3z uEVDua/GKX+TsPNfp6Uz+0GqXHh2N1J3K8MsMP/STa6BbhIl4Dswnioj6HNK2m/BJ7 NOczLzbj7niily6rh+bLGF6mL4IgdHwVudTXOWxB3mX/ORjPBY9hVaI/jim5D+WaEW aLM2Xt31V8Te8+0RRlISBfGjb4xBFKroEwiVC42n4z92JtQt85i414avwWeZveYdVy 9jueAhMZbbJVQ== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 23 Mar 2024 07:57:27 +0100 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: gregkh@linuxfoundation.org, jbrunet@baylibre.com, ruslan.bilovol@gmail.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/3] usb: gadget: u_audio: Use snprintf() instead of sprintf() Date: Sat, 23 Mar 2024 07:57:05 +0100 Message-ID: <5703e697687e4a39059bf90659969ffc86b2cfbd.1711176701.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In order to be consistent with other s[n]printf() usage in this file, switch to snprintf() here as well. Signed-off-by: Christophe JAILLET --- Compile tested only --- drivers/usb/gadget/function/u_audio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 5dba7ed9b0a1..1a634646bd24 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -1388,7 +1388,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, strscpy(card->driver, card_name); strscpy(card->shortname, card_name); - sprintf(card->longname, "%s %i", card_name, card->dev->id); + snprintf(card->longname, sizeof(card->longname), "%s %i", + card_name, card->dev->id); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, NULL, 0, BUFF_SIZE_MAX);