From mboxrd@z Thu Jan 1 00:00:00 1970 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=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 C5212C48BDF for ; Tue, 15 Jun 2021 15:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B33F861626 for ; Tue, 15 Jun 2021 15:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbhFOPwC (ORCPT ); Tue, 15 Jun 2021 11:52:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:45242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231270AbhFOPvC (ORCPT ); Tue, 15 Jun 2021 11:51:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6044261606; Tue, 15 Jun 2021 15:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623772136; bh=CWn57cX62MYv93TJVhCWkAurqo1QfU4eJSOhxDYLLPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xbng6RH1DB+WFty9ijv4JRUKmI0U6j1icrX9o4i1sEHWBEE6ffvg4Z9OR5kZ3kmuF NKfZt1AFPQ/Q//k/cjmwWO2KUHTGESVkQu8uQAfrwD75JwiuhWplvHQ3l/9Z1v/CS4 UIVfQnddVvqft8eB8aXE+iQdM6Ed4sxB1Gauti+Nvcpk/iOKSMqHXyg8wJxuWgFTVm wkajILByYZyKPLLqljQoh+NORfJHyeqEqto1vZ5jzQ8oU2uMOnAKsU47VC6mEL0TYR nCExsLkx0dOd1k3meYkdmoyNKyOT9NRRPdKjhjfVOTuddOKfSORoeDYK/78avAHQqf pHjGgtE7kFScA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ming Lei , Bart Van Assche , John Garry , Hannes Reinecke , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 25/33] scsi: core: Fix failure handling of scsi_add_host_with_dma() Date: Tue, 15 Jun 2021 11:48:16 -0400 Message-Id: <20210615154824.62044-25-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210615154824.62044-1-sashal@kernel.org> References: <20210615154824.62044-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei [ Upstream commit 3719f4ff047e20062b8314c23ec3cab84d74c908 ] When scsi_add_host_with_dma() returns failure, the caller will call scsi_host_put(shost) to release everything allocated for this host instance. Consequently we can't also free allocated stuff in scsi_add_host_with_dma(), otherwise we will end up with a double free. Strictly speaking, host resource allocations should have been done in scsi_host_alloc(). However, the allocations may need information which is not yet provided by the driver when that function is called. So leave the allocations where they are but rely on host device's release handler to free resources. Link: https://lore.kernel.org/r/20210602133029.2864069-3-ming.lei@redhat.com Cc: Bart Van Assche Cc: John Garry Cc: Hannes Reinecke Tested-by: John Garry Reviewed-by: Bart Van Assche Reviewed-by: John Garry Reviewed-by: Hannes Reinecke Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/hosts.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index d835a7b23614..48ec9c35daa4 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -278,23 +278,22 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, if (!shost->work_q) { error = -EINVAL; - goto out_free_shost_data; + goto out_del_dev; } } error = scsi_sysfs_add_host(shost); if (error) - goto out_destroy_host; + goto out_del_dev; scsi_proc_host_add(shost); scsi_autopm_put_host(shost); return error; - out_destroy_host: - if (shost->work_q) - destroy_workqueue(shost->work_q); - out_free_shost_data: - kfree(shost->shost_data); + /* + * Any host allocation in this function will be freed in + * scsi_host_dev_release(). + */ out_del_dev: device_del(&shost->shost_dev); out_del_gendev: @@ -304,7 +303,6 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, pm_runtime_disable(&shost->shost_gendev); pm_runtime_set_suspended(&shost->shost_gendev); pm_runtime_put_noidle(&shost->shost_gendev); - scsi_mq_destroy_tags(shost); fail: return error; } -- 2.30.2