Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp254429rdb; Wed, 17 Jan 2024 00:19:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAcR6ILVw8ELToBBJNSJr1Nk5J/F2Zj3cW+XQ/h+qsJCLuQMjFp75M3fpIvyxx6IzLeXql X-Received: by 2002:a17:907:a4b:b0:a1f:aca1:6bc with SMTP id be11-20020a1709070a4b00b00a1faca106bcmr4232689ejc.100.1705479565397; Wed, 17 Jan 2024 00:19:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705479565; cv=pass; d=google.com; s=arc-20160816; b=GSVfKZRC1ksls6Rgu24p7eoFU6T+45P4CfAbpOzBBHtrVd5gaCnGUnxOJImGOZNsNp b6pLWr37Xl53oEzeX1FVkSVKpOknD7mhb+Ly0pXIA3xttN6Hvv79imw0+MGs9if1+Knb 05FWoh8xUh6yDke+f5ZslMmJzZtw2cTcdu9YLv087uOeSGB2MmdUDHr7Zk9HSiGh4PXd mXOpFYivdhJTvGIZmMDbc0OcAuS4fQGqwXT7+3G+i2m3gwlI7UwBc5WEjC9fa3Ii/ymj xR41//gUzITFeYhQ7FA/7Fim7k/oqpKPVPDyVVvF1qt9waNlAMUAr8Io4UOayXLzMs4P EGFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=YjPRZmdDVbd4mElgciE9VaMSWyyJiJ1T397KF5HyEu0=; fh=oDthjG27qi8h+f6Qofx2xdktggJdSn+kdwA4uBK9ly4=; b=CrVF6WnnyxgUZL5aKNQar4wnYd0IewNWY8sO6S8Ir11yNvTSqbqP55FIdWY9tN3tyq /8575tTV2owP0l3tvz0VIrDbn93Gr7UbzTHoAcnlC2sVpAXsmCDKydiu128x8Vf0Zy8a 8E05B8srjGdwHgq51sLlViz2MjoOaRJf3xx8jaCmV0GfB+5v+XJFi03nzrCk+w/ELlhi JkW25uGcKzJE6TfxTbmE3Z+Bte10CP/J1xIiiMD10Lbgw5vQAbpDYYWJIMKY+Z3qPgOp tU3AnhFSrPu5jwOQZJXP418hbT6VZvT/447GRExPWEmCKpiylgRYqUyi2tsV0VD2MJDp oYLA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-28637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28637-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lv10-20020a170906bc8a00b00a2eb7685549si560555ejb.953.2024.01.17.00.19.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 00:19:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-28637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28637-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0FAE01F254EF for ; Wed, 17 Jan 2024 08:19:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3F31125AF; Wed, 17 Jan 2024 08:19:01 +0000 (UTC) Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.231.56.155]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02572CA73; Wed, 17 Jan 2024 08:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=20.231.56.155 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479541; cv=none; b=GNfC3IRQsilu77N2d7+8QXsfbxmcdKQViURx5yq3Mj+a0JFGLD2rIs3PiDiSiSkI+KAoAD7f5XL8fSpwp+Fu1zVCBEyz9DDFJvSOfjw9KHhsMy32WyqLM2XXur+mxYlva0wlfzGvewl1By1QMoWMB4/IkqzgXWRcTJWtLI5Z7SM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705479541; c=relaxed/simple; bh=YOzCraFGvw1PLY77Yxo76qhKtpwqmc8DWbhhZXYpDYE=; h=Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; b=Og5x1Nx4nx42B6R5TWAo0ebNdAr4tJKK4qSKZy05Cy3QF0Li2Sf3TZuQwV1AVMj17U2QXlO2xqSE7yRG24P7m6kdI0ijKCFCdOuCPJMHV+czXQgknyVQ8+8m+Cr8prtm+Ue9evN5uKcgN2dAf6xcrJoHZ666pmY6QgmGm5CT53g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=20.231.56.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [183.159.170.227]) by mail-app4 (Coremail) with SMTP id cS_KCgCHo4IyjKdlfk0uAA--.42394S2; Wed, 17 Jan 2024 16:13:38 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Kashyap Desai , Sumit Saxena , Shivasharan S , Chandrakanth patil , "James E.J. Bottomley" , "Martin K. Petersen" , megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: megaraid_sas: Fix a memleak in megasas_init_fw Date: Wed, 17 Jan 2024 16:13:13 +0800 Message-Id: <20240117081314.3818871-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cS_KCgCHo4IyjKdlfk0uAA--.42394S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tFyfZr4Dur1xCr1xGFW5Awb_yoW8uF4Upr yruw13tr17AayfWrWDKw4F9ayjya18G345Kr18t34j934agry5XF4vgrWxGFn7CF95JF9x Zrn8Xr1fCF4jgaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCY02Avz4vE14v_GFyl42xK82IYc2Ij64vIr4 1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK 67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI 8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUObyZUUUUU X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ In the error-handling paths after allocation of fusion->stream_detect_by_ld and fusion->stream_detect_by_ld[i], megasas_init_fw should free them or there would be memleaks. Fixes: 2e47e4e62e40 ("scsi: megaraid_sas: Fail init if heartbeat timer fails") Signed-off-by: Zhipeng Lu --- drivers/scsi/megaraid/megaraid_sas_base.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 3d4f13da1ae8..046d7c880be6 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -6378,11 +6378,7 @@ static int megasas_init_fw(struct megasas_instance *instance) if (!fusion->stream_detect_by_ld[i]) { dev_err(&instance->pdev->dev, "unable to allocate stream detect by LD\n "); - for (j = 0; j < i; ++j) - kfree(fusion->stream_detect_by_ld[j]); - kfree(fusion->stream_detect_by_ld); - fusion->stream_detect_by_ld = NULL; - goto fail_get_ld_pd_list; + goto fail_alloc_stream_detect; } fusion->stream_detect_by_ld[i]->mru_bit_map = MR_STREAM_BITMAP; @@ -6502,7 +6498,7 @@ static int megasas_init_fw(struct megasas_instance *instance) megasas_start_timer(instance); } else { instance->skip_heartbeat_timer_del = 1; - goto fail_get_ld_pd_list; + goto fail_alloc_stream_detect; } } @@ -6520,6 +6516,13 @@ static int megasas_init_fw(struct megasas_instance *instance) fail_start_watchdog: if (instance->requestorId && !instance->skip_heartbeat_timer_del) del_timer_sync(&instance->sriov_heartbeat_timer); +fail_alloc_stream_detect: + if (instance->adapter_type >= VENTURA_SERIES) { + for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) + kfree(fusion->stream_detect_by_ld[i]); + kfree(fusion->stream_detect_by_ld); + fusion->stream_detect_by_ld = NULL; + } fail_get_ld_pd_list: instance->instancet->disable_intr(instance); megasas_destroy_irqs(instance); -- 2.34.1