From patchwork Sat Dec 1 14:01:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10707707 X-Patchwork-Delegate: kvalo@adurom.com 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 54BA913BF for ; Sat, 1 Dec 2018 14:01:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4425D2DFAD for ; Sat, 1 Dec 2018 14:01:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35C4D2DFB1; Sat, 1 Dec 2018 14:01:42 +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 E217A2DFAD for ; Sat, 1 Dec 2018 14:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbeLBBOP (ORCPT ); Sat, 1 Dec 2018 20:14:15 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41562 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726570AbeLBBOP (ORCPT ); Sat, 1 Dec 2018 20:14:15 -0500 Received: by mail-wr1-f67.google.com with SMTP id x10so7859942wrs.8 for ; Sat, 01 Dec 2018 06:01:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W7ON34L400jtLVNPQlEDgnBe9WRZkgfwQI4Scb6znGE=; b=bclNWdTHLZIMDz0i0UZPXWl5IIC2QA0kQPNuau5p/xWmrXn6BYMgMdiNxrTY2w4glu ju7kp5tpmlXre7ncgpw7Ha4tYUhvb7in/1nlm2Na1KDtM1yMNyuCnQ4VJRgDR8LOWV7L fU0sjth5c7cmDqKXFD7WR6Sz9EDsu6C631TbSFoRA5Yxm7vo4k9Rher2NaAr/pnBGECY ytLDdVDyFbP0COLlScsrH10WfFM6MsF1yFBe84RTIPJmv8lAJDmi3vc6yF4Zw7NTrL9n 3ALyohcNjcSALZ0V9mCceSlIRxp/2iqWy758T+QVCtIyzEqZBpuOXzqbbmlEoj5mVa5t PN1A== X-Gm-Message-State: AA+aEWYhVBQ177N98yf1ECNhPDG2nVl93/kso4hofVZUlsmLGLPe2pe4 hDQLDPiaEWbu57ScEgsB7wbQr4Hf8oQ= X-Google-Smtp-Source: AFSGD/XMIUHp9JrdH5RixE3COp/FjtL0ZBRiIB7ENtqzziURvRWAsSM5wTNd2zDw7dFfaGOmBqBH/g== X-Received: by 2002:adf:9dd2:: with SMTP id q18mr8245267wre.12.1543672899321; Sat, 01 Dec 2018 06:01:39 -0800 (PST) Received: from localhost.localdomain ([151.66.56.232]) by smtp.gmail.com with ESMTPSA id i16sm2260502wmd.28.2018.12.01.06.01.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 06:01:38 -0800 (PST) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH] mt76: usb: do not build the skb if reported len does not fit in buf_size Date: Sat, 1 Dec 2018 15:01:19 +0100 Message-Id: X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Precompute data length in order to avoid to allocate the related skb data structure if reported length does not fit in queue buf_size Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/usb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index b061263453d4..14ff06c5764e 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -407,17 +407,15 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) if (len < 0) return 0; + data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN); + if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) + return 0; + skb = build_skb(data, q->buf_size); if (!skb) return 0; - data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN); skb_reserve(skb, MT_DMA_HDR_LEN); - if (skb->tail + data_len > skb->end) { - dev_kfree_skb(skb); - return 1; - } - __skb_put(skb, data_len); len -= data_len;