From patchwork Tue Aug 5 15:44:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 34959 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E83C3202A1 for ; Tue, 5 Aug 2014 15:45:02 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf7427775pab.5 for ; Tue, 05 Aug 2014 08:45:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=jg1WhsOB/LfbqP4k/aRuhABVHtchIhnLh3HGHjVLjQ4=; b=LKxHZ2OGx4bIfnyJz4Ba6o+QHAiEBrrcZ4v+mQkdER2wdAO2M0+tXHIcuKeL+kEHvZ RJMPSvTel1glDMUAQwOsb7aWkhFeiQmsFUlF3YXrpPdhVCBSaiOPfNUnOOjgBXptHtuI oZcBc6EmCRsR7kXHimrKteUr2D3C8X4mALKLQdXbRNkWcKAboQP8lgp4i302/O0TKug/ dcOXObXl8UsR94MJIjYQcy/UlfhRUCmB9si+H0yIFo2MA+qHRhbBQdhJfsF5Q56m6Seg DXxJfWfU6BkO1d9zpkvvuyChaAdA9SelqS6Mr75+6Nnqj+ESLvrdZFJE3MGntuMFXHmb se2A== X-Gm-Message-State: ALoCoQlVJj2O0t6/jD7x+ckyRNbHcRScpvVt6/tQ2BTUFNvsrAZkqOcA8J3BDvUOI3o9MIPX3LFc X-Received: by 10.66.158.193 with SMTP id ww1mr2381072pab.12.1407253502152; Tue, 05 Aug 2014 08:45:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.149 with SMTP id n21ls392697qgd.2.gmail; Tue, 05 Aug 2014 08:45:02 -0700 (PDT) X-Received: by 10.53.3.169 with SMTP id bx9mr2218815vdd.80.1407253502018; Tue, 05 Aug 2014 08:45:02 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id g8si1386570vdk.33.2014.08.05.08.45.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 08:45:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so1783744vcb.40 for ; Tue, 05 Aug 2014 08:45:01 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr3952860vdz.24.1407253501885; Tue, 05 Aug 2014 08:45:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp399764vcb; Tue, 5 Aug 2014 08:45:01 -0700 (PDT) X-Received: by 10.68.238.69 with SMTP id vi5mr5105530pbc.99.1407253500744; Tue, 05 Aug 2014 08:45:00 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df3si2372231pbc.99.2014.08.05.08.45.00 for ; Tue, 05 Aug 2014 08:45:00 -0700 (PDT) Received-SPF: none (google.com: netdev-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754606AbaHEPo5 (ORCPT + 3 others); Tue, 5 Aug 2014 11:44:57 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:48990 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753214AbaHEPo4 (ORCPT ); Tue, 5 Aug 2014 11:44:56 -0400 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.143]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 38DE213F987; Tue, 5 Aug 2014 10:44:40 -0500 (CDT) From: Marc Zyngier To: netdev@vger.kernel.org, linux-sunxi@googlegroups.com Cc: Stefan Roese , Maxime Ripard Subject: [PATCH] net: sun4i-emac: fix memory leak on bad packet Date: Tue, 5 Aug 2014 16:44:39 +0100 Message-Id: <1407253479-30076-1-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 2.0.0 Sender: netdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: netdev@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Upon reception of a new frame, the emac driver checks for a number of error conditions, and flag the packet as "bad" if any of these are present. It then allocates a skb unconditionally, but only uses it if the packet is "good". On the error path, the skb is just forgotten, and the system leaks memory. The piece of junk I have on my desk seems to encounter such error frequently enough so that the box goes OOM after a couple of days, which makes me grumpy. Fix this by moving the allocation on the "good_packet" path (and convert it to netdev_alloc_skb while we're at it). Tested on a random Allwinner A20 board. Cc: Stefan Roese Cc: Maxime Ripard Cc: # 3.11+ Signed-off-by: Marc Zyngier Acked-by: Maxime Ripard --- drivers/net/ethernet/allwinner/sun4i-emac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c index d81e716..29b9f08 100644 --- a/drivers/net/ethernet/allwinner/sun4i-emac.c +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c @@ -633,8 +633,10 @@ static void emac_rx(struct net_device *dev) } /* Move data from EMAC */ - skb = dev_alloc_skb(rxlen + 4); - if (good_packet && skb) { + if (good_packet) { + skb = netdev_alloc_skb(dev, rxlen + 4); + if (!skb) + continue; skb_reserve(skb, 2); rdptr = (u8 *) skb_put(skb, rxlen - 4);