Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1956627ybm; Sun, 31 May 2020 04:04:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD+u9JzkoDVxV/eW3wu7SzWqmDvhQ7OjBcLcUgg0+PBodyDIgHnLcFMKROx6DQXCyLKt1T X-Received: by 2002:a50:bae7:: with SMTP id x94mr11084280ede.127.1590923098264; Sun, 31 May 2020 04:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590923098; cv=none; d=google.com; s=arc-20160816; b=joqE/3YK5sNBMDyZ31Yy8ipqiRmlP2a3iqN68wtRqrARDeiM8Whpm0mm86uo1KGJMY Uk+G/zld0nWqEJlnHGk/nFyaqSAW/dAI1TS8KpTKkYEPVBBBUwGKSul803QACnHFsaom UDahfPtXEQgS/yH+d4V13qcKKjfA8neBS+hd/X1y0tHdRaP1yPQzZf2D9l2WYpPVweIF JjyT8n73JoS3poQq+DXZ85b/7ThZ8vZ3mGG1QUVJJLU/2QQRJIOZ5hP+7ZoHtXzGIFMc bihoCpPxbMf8xShbeGJXZGN1GlyzcYefxaBa2spQdjYF37lWAIqfQZWiGVDoIRTrKHpK HJEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4ZeH+3Xs1eLtvVZLC2Ghqmx2t9Qj5bzcPEiLkSrbQKo=; b=qVDP81Ou4NZ8XTuiQRqKRYKXL23Ox7VRrhiW0YCSKloXc/DKMRlfVOE5WVdDBaRhKQ eNYgPyJqCdXeyHZMCn27PKlTfmL4wIxxlBx2TiIsSFwK2CXRjx0vW2wgr0bNQsK1ulZ8 pxsaILEY7kdtsyu9WF3YlCnZO0lw7j7Cxzl40R/L4MUB0mXjtW9t16tDTGyK8mJsQsXD d5wTdOdqr6Gle/MKVN/N/yzVTJuNkul6GJCclMfN9Ssj/jUjrwraKsWeGja0OPM4TPEU 9INXeYLRyUIy351puBf8OP0+ypgIBQ+AuKTy+JbFQAEryTecZYzP1NTRyNbZRvYpXvpa iDLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="V/u7sKIV"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si872010edy.169.2020.05.31.04.04.35; Sun, 31 May 2020 04:04:58 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="V/u7sKIV"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729680AbgEaLBw (ORCPT + 99 others); Sun, 31 May 2020 07:01:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726020AbgEaLBv (ORCPT ); Sun, 31 May 2020 07:01:51 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24179C061A0E for ; Sun, 31 May 2020 04:01:51 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id z13so4559601ljn.7 for ; Sun, 31 May 2020 04:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4ZeH+3Xs1eLtvVZLC2Ghqmx2t9Qj5bzcPEiLkSrbQKo=; b=V/u7sKIVbzwoHQ9wVIOeSooJyWzb2QQiXYzSXNcQSYKkQGygOrAZ4WD8l4SMuhA0T4 iwgXniwTuKtDnd7H/mys4Oc2Es3xUMpCC5L5yIZUz9diJzpsx+DjBpNQ/hScwgLaJNBD +vR8fOTzeRAOyM7BNUz9LKKeXiGnYLWxmBBwHIjuY3pSYh7C6r8EwdBcf4nngl19VVmz IoXxH7YaLF3t/DfJksXz2H6oHRujIn5wcM6Rpnx7Uf6vmbXzAptpfI7d1oM16lq9HwQz mhOfSibt2JaZeaz6DEyCLiWD3bS3WDdgbUzuaB9krSODilv42Nc+ghMFbsi3JbkjHflp +2Ig== 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:mime-version :content-transfer-encoding; bh=4ZeH+3Xs1eLtvVZLC2Ghqmx2t9Qj5bzcPEiLkSrbQKo=; b=opVB1LpGh7B15BrikARZ1mI28bOBJhqHyUjy9m1m1DS1hCVK6I65Qv/L2Ip8P7lrbc TX36Cj9HBah9Ry2T0cX4+dlLcnZuCtmP4D7JJx+7sn9xMawjbRL2hjensoggaGUA6CUj ZNT65bVPiRSXi03LZPdtxB5+ZTt8xse5zTmPmEAJT9sZDmXvV9ytSmS1jLY8Of3LFLcA TtlFH4haPKKqwXkFShrXzfDYsOZKq32U2gvmfCAG7yaTXbgZYUrW7YhNXPUKXpzdJvAs bWaDaxPf3Mar1O6/BnHDfPIleSKNWJD+/2lR9PEjonCn/b6aYQPw/zplQ61ozycjzsv/ FG+A== X-Gm-Message-State: AOAM531C5b8sv1J1Puw9bu+PMvLrba3T1rMLgYbac0r9/j8tMuUzODM5 O7xFwq1TL0njBEaNAabKxPE= X-Received: by 2002:a05:651c:205b:: with SMTP id t27mr8251413ljo.456.1590922909639; Sun, 31 May 2020 04:01:49 -0700 (PDT) Received: from alpha (84.188.smarthome.spb.ru. [80.249.188.84]) by smtp.gmail.com with ESMTPSA id z5sm3148776ljm.64.2020.05.31.04.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 May 2020 04:01:49 -0700 (PDT) Received: (nullmailer pid 9364 invoked by uid 1000); Sun, 31 May 2020 11:06:18 -0000 From: Ivan Safonov To: Larry Finger Cc: Florian Schilhabel , Greg Kroah-Hartman , Nishka Dasgupta , Cristiane Naves , Wambui Karuga , Dan Carpenter , Merwin Trever Ferrao , Kees Cook , Michael Straube , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Ivan Safonov Subject: [PATCH] staging:rtl8712: avoid skb_clone after skb allocation fail Date: Sun, 31 May 2020 14:05:47 +0300 Message-Id: <20200531110548.9318-1-insafonov@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The skb allocated when out of memory is likely to be discarded during subsequent processing. Signed-off-by: Ivan Safonov --- drivers/staging/rtl8712/rtl8712_recv.c | 29 ++++++++++---------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c index 116773943a2e..570030be3077 100644 --- a/drivers/staging/rtl8712/rtl8712_recv.c +++ b/drivers/staging/rtl8712/rtl8712_recv.c @@ -1037,24 +1037,17 @@ static void recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb) */ alloc_sz += 6; pkt_copy = netdev_alloc_skb(padapter->pnetdev, alloc_sz); - if (pkt_copy) { - precvframe->u.hdr.pkt = pkt_copy; - skb_reserve(pkt_copy, 4 - ((addr_t)(pkt_copy->data) - % 4)); - skb_reserve(pkt_copy, shift_sz); - memcpy(pkt_copy->data, pbuf, tmp_len); - precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = - precvframe->u.hdr.rx_tail = pkt_copy->data; - precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz; - } else { - precvframe->u.hdr.pkt = skb_clone(pskb, GFP_ATOMIC); - if (!precvframe->u.hdr.pkt) - return; - precvframe->u.hdr.rx_head = pbuf; - precvframe->u.hdr.rx_data = pbuf; - precvframe->u.hdr.rx_tail = pbuf; - precvframe->u.hdr.rx_end = pbuf + alloc_sz; - } + if (!pkt_copy) + return; + + precvframe->u.hdr.pkt = pkt_copy; + skb_reserve(pkt_copy, 4 - ((addr_t)(pkt_copy->data) % 4)); + skb_reserve(pkt_copy, shift_sz); + memcpy(pkt_copy->data, pbuf, tmp_len); + precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = + precvframe->u.hdr.rx_tail = pkt_copy->data; + precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz; + recvframe_put(precvframe, tmp_len); recvframe_pull(precvframe, drvinfo_sz + RXDESC_SIZE); /* because the endian issue, driver avoid reference to the -- 2.26.2