From patchwork Fri Jul 8 07:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunfeng Yun X-Patchwork-Id: 12910724 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 74C2EC433EF for ; Fri, 8 Jul 2022 08:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=R7572ua/IzVxBNIzxJzrSCF83di6S573sTwm1+Du0Xg=; b=JNR0cOMZ36hvIL Cxsu7M640fP37mukMJV4VbdIMnqBjR4EI9qxOVAUbXQJFWctEhE+yB6F8KPpRgTragJmZzhgtTFLK GGOCWXZcwtqijC+TWO5iX98dkAuKTFmCTm8Co78E6AcIMTGv7YMJpaFKYUZZNHRiA/8X2mfE6yP8J W/fLyE77/I219Yv2sG0qR1WOL7IymwmMuX2GqXoTTEPiIBGOWaRl/Q7YB4ZlfKKpMFLVTVTaioobj hi32Jvpi7bs2x8PnYOqOYMd9F5VV8bsseNttbQIRmSdexIy+PaJsPP7ldbJib7/MKGNnc95cROBJ9 KSrd5b/mIpRUxFQUqpXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9jE7-002U4d-JK; Fri, 08 Jul 2022 08:20:40 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9jDI-002ThG-Fv; Fri, 08 Jul 2022 08:19:51 +0000 X-UUID: fefb5ad46aba494a918515b90ee1b8b1-20220708 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:5e66a2ba-dd53-4a69-86a0-a0dc3105c119,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:0f94e32,CLOUDID:a1bae586-57f0-47ca-ba27-fe8c57fbf305,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: fefb5ad46aba494a918515b90ee1b8b1-20220708 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 863590294; Fri, 08 Jul 2022 01:19:44 -0700 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Fri, 8 Jul 2022 15:19:07 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 8 Jul 2022 15:19:06 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman CC: Chunfeng Yun , Matthias Brugger , , , , , Felipe Balbi , Eddie Hung Subject: [PATCH 1/5] usb: mtu3: fix coverity of string buffer Date: Fri, 8 Jul 2022 15:18:59 +0800 Message-ID: <20220708071903.25752-1-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220708_011948_594535_7CC783FC X-CRM114-Status: GOOD ( 12.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use snprintf instead of sprintf which could cause buffer overflow. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 4 +++- drivers/usb/mtu3/mtu3_debugfs.c | 2 +- drivers/usb/mtu3/mtu3_gadget.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 8408e1b1a24a..9893dd1bafbb 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -92,6 +92,8 @@ struct mtu3_request; #define BULK_CLKS_CNT 4 +#define MTU3_EP_NAME_LEN 12 + /* device operated link and speed got from DEVICE_CONF register */ enum mtu3_speed { MTU3_SPEED_INACTIVE = 0, @@ -272,7 +274,7 @@ struct ssusb_mtk { */ struct mtu3_ep { struct usb_ep ep; - char name[12]; + char name[MTU3_EP_NAME_LEN]; struct mtu3 *mtu; u8 epnum; u8 type; diff --git a/drivers/usb/mtu3/mtu3_debugfs.c b/drivers/usb/mtu3/mtu3_debugfs.c index d27de647c86a..a6f72494b819 100644 --- a/drivers/usb/mtu3/mtu3_debugfs.c +++ b/drivers/usb/mtu3/mtu3_debugfs.c @@ -132,7 +132,7 @@ static void mtu3_debugfs_regset(struct mtu3 *mtu, void __iomem *base, if (!mregs) return; - sprintf(mregs->name, "%s", name); + snprintf(mregs->name, MTU3_DEBUGFS_NAME_LEN, "%s", name); regset = &mregs->regset; regset->regs = regs; regset->nregs = nregs; diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c index 30999b4debb8..a751e0533c2d 100644 --- a/drivers/usb/mtu3/mtu3_gadget.c +++ b/drivers/usb/mtu3/mtu3_gadget.c @@ -635,8 +635,8 @@ static void init_hw_ep(struct mtu3 *mtu, struct mtu3_ep *mep, INIT_LIST_HEAD(&mep->req_list); - sprintf(mep->name, "ep%d%s", epnum, - !epnum ? "" : (is_in ? "in" : "out")); + snprintf(mep->name, MTU3_EP_NAME_LEN, "ep%d%s", epnum, + !epnum ? "" : (is_in ? "in" : "out")); mep->ep.name = mep->name; INIT_LIST_HEAD(&mep->ep.ep_list);