From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 E91AF3D1AA0 for ; Fri, 7 Aug 2026 11:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786102940; cv=none; b=B6fWK/Mtz9Q5s7SVu6gcuMtvBH9shSYXFkGGBhvbdpSCpdMb0VYVV+vT188vvKQ6pwalsKyKWFEwR2/lCNmp8je/NzLuhbwbxQBbTo/2MRtoKbkhreOnknSOImbiW4bKlx+MNX+kQzgAG9hwfee3hYc1cYEsJZxJfFeA3PSXVGM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786102940; c=relaxed/simple; bh=SW3QQ7TLL2MlBWmSFLXbFPE4nTuOfBcLz7c3BJkp6jc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HAvDON7ybgwjUJcsO/9e+g71QAb2e/dxPSULyy0LBiPuWveIRfLH64j8Hl9OSjzMGZipZIhRfRA2Bh1MXE2HpLguksf+1YObXo2XS0R6U+F4IEIbF6Xb6N6+uEV20qgUwdeDQtFZaIRtQKJoCvExjkvuQvTPFjdFCg9TmXbcrVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qC9JIg7L; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qC9JIg7L" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-84e0688b7e8so3132350b3a.1 for ; Fri, 07 Aug 2026 04:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786102928; x=1786707728; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=O6lR1SogBn9JLBrBLFh5Dez9g6Tr1CXQQppMwm2xDcc=; b=qC9JIg7LJbPyoGFssi/HNtrHcI2V70QyzK/e8fVsyG3hK4JtPgFsLeFWkYu0A/CqLd z7lNCqFdBKE+SedeysAeMJaR/PC+eigrFSVY68OphWfVYTUKIimHl7PnfDO/9U/vk3iz biewQ6iCyIfMCZQCN66Fc8myc/Ld5GixlIjiQP/FAWR5Nhp2qOLBMnAftzRxrZ9W5lQk f/+SfHbeaIODC8Fh0Ys1DdVBXShcjtnHrnStN8KfZh0vSY3fvJsgvdH0/7MQ9iI2Qd2T 0unv1Nj+dT43l3K6PNdo5b0z96Wwu8ISSYroPeWFsb9k1z726ne+o6uEV4fJHLegxm9g AI3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786102928; x=1786707728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O6lR1SogBn9JLBrBLFh5Dez9g6Tr1CXQQppMwm2xDcc=; b=ZbBMoxUa/wEN8y/vD4j1HiEYtxS7lTXGt88+lu9UU+BomlVLq6EH2cywwnybDmYNLC WlAHC9DArc61Zq1kouneRiDPHSbFP2YCjoSevGfnnISIMyczDTncKkXt+kfzONFjlEEv ZARm/ie8BNFJ2MwwdX2oXew6iWtCSJlZpYu4/+xF7mxKgPgzNW/yxQUyKtGRWuwKBijl G9tJjRrbY0f/r26NQlCe+y51f0jvrkXjUw0nw/kIz+d5ZIftw0J6gIgKyBaGs+JVUbRW rRgv1mUc/Kn9zcb2le0hVQ5aQnbvIAW0IRYLQIEYFX8y8OLfT9teOaxhUA3fhi6InWwE dwNQ== X-Forwarded-Encrypted: i=1; AHgh+RoShi9coIgvAfWOiLyOfmN6SU7MZ2N2PsgHVBluMwx8LujNisz8JEIHNboYfqWyu3FXXEluaQT4xE0rOGw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3/U0hf/ESJvsPK0rWA62jIymKtA7m0txq5GcnqCPHFCVVWJjd 6muGMiWsiAmp7cSSQP+PqrdAklLHxHYr28cgAmlgFLhDoQw6s5YO8vRm X-Gm-Gg: AR+sD10/5IuC/TxH75OS4M9Xq9JgSwm/Pch9LRDaU19fPficT86gPOTkX/lHeb/QfDJ 8DnLWQQXXHt3zxqeRPJ397HEjLFEu74bKlaea7ywKBCb2kn+uVMX8kivYF5kgQCqOBrpDh65HDv fk5SNcxwmANfWE3OHtDu3OlNWQUwPEjqVzIRckrVq6B15ByKTxhJqYt2ZW8aVaHXpcaBCapkAy4 PG6QOGcOLvcjodLEYAScl7fOBEo7ue3NYl0FdKmnmRQiB1y5/buuRPetvgLJdMZbrPYa/Opjlkp e0s4k8jFk/shNFIlN3coqCIW+8n2LORz9JHVR3fzUyZ0PHljySBv6q0SBvvll77wFXUlCQWdsF7 fBfJ+DmXNlhkutAtSyT/FI0BH7V6IEF3NGJhpU4NgDnKzAxyvwFbD2yOD0w2NXdJkbnP90oZ+Oy Nxl0DFpAWO/LTT9B5N3jxGnodGPxthvhUXbQDZ3+MdCAw3U0LyVmuq7i1XQx4MfdGCaCVWibvyf vSNiHl+PMQ= X-Received: by 2002:a05:6a20:d4b:b0:3c3:8255:8c4a with SMTP id adf61e73a8af0-3cb85ea2ee0mr27242276637.17.1786102927754; Fri, 07 Aug 2026 04:42:07 -0700 (PDT) Received: from localhost.localdomain ([72.255.58.127]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315be86d3fcsm6930508eec.4.2026.08.07.04.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2026 04:42:07 -0700 (PDT) From: Mahad Ibrahim To: Takashi Iwai , Jaroslav Kysela Cc: Kees Cook , Andy Shevchenko , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Mahad Ibrahim Subject: [PATCH 2/7] ALSA: ac97: replace strlcat() with scnprintf() Date: Fri, 7 Aug 2026 11:41:34 +0000 Message-ID: <20260807114139.1661-3-mahad.ibrahim.dev@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260807114139.1661-1-mahad.ibrahim.dev@gmail.com> References: <20260807114139.1661-1-mahad.ibrahim.dev@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit At this point name holds the vendor name written by the earlier strscpy(). A space and then the codec name were appended with two strlcat() calls. The else branch below already took its own offset with strlen() before calling snprintf(). Take that offset once, before the branch, and use it for both. The two appends become a single scnprintf() writing " %s" at the offset, and the else branch uses the same variable instead of computing its own. The bytes written and the point at which the result is truncated are unchanged. Signed-off-by: Mahad Ibrahim --- sound/pci/ac97/ac97_codec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 0bb65be021d9..dfd712ef0c63 100644 --- a/sound/pci/ac97/ac97_codec.c +++ b/sound/pci/ac97/ac97_codec.c @@ -1832,6 +1832,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, size_t maxlen, int modem) { const struct ac97_codec_id *pid; + int len; sprintf(name, "0x%x %c%c%c", id, printable(id >> 24), @@ -1849,9 +1850,9 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, } pid = look_for_codec_id(snd_ac97_codec_ids, id); + len = strlen(name); if (pid) { - strlcat(name, " ", maxlen); - strlcat(name, pid->name, maxlen); + scnprintf(name + len, maxlen - len, " %s", pid->name); if (pid->mask != 0xffffffff) sprintf(name + strlen(name), " rev %u", id & ~pid->mask); if (ac97 && pid->patch) { @@ -1860,8 +1861,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, pid->patch(ac97); } } else { - int l = strlen(name); - snprintf(name + l, maxlen - l, " id %x", id & 0xff); + snprintf(name + len, maxlen - len, " id %x", id & 0xff); } } -- 2.54.0