From patchwork Fri Jan 3 16:42:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang ZHAO X-Patchwork-Id: 3432261 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 7AB109F374 for ; Fri, 3 Jan 2014 16:44:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1C68200F3 for ; Fri, 3 Jan 2014 16:44:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9329D200ED for ; Fri, 3 Jan 2014 16:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751302AbaACQoA (ORCPT ); Fri, 3 Jan 2014 11:44:00 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:56876 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751217AbaACQoA (ORCPT ); Fri, 3 Jan 2014 11:44:00 -0500 Received: by mail-pa0-f51.google.com with SMTP id fa1so15889406pad.24 for ; Fri, 03 Jan 2014 08:43:59 -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; bh=3pvxsFRViDuK4cVLjPU3zDGoACB+Q7BcXblKhFVu83s=; b=nMoUZW+DeNd4uJpkBbRM625s4Hr17bEwvyUARx0t2d1/i4dywuTGussWxtgppHQA/T KzwlbGC8NoZiUDiAhQD+pDe7w2A8AZxxW8u8HpFcT9+EDy1BspYCvEvmrVpraSqCb9qF zHdQ8eUS0pjXE9SWube4Ki2g7wYEQ5GXDx3H3bhNq3QLJPm8MgJwUPls9YILKEI5SSRY /E+NhBCTKi6j1vTx1m0quMyyTWZLp43pgWjNbk0pnA2mPmMG9GMlk9xa1RI1vW+dttEP GQhA7VpQnTtWERVcWI6WqfPEq2r4na5SZQZQ2YxvBJrSTYpZNVeu+Df0Z8m+7joPouoT N8ag== X-Received: by 10.66.119.136 with SMTP id ku8mr96362060pab.121.1388767439537; Fri, 03 Jan 2014 08:43:59 -0800 (PST) Received: from localhost.localdomain ([61.157.126.30]) by mx.google.com with ESMTPSA id de1sm110002595pbc.7.2014.01.03.08.43.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jan 2014 08:43:58 -0800 (PST) From: ZHAO Gang To: Johannes Berg Cc: linux-wireless Subject: [PATCH] mac80211: add handler for memeory allocation failure Date: Sat, 4 Jan 2014 00:42:52 +0800 Message-Id: <46c874024953fa47667455051f304041827748e0.1388766243.git.gamerh2o@gmail.com> X-Mailer: git-send-email 1.8.4.2 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 Signed-off-by: ZHAO Gang --- net/mac80211/sta_info.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 4576ba0..c600caf 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -325,8 +325,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, ewma_init(&sta->chain_signal_avg[i], 1024, 8); if (sta_prepare_rate_control(local, sta, gfp)) { - kfree(sta); - return NULL; + goto free_sta; } for (i = 0; i < IEEE80211_NUM_TIDS; i++) { @@ -375,10 +374,15 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, tx_latency = rcu_dereference(local->tx_latency); /* init stations Tx latency statistics && TID bins */ - if (tx_latency) + if (tx_latency) { sta->tx_lat = kzalloc(IEEE80211_NUM_TIDS * sizeof(struct ieee80211_tx_latency_stat), GFP_ATOMIC); + if (!sta->tx_lat) { + rcu_read_unlock(); + goto free_rate_ctrl; + } + } /* * if Tx latency and bins are enabled and the previous allocation @@ -392,12 +396,28 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, sta->tx_lat[i].bins = kcalloc(sta->tx_lat[i].bin_count, sizeof(u32), GFP_ATOMIC); + if (!sta->tx_lat[i].bins) { + rcu_read_unlock(); + goto free_bins; + } } rcu_read_unlock(); sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr); + goto out; +free_bins: + while (i > 0) + kfree(sta->tx_lat[--i].bins); + kfree(sta->tx_lat); +free_rate_ctrl: + if (sta->rate_ctrl) + rate_control_free_sta(sta); +free_sta: + kfree(sta); + sta = NULL; +out: return sta; }