]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bnx2x: fix memory leak in bnx2x_init_firmware()
authorMichal Schmidt <mschmidt@redhat.com>
Thu, 15 Mar 2012 14:08:29 +0000 (14:08 +0000)
committerJoe Jin <joe.jin@oracle.com>
Wed, 16 May 2012 14:52:35 +0000 (22:52 +0800)
When cycling the interface down and up, bnx2x_init_firmware() knows that
the firmware is already loaded, but nevertheless it allocates certain
arrays anew (init_data, init_ops, init_ops_offsets, iro_arr). The old
arrays are leaked.

Fix the leaks by returning early if the firmware was already loaded.
Because if the firmware is loaded, so are the arrays.

(cherry picked from commit c0ea452e422a1fc78ec8c639df64012d0b8dbb4a)
Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
Acked-by: Eilon Greenstein <eilong@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Joe Jin <joe.jin@oracle.com>
drivers/net/bnx2x/bnx2x_main.c

index b954d866ef891d0d53402f5a9f339991d2060c07..2d4bcfa9f04059ef5d94fd90873a7941416f4307 100644 (file)
@@ -10841,38 +10841,36 @@ do {                                                                  \
 
 int bnx2x_init_firmware(struct bnx2x *bp)
 {
+       const char *fw_file_name;
        struct bnx2x_fw_file_hdr *fw_hdr;
        int rc;
 
+       if (bp->firmware)
+               return 0;
 
-       if (!bp->firmware) {
-               const char *fw_file_name;
-
-               if (CHIP_IS_E1(bp))
-                       fw_file_name = FW_FILE_NAME_E1;
-               else if (CHIP_IS_E1H(bp))
-                       fw_file_name = FW_FILE_NAME_E1H;
-               else if (!CHIP_IS_E1x(bp))
-                       fw_file_name = FW_FILE_NAME_E2;
-               else {
-                       BNX2X_ERR("Unsupported chip revision\n");
-                       return -EINVAL;
-               }
-               BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
+       if (CHIP_IS_E1(bp))
+               fw_file_name = FW_FILE_NAME_E1;
+       else if (CHIP_IS_E1H(bp))
+               fw_file_name = FW_FILE_NAME_E1H;
+       else if (!CHIP_IS_E1x(bp))
+               fw_file_name = FW_FILE_NAME_E2;
+       else {
+               BNX2X_ERR("Unsupported chip revision\n");
+               return -EINVAL;
+       }
+       BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
 
-               rc = request_firmware(&bp->firmware, fw_file_name,
-                                     &bp->pdev->dev);
-               if (rc) {
-                       BNX2X_ERR("Can't load firmware file %s\n",
-                                 fw_file_name);
-                       goto request_firmware_exit;
-               }
+       rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
+       if (rc) {
+               BNX2X_ERR("Can't load firmware file %s\n",
+                         fw_file_name);
+               goto request_firmware_exit;
+       }
 
-               rc = bnx2x_check_firmware(bp);
-               if (rc) {
-                       BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
-                       goto request_firmware_exit;
-               }
+       rc = bnx2x_check_firmware(bp);
+       if (rc) {
+               BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
+               goto request_firmware_exit;
        }
 
        fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;