crypto: hisilicon/hpre - Fix a erroneous check after snprintf()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 4 Sep 2023 20:17:29 +0000 (22:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:59:18 +0000 (11:59 +0100)
[ Upstream commit c977950146720abff14e46d8c53f5638b06a9182 ]

This error handling looks really strange.
Check if the string has been truncated instead.

Fixes: 02ab994635eb ("crypto: hisilicon - Fixed some tiny bugs of HPRE")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/hisilicon/hpre/hpre_main.c

index 39297ce70f441eababf9ad7825c09246882be443..db44d889438a6ac040b51ff1ebeea50d435f6abe 100644 (file)
@@ -1033,7 +1033,7 @@ static int hpre_cluster_debugfs_init(struct hisi_qm *qm)
 
        for (i = 0; i < clusters_num; i++) {
                ret = snprintf(buf, HPRE_DBGFS_VAL_MAX_LEN, "cluster%d", i);
-               if (ret < 0)
+               if (ret >= HPRE_DBGFS_VAL_MAX_LEN)
                        return -EINVAL;
                tmp_d = debugfs_create_dir(buf, qm->debug.debug_root);