From patchwork Tue Apr 9 14:37:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhu X-Patchwork-Id: 10891367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 398181390 for ; Tue, 9 Apr 2019 14:39:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2718728574 for ; Tue, 9 Apr 2019 14:39:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B5D52858B; Tue, 9 Apr 2019 14:39:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A0E528574 for ; Tue, 9 Apr 2019 14:39:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbfDIOjs (ORCPT ); Tue, 9 Apr 2019 10:39:48 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5704 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726035AbfDIOjs (ORCPT ); Tue, 9 Apr 2019 10:39:48 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 21B605E8C71BA959E5EA; Tue, 9 Apr 2019 22:39:46 +0800 (CST) Received: from suse12-sp2.huawei.com (10.67.189.94) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 22:39:36 +0800 From: zhuyan To: , CC: , , Subject: [PATCH] usb:host: fix divide-by-zero in function fhci_queue_urb Date: Tue, 9 Apr 2019 22:37:12 +0800 Message-ID: <1554820632-13782-1-git-send-email-zhuyan34@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 X-Originating-IP: [10.67.189.94] X-CFilter-Loop: Reflected Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In function fhci_queue_urb, the divisor of expression (urb->transfer_buffer_length % usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) may be zero. When it is zero, unexpected results may occur, so it is necessary to ensure that the divisor is not zero. Signed-off-by: zhuyan --- drivers/usb/host/fhci-sched.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c index 3d12cdd..27ed63c 100644 --- a/drivers/usb/host/fhci-sched.c +++ b/drivers/usb/host/fhci-sched.c @@ -704,6 +704,7 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) struct td *td; u8 *data; u16 cnt = 0; + u16 max_pkt_size = 0; if (ed == NULL) { ed = fhci_get_empty_ed(fhci); @@ -765,11 +766,13 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) switch (ed->mode) { case FHCI_TF_BULK: + max_pkt_size = usb_maxpacket(urb->dev, urb->pipe, + usb_pipeout(urb->pipe)); if (urb->transfer_flags & URB_ZERO_PACKET && urb->transfer_buffer_length > 0 && + (max_pkt_size != 0) && ((urb->transfer_buffer_length % - usb_maxpacket(urb->dev, urb->pipe, - usb_pipeout(urb->pipe))) == 0)) + max_pkt_size) == 0)) urb_state = US_BULK0; while (data_len > 4096) { td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt,