Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2651545pxj; Mon, 14 Jun 2021 04:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpXciEQNVAD4yqQoBNFXSI42feqfgC6DjWG1JUW9gzfdH+/dKDqjDnPbdKFC/BtrvmxTqB X-Received: by 2002:a17:907:7ba8:: with SMTP id ne40mr14754735ejc.209.1623668690348; Mon, 14 Jun 2021 04:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668690; cv=none; d=google.com; s=arc-20160816; b=oSrPG1iBD5MjncEQkeVrybNM4GhT7VDTWZCtejtCFe6pcOnjWqg/MlpCwAcH4wy+Ng DoqCm37hNNjS9zHDftoK2nB5n5fUq3dnziwyS1HfoPM2mt0Cdv/FBqlFlW18/fX3LHah wPKEte4Uk+1qJ+bdXARi/sRwTMEjAJkGroT/yhoyeO/C0KX9qvXVS44fpBzAVmLqWuuV GAxqUUNPq6uN+qNcNMJsa99GsUUHCnFKGwk1r37al7B9hpSrFqYGonLmkKk0WWyjPlxK oZ7PXqOphcaLJogefy7ExzrcWE7hLLxeaRIG76mOSuw8eFcaYDeYFMRkEprHGjHH7EKA Yxkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lAYwRezoqhYMUEbHL73VPmxdLY2HEK6P2hF2nz9rbmE=; b=CUT+LsorFhJ8f6XNnzJ45ZMzTl5sbmPNi1eBTObza4zwGzaF6APqAClJxicw//p8VR qLTFqxaSWjaEqGPrJtAIrX8XyoB04CTEN0obj8ouPjLRpapYlRVQKToEqLFCvhZ/fxye ExpQ698/j3kIYB+CirD1AnRWaYZMMTk2cvGYRhhheiVWyZAL+DtsmZV91xfKzzkKG7Mu oU/aFga25EfCOP1uBHU1lKqm/mEbLfYGPlUkMRmul65JRJB6bQT9x1F5+S/QWF1UfF9Z 25b5B0Bim3O5ontEhoYig4wu1sDaofP0ZO3KEqB0H+RU3F7bTAQT4fkY2eEVo5IrfmRU A+Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=USFYNLpw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh24si10745182ejb.194.2021.06.14.04.04.28; Mon, 14 Jun 2021 04:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=USFYNLpw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234297AbhFNLDs (ORCPT + 99 others); Mon, 14 Jun 2021 07:03:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:32832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234967AbhFNKy5 (ORCPT ); Mon, 14 Jun 2021 06:54:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD7946157E; Mon, 14 Jun 2021 10:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667241; bh=vJyRxfmZZqgC6hgxCVDtkwR1OygQiw3eDmFdEPMLjk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=USFYNLpwe0ovpJRLp3Bny0JEdcFD+cr6yJ88NAwf9JGa+dWbszrJYPAjogYVbWoZ7 NNvD++mOxDpdWyHJkEJ1qcqz+iyjJs4JlR76aCgQ0Lgm1INN1+QeGdhsAty+QSic7T oS85DrREZlXfyYCFgsnt0iIz3WDcffslUWoex3sU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , John Garry , Hannes Reinecke , Ming Lei , "Martin K. Petersen" Subject: [PATCH 5.4 80/84] scsi: core: Fix failure handling of scsi_add_host_with_dma() Date: Mon, 14 Jun 2021 12:27:58 +0200 Message-Id: <20210614102649.099225996@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102646.341387537@linuxfoundation.org> References: <20210614102646.341387537@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei commit 3719f4ff047e20062b8314c23ec3cab84d74c908 upstream. 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: Greg Kroah-Hartman --- drivers/scsi/hosts.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -275,23 +275,22 @@ int scsi_add_host_with_dma(struct Scsi_H shost->work_q_name); 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: @@ -301,7 +300,6 @@ int scsi_add_host_with_dma(struct Scsi_H 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; }