From patchwork Mon Feb 18 20:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10818811 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 2742714E1 for ; Mon, 18 Feb 2019 20:22:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 128482A686 for ; Mon, 18 Feb 2019 20:22:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06C092BB66; Mon, 18 Feb 2019 20:22:03 +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 A00412BB72 for ; Mon, 18 Feb 2019 20:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729332AbfBRUWB (ORCPT ); Mon, 18 Feb 2019 15:22:01 -0500 Received: from gateway21.websitewelcome.com ([192.185.45.154]:31239 "EHLO gateway21.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728443AbfBRUV4 (ORCPT ); Mon, 18 Feb 2019 15:21:56 -0500 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway21.websitewelcome.com (Postfix) with ESMTP id EDE3D400CDBD1 for ; Mon, 18 Feb 2019 14:21:54 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id vpQIgK2daiQervpQIgYJEY; Mon, 18 Feb 2019 14:21:54 -0600 X-Authority-Reason: nr=8 Received: from [189.250.119.20] (port=47442 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1gvpQI-001GOQ-5O; Mon, 18 Feb 2019 14:21:54 -0600 Date: Mon, 18 Feb 2019 14:21:53 -0600 From: "Gustavo A. R. Silva" To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] usb: wusbcore: wa-xfer: use struct_size() helper Message-ID: <20190218202153.GA21376@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.119.20 X-Source-L: No X-Exim-ID: 1gvpQI-001GOQ-5O X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.119.20]:47442 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes 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 Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used. So, change the following form: sizeof(*packet_desc) + (sizeof(packet_desc->PacketLength[0]) * seg->isoc_frame_count) to : struct_size(packet_status, PacketStatus, seg->isoc_frame_count); This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- drivers/usb/wusbcore/wa-xfer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c index 01f2f21830c0..abf88cea37bb 100644 --- a/drivers/usb/wusbcore/wa-xfer.c +++ b/drivers/usb/wusbcore/wa-xfer.c @@ -662,9 +662,9 @@ static void __wa_setup_isoc_packet_descr( /* populate isoc packet descriptor. */ packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO; - packet_desc->wLength = cpu_to_le16(sizeof(*packet_desc) + - (sizeof(packet_desc->PacketLength[0]) * - seg->isoc_frame_count)); + packet_desc->wLength = cpu_to_le16(struct_size(packet_desc, + PacketLength, + seg->isoc_frame_count)); for (frame_index = 0; frame_index < seg->isoc_frame_count; ++frame_index) { int offset_index = frame_index + seg->isoc_frame_offset; @@ -2438,7 +2438,7 @@ static int wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) struct wa_rpipe *rpipe; unsigned done = 0, dti_busy = 0, data_frame_count = 0, seg_index; unsigned first_frame_index = 0, rpipe_ready = 0; - int expected_size; + size_t expected_size; /* We have a xfer result buffer; check it */ dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n", @@ -2460,11 +2460,10 @@ static int wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) goto error_bad_seg; seg = xfer->seg[wa->dti_isoc_xfer_seg]; rpipe = xfer->ep->hcpriv; - expected_size = sizeof(*packet_status) + - (sizeof(packet_status->PacketStatus[0]) * - seg->isoc_frame_count); + expected_size = struct_size(packet_status, PacketStatus, + seg->isoc_frame_count); if (urb->actual_length != expected_size) { - dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %d needed)\n", + dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %zu needed)\n", urb->actual_length, expected_size); goto error_bad_seg; }