From patchwork Mon Sep 4 19:18:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13374268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4968FC71153 for ; Mon, 4 Sep 2023 19:18:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9488110E179; Mon, 4 Sep 2023 19:18:44 +0000 (UTC) Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8D7EF10E3DD for ; Mon, 4 Sep 2023 19:18:42 +0000 (UTC) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id dF5pqisSfrpphdF5qqmw28; Mon, 04 Sep 2023 21:18:40 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1693855120; bh=IJ6e+7Zx4V39vofq+85y5jlLYHgKa63pDRxIQQkBNeo=; h=From:To:Cc:Subject:Date; b=stflw7wrngPm23k1j/k3IOrf8dC+0fTLtV3ZRPCb6gYi7+b6tsAqanlXa2oBI8D5o 3vPfKvWPNFl39fEdz1kGs+Yo+gdePwLBH5KGlY07d9rnkYEib7+TYap7+0o8bUi0H1 qh0AdSjs5+Ylrl4GcvV5d0qmMfTWcezVwQk3u3XYpzxkNlUW4HErscX29tjMgOBxuz xOasZJpVeRrDIhkbtwRv+SUIagIJKtea6lobGm9Z+B464GNdWWHL8gFkBkY95q+bG/ QJYniGX457kSH7/VZynexZLs3dhPX/ojuUM5Ws8eUxgsaaeqDKYZvoB7yCsCsKC5Z4 OPmT2doe+12fA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 04 Sep 2023 21:18:40 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Oded Gabbay , Dani Liberman , Stanislaw Gruszka Subject: [PATCH] accel/habanalabs/gaudi2: Fix incorrect string length computation in gaudi2_psoc_razwi_get_engines() Date: Mon, 4 Sep 2023 21:18:36 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe JAILLET , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" snprintf() returns the "number of characters which *would* be generated for the given input", not the size *really* generated. In order to avoid too large values for 'str_size' (and potential negative values for "PSOC_RAZWI_ENG_STR_SIZE - str_size") use scnprintf() instead of snprintf(). Fixes: c0e6df916050 ("accel/habanalabs: fix address decode RAZWI handling") Signed-off-by: Christophe JAILLET Reviewed-by: Stanislaw Gruszka --- drivers/accel/habanalabs/gaudi2/gaudi2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index d94acec63d95..9617c062b7ca 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -8277,11 +8277,11 @@ static int gaudi2_psoc_razwi_get_engines(struct gaudi2_razwi_info *razwi_info, u eng_id[num_of_eng] = razwi_info[i].eng_id; base[num_of_eng] = razwi_info[i].rtr_ctrl; if (!num_of_eng) - str_size += snprintf(eng_name + str_size, + str_size += scnprintf(eng_name + str_size, PSOC_RAZWI_ENG_STR_SIZE - str_size, "%s", razwi_info[i].eng_name); else - str_size += snprintf(eng_name + str_size, + str_size += scnprintf(eng_name + str_size, PSOC_RAZWI_ENG_STR_SIZE - str_size, " or %s", razwi_info[i].eng_name); num_of_eng++;