Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2672165ybh; Fri, 24 Jul 2020 20:47:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXyBHf/0Kjrye5ISVY/yKstYrRQwIRUYiqQ3KZIH0uAdbg74VC8hrSWgY6ZVRUm6Z7Xl6G X-Received: by 2002:a17:906:8782:: with SMTP id za2mr9604498ejb.419.1595648859839; Fri, 24 Jul 2020 20:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595648859; cv=none; d=google.com; s=arc-20160816; b=LvchuditDPR3vJJFdX9iJedv8pDEv21qtS+0cby6rnpHkbai9/G5ZEI2t1+/TBpFfh r4JrtSqbzDype4fp5T5+bse653CpqI9UREft/6XhPfYCLRmlC5NJqFKGMU19+0dyrf7R 8ZiT/Oa38m1O2Li4esZ6WOzZBoB2+EvOlXmRdDs/EYfEBt+DsUlA/pAzV9Ich1pRXPfc qwxa0OMbHn5QknNqfMJYHALkyW9Om/FETRJEf5J6gQDgWxeskJmoRK21lVihv5vQlCkb 9iHv8HyJwJ7i47lgaLM/8du7Wydd2qKGUvZ8B5vSpdfyYeA3p90+IEFWq1wWJZRtcVSD 3oOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=yy2aqetwijV5IkVoTSrUrv/D6x64CUVdNbcOV7Ro1rk=; b=n6xApuzwuADt0eYYV2QdnM9GV1rVMX0fhPcnbGmyi6RemXie7ultt8+5JHz0ENx8A9 5V7OhOAzog/ZuqMy/3ojKYfUb08wytTsRD/wnZ3/2RwtXe79b5LWOARLyKKXnlrI8+Aw diVTnHZWJqtNHR774wf2ZHPBO/4nqcIYywox79eVMq7dW9y7BAFtIAQ8b78ZqeTdS6Lm 9xwf6esWG/RvY7VICW4C6pUDOEEEaxXcWasxxrKZlues5uOyojwzA19IZZKqwX5Bn7RT NQGs9Q49uGlSkxBKl/ilKyWgkpcMC8gohVtX+W0AhI+l67sCh1Oj220AxCjBwlwvzzrt Ms2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si1888630ejn.667.2020.07.24.20.47.17; Fri, 24 Jul 2020 20:47:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgGYDqz (ORCPT + 99 others); Fri, 24 Jul 2020 23:46:55 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8818 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726971AbgGYDqz (ORCPT ); Fri, 24 Jul 2020 23:46:55 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DF2DD7214520EC9F1F51; Sat, 25 Jul 2020 11:46:49 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Sat, 25 Jul 2020 11:46:40 +0800 From: Yang Shen To: , CC: , , , Subject: [PATCH 04/10] crypto: hisilicon/zip - replace 'sprintf' with 'scnprintf' Date: Sat, 25 Jul 2020 11:44:37 +0800 Message-ID: <1595648683-50590-5-git-send-email-shenyang39@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595648683-50590-1-git-send-email-shenyang39@huawei.com> References: <1595648683-50590-1-git-send-email-shenyang39@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace 'sprintf' with 'scnprintf' to avoid overrun. Signed-off-by: Yang Shen Reviewed-by: Zhou Wang --- drivers/crypto/hisilicon/zip/zip_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c index df1a16f..1883d1b 100644 --- a/drivers/crypto/hisilicon/zip/zip_main.c +++ b/drivers/crypto/hisilicon/zip/zip_main.c @@ -428,7 +428,7 @@ static ssize_t hisi_zip_ctrl_debug_read(struct file *filp, char __user *buf, return -EINVAL; } spin_unlock_irq(&file->lock); - ret = sprintf(tbuf, "%u\n", val); + ret = scnprintf(tbuf, HZIP_BUF_SIZE, "%u\n", val); return simple_read_from_buffer(buf, count, pos, tbuf, ret); } @@ -514,13 +514,16 @@ static int hisi_zip_core_debug_init(struct hisi_qm *qm) struct debugfs_regset32 *regset; struct dentry *tmp_d; char buf[HZIP_BUF_SIZE]; - int i; + int i, ret; for (i = 0; i < HZIP_CORE_NUM; i++) { if (i < HZIP_COMP_CORE_NUM) - sprintf(buf, "comp_core%d", i); + ret = scnprintf(buf, HZIP_BUF_SIZE, "comp_core%d", i); else - sprintf(buf, "decomp_core%d", i - HZIP_COMP_CORE_NUM); + ret = scnprintf(buf, HZIP_BUF_SIZE, "decomp_core%d", + i - HZIP_COMP_CORE_NUM); + if (!ret) + return -ENOMEM; regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); if (!regset) -- 2.7.4