From patchwork Wed Mar 17 19:08:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandrakanth Patil X-Patchwork-Id: 12146863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE,SPF_PASS,T_TVD_MIME_NO_HEADERS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C43C433E0 for ; Wed, 17 Mar 2021 19:09:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72A0B64F53 for ; Wed, 17 Mar 2021 19:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbhCQTJI (ORCPT ); Wed, 17 Mar 2021 15:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbhCQTJE (ORCPT ); Wed, 17 Mar 2021 15:09:04 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B5FC06174A for ; Wed, 17 Mar 2021 12:09:04 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d23so1243726plq.2 for ; Wed, 17 Mar 2021 12:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=krRi+pDI3FmT+M5ah4/Ku2XkHwyHqaSNzv+nMXpr2DQ=; b=gIgl5OowKhGG6wX/E2jmoLjGjOr0YLWXq2wX74SeKQ2BtXqjIkO8fAHFaa1WtCbsa+ FugEI0BnrJotahrCP8CVxpRxgf77qbochUCPDfA+dB/bxSRJRVBkAz4lFko4660mb7vt +jDE8r1tOkd9FNefQjkHmnxXN4gdo9eHLdBXg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=krRi+pDI3FmT+M5ah4/Ku2XkHwyHqaSNzv+nMXpr2DQ=; b=awhYJ2VM3CLJKQWdTy2y6MaEn6YKqkB9FMvKKADdtt7uEBRimkFaKgGrCn4F4W7QVT OWm3LoRNf1kbSl4yk3SuWB0u/yP71Uxr56rvpejZoQ+PHbxeFeZSbwrZJm62lR2oBBt1 wKqkh6UKEf5/pJEhiZzOIy+6A/mEJbSpIzGr7KkxMigLwR8urd8GyhDiYk3WbEH9Dtr5 24jhLaTS1Jh/zyDJbKMMeHOVF4tx795jtQi1T/7mbgRqPVshZR2Nb2GZKZw/RDc9HGtz hFiWjSAelHc0LfeYBQju1jSS0+K9ULtR8fr9cuoLcf+MJlmXsfjxz+fs2+J+uYlq5gY/ +ZnA== X-Gm-Message-State: AOAM532Ht83kf58zP+fyoWypMhm/8eNEviTd5JKVxrt2KcqD72TnJfWF CD/d74brJFtBHUclg0GJZUOXgN+ivoePeUN9606g2dZ3DzYvCqNAwajGw8DCny1kBEcXPIYBErd w6/eM/hsDoO/alAA08Wsjqumx92EhWZxpYVFIm+z3vv9s7y86TvbMQuW+V8TSXNsmIpkiydmN6t WQDc+E2JFkGA0d X-Google-Smtp-Source: ABdhPJz3WLE80BaABZLEYFnox25OTBDSdShMwq02/OGPbEzCsjJXmbz0UkDcmaqdhWfZsD8jAWAPdA== X-Received: by 2002:a17:90a:af8a:: with SMTP id w10mr333728pjq.114.1616008143978; Wed, 17 Mar 2021 12:09:03 -0700 (PDT) Received: from dhcp-10-123-20-75.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id w2sm20569437pgh.54.2021.03.17.12.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 12:09:03 -0700 (PDT) From: Chandrakanth Patil To: linux-scsi@vger.kernel.org Cc: kashyap.desai@broadcom.com, sumit.saxena@broadcom.com, kiran-kumar.kasturi@broadcom.com, sankar.patra@broadcom.com, sasikumar.pc@broadcom.com, shivasharan.srikanteshwara@broadcom.com, anand.lodnoor@broadcom.com, Chandrakanth Patil Subject: [PATCH 2/5] megaraid_sas: Fix the resource leak in case of probe failure Date: Thu, 18 Mar 2021 00:38:21 +0530 Message-Id: <20210317190824.3050-3-chandrakanth.patil@broadcom.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210317190824.3050-1-chandrakanth.patil@broadcom.com> References: <20210317190824.3050-1-chandrakanth.patil@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Driver doesn't cleanup all the allocated resources properly when scsi_add_host(),megasas_start_aen() function fails during the PCI device probe. This patch will cleanup all those resources. Signed-off-by: Chandrakanth Patil Signed-off-by: Sumit Saxena --- drivers/scsi/megaraid/megaraid_sas_base.c | 13 +++++++++++++ drivers/scsi/megaraid/megaraid_sas_fusion.c | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 63a4f48bdc75..7ab741f03b84 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -7478,11 +7478,16 @@ static int megasas_probe_one(struct pci_dev *pdev, return 0; fail_start_aen: + instance->unload = 1; + scsi_remove_host(instance->host); fail_io_attach: megasas_mgmt_info.count--; megasas_mgmt_info.max_index--; megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; + if (instance->requestorId && !instance->skip_heartbeat_timer_del) + del_timer_sync(&instance->sriov_heartbeat_timer); + instance->instancet->disable_intr(instance); megasas_destroy_irqs(instance); @@ -7490,8 +7495,16 @@ static int megasas_probe_one(struct pci_dev *pdev, megasas_release_fusion(instance); else megasas_release_mfi(instance); + if (instance->msix_vectors) pci_free_irq_vectors(instance->pdev); + instance->msix_vectors = 0; + + if (instance->fw_crash_state != UNAVAILABLE) + megasas_free_host_crash_buffer(instance); + + if (instance->adapter_type != MFI_SERIES) + megasas_fusion_stop_watchdog(instance); fail_init_mfi: scsi_host_put(host); fail_alloc_instance: diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 73295cf74cbe..54f8a8073ca0 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -5201,6 +5201,7 @@ megasas_alloc_fusion_context(struct megasas_instance *instance) if (!fusion->log_to_span) { dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__); + kfree(instance->ctrl_context); return -ENOMEM; } }