Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751439AbcLDKrB (ORCPT ); Sun, 4 Dec 2016 05:47:01 -0500 Received: from m50-132.163.com ([123.125.50.132]:38119 "EHLO m50-132.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbcLDKq7 (ORCPT ); Sun, 4 Dec 2016 05:46:59 -0500 From: Pan Bian To: Sergei Shtylyov , Michal Kalderon , Yuval Mintz , Ariel Elior , everest-linux-l2@cavium.com, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1 v2] net: bnx2x: fix improper return value Date: Sun, 4 Dec 2016 18:46:03 +0800 Message-Id: <1480848363-16045-1-git-send-email-bianpan201604@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DNGowADnDvPs80NYWWXKIQ--.18027S3 X-Coremail-Antispam: 1Uf129KBjvJXoWrKF18ZFy5KF1xGw45AFyUtrb_yoW8Jry8p3 y7GryUCr4DGrWru348Gw1rZrn8uay3JryqgFW7Z395Za1jy3WDJFsxKrW2qFyDCrWkCF1a qr4Y9wn3Jas0qw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b6ID7UUUUU= X-Originating-IP: [114.243.30.33] X-CM-SenderInfo: held01tdqsiiqwquqiywtou0bp/1tbiNw82+1WBSMB5agAAs6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1169 Lines: 31 From: Pan Bian Macro BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate memory, and jumps to label "lbl" if the allocation fails. Label "lbl" first cleans memory and then returns variable rc. Before calling the macro, the value of variable rc is 0. Because 0 means no error, the callers of bnx2x_init_firmware() may be misled. This patch fixes the bug, assigning "-ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET(). Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141 Signed-off-by: Pan Bian --- drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c index 0cee4c0..6f9fc20 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c @@ -13505,6 +13505,7 @@ static int bnx2x_init_firmware(struct bnx2x *bp) /* Initialize the pointers to the init arrays */ /* Blob */ + rc = -ENOMEM; BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); /* Opcodes */ -- 1.9.1