From patchwork Tue Feb 18 01:10:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 3666431 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 06FA29F1EE for ; Tue, 18 Feb 2014 01:10:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39FD92020F for ; Tue, 18 Feb 2014 01:10:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60B2620142 for ; Tue, 18 Feb 2014 01:10:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753263AbaBRBKm (ORCPT ); Mon, 17 Feb 2014 20:10:42 -0500 Received: from mail-ee0-f41.google.com ([74.125.83.41]:46230 "EHLO mail-ee0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753125AbaBRBKk (ORCPT ); Mon, 17 Feb 2014 20:10:40 -0500 Received: by mail-ee0-f41.google.com with SMTP id e51so6884699eek.0 for ; Mon, 17 Feb 2014 17:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6CYV+mWXnMmO3cHINypjNrnFHQESCjF6Jd3vEuscK0Y=; b=vri6fbmUsgb612RmEPlWx4Mms13k4MM/JgRQmqzRRKC2saHll0Fw1GKf6uDHx1aggF ZWVuJS+r9yIOlks08Aqpeft9Xh/MhK+2TdXP04Oe+EEFhhIQileM/4/y2BNnfqfhX/MZ lnPESPXkCbu4si0M9aRG/7y0mQqjmoa69wmysHSgRwZpkVcZdL/4BwAoChsnc4vfSzkj 0StCSmnroW8Or66zshxWUbDZOWya9LNP1QrSNEVH+oNXECWwQ/i/dY3ql/ceSLn3FLSD cqYCWOWDyGRqLK4OHqIXZVgQaotvaPCB4rMwbyb0dhPkKsGiiP8hMP2cSXSOwcceE/R+ qBdg== X-Received: by 10.14.183.132 with SMTP id q4mr174349eem.91.1392685839561; Mon, 17 Feb 2014 17:10:39 -0800 (PST) Received: from localhost.localdomain ([95.237.125.26]) by mx.google.com with ESMTPSA id j41sm63723093eeg.10.2014.02.17.17.10.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 17:10:38 -0800 (PST) From: Andrea Merello To: linville@tuxdriver.com Cc: linux-wireless@vger.kernel.org, Larry.Finger@lwfinger.net, bernhard@schiffner-limbach.de, dan.carpenter@oracle.com, liuhq11@mails.tsinghua.edu.cn, andrea merello Subject: [PATCH 4/7] rtl818x: make dev_alloc_skb() null pointer check to really work Date: Tue, 18 Feb 2014 02:10:43 +0100 Message-Id: <1392685846-10116-5-git-send-email-andrea.merello@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392685846-10116-1-git-send-email-andrea.merello@gmail.com> References: <1392685846-10116-1-git-send-email-andrea.merello@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: andrea merello During driver initialization, some skbs are preallocated for RX. Currenly if the allocation fails, the driver's allocation routine exits immediatly but it will return zero (success) anyway. In this way the driver will continue initialization with buggy pointers around. This patch makes the driver's allocation routine to return an error value and to print a complaint message when skb allocation fails. In this way its caller will not go further, avoinding the driver to successfully load, and preventing dereferencing buggy pointers. An hint is thus printed about why the driver failed. Signed-off-by: Andrea Merello --- drivers/net/wireless/rtl818x/rtl8180/dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c index 848ea59..cb97380 100644 --- a/drivers/net/wireless/rtl818x/rtl8180/dev.c +++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c @@ -477,9 +477,10 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) struct sk_buff *skb = dev_alloc_skb(MAX_RX_SIZE); dma_addr_t *mapping; entry = &priv->rx_ring[i]; - if (!skb) - return 0; - + if (!skb) { + wiphy_err(dev->wiphy, "Cannot allocate RX skb\n"); + return -ENOMEM; + } priv->rx_buf[i] = skb; mapping = (dma_addr_t *)skb->cb; *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb),