From patchwork Wed Jun 2 13:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 452942 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=-16.1 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, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED 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 477F5C4708F for ; Wed, 2 Jun 2021 13:30:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29948611CA for ; Wed, 2 Jun 2021 13:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbhFBNca (ORCPT ); Wed, 2 Jun 2021 09:32:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60312 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhFBNca (ORCPT ); Wed, 2 Jun 2021 09:32:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622640647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E0clE7oUgmYprbx5VRb/XN2QBzVz2hh0Wwbt0Jz64fQ=; b=Z9ujpTD11NXpSzeIgqw174Xne0KAiVCBg5ExGrEeqSh1/SwXYeOjouxs7RyhRu7WH3k58h +1u53oRrQp2vsksWbqk92Jmgsc/yoIgAtX7lxrZFFDcRJ/GWQErTSopdW4TsD7auT7ueEC vN0LMDVxCpFNmAtk/K9wegZ04OAeDwo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-fV73b7dYPcmhbceHLxgfmw-1; Wed, 02 Jun 2021 09:30:46 -0400 X-MC-Unique: fV73b7dYPcmhbceHLxgfmw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9446F6D241; Wed, 2 Jun 2021 13:30:44 +0000 (UTC) Received: from localhost (ovpn-12-176.pek2.redhat.com [10.72.12.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F88819D9B; Wed, 2 Jun 2021 13:30:40 +0000 (UTC) From: Ming Lei To: "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Ming Lei , Bart Van Assche , John Garry , Hannes Reinecke Subject: [PATCH 1/4] scsi: core: fix error handling of scsi_host_alloc Date: Wed, 2 Jun 2021 21:30:26 +0800 Message-Id: <20210602133029.2864069-2-ming.lei@redhat.com> In-Reply-To: <20210602133029.2864069-1-ming.lei@redhat.com> References: <20210602133029.2864069-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org After device is initialized via device_initialize(), or its name is set via dev_set_name(), the device has to be freed via put_device(), otherwise device name will be leaked because it is allocated dynamically in dev_set_name(). Fixes the issue by replacing kfree(shost) via put_device(&shost->shost_gendev) which can help to free dev_name(&shost->shost_dev) when host state is in SHOST_CREATED. Meantime needn't to remove IDA and stop the kthread of shost->ehandler in the error handling code. Cc: Bart Van Assche Cc: John Garry Cc: Hannes Reinecke Signed-off-by: Ming Lei Reviewed-by: Bart Van Assche Reviewed-by: John Garry Reviewed-by: Hannes Reinecke --- drivers/scsi/hosts.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 624e2582c3df..25cf76e73595 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -391,8 +391,10 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) mutex_init(&shost->scan_mutex); index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL); - if (index < 0) - goto fail_kfree; + if (index < 0) { + kfree(shost); + return NULL; + } shost->host_no = index; shost->dma_channel = 0xff; @@ -484,7 +486,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) shost_printk(KERN_WARNING, shost, "error handler thread failed to spawn, error = %ld\n", PTR_ERR(shost->ehandler)); - goto fail_index_remove; + goto fail; } shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d", @@ -493,17 +495,18 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) if (!shost->tmf_work_q) { shost_printk(KERN_WARNING, shost, "failed to create tmf workq\n"); - goto fail_kthread; + goto fail; } scsi_proc_hostdir_add(shost->hostt); return shost; + fail: + /* + * host state is still SHOST_CREATED, and it is enough to release + * ->shost_gendev since scsi_host_dev_release() can help to free + * dev_name(&shost->shost_dev) + */ + put_device(&shost->shost_gendev); - fail_kthread: - kthread_stop(shost->ehandler); - fail_index_remove: - ida_simple_remove(&host_index_ida, shost->host_no); - fail_kfree: - kfree(shost); return NULL; } EXPORT_SYMBOL(scsi_host_alloc); From patchwork Wed Jun 2 13:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 453748 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=-16.1 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, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED 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 76456C47083 for ; Wed, 2 Jun 2021 13:30:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F0D3613D6 for ; Wed, 2 Jun 2021 13:30:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbhFBNcj (ORCPT ); Wed, 2 Jun 2021 09:32:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50273 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhFBNci (ORCPT ); Wed, 2 Jun 2021 09:32:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622640655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=20YYFLVaa8L5M/MJszhr1uRhV900ACMgcrFhUGBNHoU=; b=LDwcf/pJ9CUX0gnIlHnawKuYyiM4BFZzmhP9ImfkCcoUWwcQxwnuF6TNPkUQpnHXvIqtiQ s3ZgW9Z4aHD9iLknhal3y3QHl0YOpW1GVGdfP3OF7CqrphaO3OKxl0KvDXVWLoiPvYDsGe Fz/8yDQ6/sFCqGOdHFvCATycfgp70aA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-f-3EOdzhOIGDhMdQB1NX8g-1; Wed, 02 Jun 2021 09:30:51 -0400 X-MC-Unique: f-3EOdzhOIGDhMdQB1NX8g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C19B719251A4; Wed, 2 Jun 2021 13:30:50 +0000 (UTC) Received: from localhost (ovpn-12-176.pek2.redhat.com [10.72.12.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB945620DE; Wed, 2 Jun 2021 13:30:46 +0000 (UTC) From: Ming Lei To: "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Ming Lei , Bart Van Assche , John Garry , Hannes Reinecke Subject: [PATCH 2/4] scsi: core: fix failure handling of scsi_add_host_with_dma Date: Wed, 2 Jun 2021 21:30:27 +0800 Message-Id: <20210602133029.2864069-3-ming.lei@redhat.com> In-Reply-To: <20210602133029.2864069-1-ming.lei@redhat.com> References: <20210602133029.2864069-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When scsi_add_host_with_dma() return failure, the caller will call scsi_host_put(shost) to release everything allocated for this host instance. So we can't free allocated stuff in scsi_add_host_with_dma(), otherwise double free will be caused. Strictly speaking, these host resources allocation should have been moved to scsi_host_alloc(), but the allocation may need driver's info which can be built between calling scsi_host_alloc() and scsi_add_host(), so just keep the allocations in scsi_add_host_with_dma(). Fixes the problem by relying on host device's release handler to release everything. Cc: Bart Van Assche Cc: John Garry Cc: Hannes Reinecke Signed-off-by: Ming Lei Reviewed-by: John Garry Reviewed-by: Hannes Reinecke --- 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 25cf76e73595..796736e47764 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -281,23 +281,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, so don't free them in the failure path + */ out_del_dev: device_del(&shost->shost_dev); out_del_gendev: @@ -307,7 +306,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; } From patchwork Wed Jun 2 13:30:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 452941 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=-16.1 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, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED 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 394C8C4708F for ; Wed, 2 Jun 2021 13:31:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21AF8611CA for ; Wed, 2 Jun 2021 13:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbhFBNcn (ORCPT ); Wed, 2 Jun 2021 09:32:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22520 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbhFBNcm (ORCPT ); Wed, 2 Jun 2021 09:32:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622640659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zs5thUCzzMflTBqmeziZ9dfRocubSyhR9ZnK5FyaX1o=; b=GKv/sYIUAKO/Ba+3jq59p7c9JPNfriLnL4b/eDpt4aMHnJ6UyK+wA08U59aOcC28nJIpGd EPjf4ijaV2o4hvVarFAIv2htOD4ndk4tNfgRaYCHvw6v56P9J6p7gkRCatEDjYVdAcd89T +A2AghDV+bhgeA2VWazzOcWJUaWJXlQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-GRmxQegLPBGwWfI5FF8yDA-1; Wed, 02 Jun 2021 09:30:58 -0400 X-MC-Unique: GRmxQegLPBGwWfI5FF8yDA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E8706D241; Wed, 2 Jun 2021 13:30:57 +0000 (UTC) Received: from localhost (ovpn-12-176.pek2.redhat.com [10.72.12.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 034EB687F6; Wed, 2 Jun 2021 13:30:52 +0000 (UTC) From: Ming Lei To: "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Ming Lei , John Garry , Bart Van Assche , Hannes Reinecke Subject: [PATCH 3/4] scsi: core: put .shost_dev in failure path if host state becomes running Date: Wed, 2 Jun 2021 21:30:28 +0800 Message-Id: <20210602133029.2864069-4-ming.lei@redhat.com> In-Reply-To: <20210602133029.2864069-1-ming.lei@redhat.com> References: <20210602133029.2864069-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_host_dev_release() only works around for us by freeing dev_name(&shost->shost_dev) when host state is SHOST_CREATED. After host state is changed to SHOST_RUNNING, scsi_host_dev_release() doesn't do that any more. So fix the issue by put .shost_dev in failure path if host state becomes running, meantime move get_device(&shost->shost_gendev) before device_add(&shost->shost_dev), so that scsi_host_cls_release() can put this reference. Reported-by: John Garry Cc: Bart Van Assche Cc: Hannes Reinecke Signed-off-by: Ming Lei Reviewed-by: John Garry Reviewed-by: Hannes Reinecke --- drivers/scsi/hosts.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 796736e47764..7049844adb6b 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -257,12 +257,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, device_enable_async_suspend(&shost->shost_dev); + get_device(&shost->shost_gendev); error = device_add(&shost->shost_dev); if (error) goto out_del_gendev; - get_device(&shost->shost_gendev); - if (shost->transportt->host_size) { shost->shost_data = kzalloc(shost->transportt->host_size, GFP_KERNEL); @@ -300,6 +299,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, out_del_dev: device_del(&shost->shost_dev); out_del_gendev: + /* + * host state has become SHOST_RUNNING, so we have to release + * ->shost_dev explicitly + */ + put_device(&shost->shost_dev); device_del(&shost->shost_gendev); out_disable_runtime_pm: device_disable_async_suspend(&shost->shost_gendev); From patchwork Wed Jun 2 13:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 453747 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=-16.1 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, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED 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 38074C47083 for ; Wed, 2 Jun 2021 13:31:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20E50613D6 for ; Wed, 2 Jun 2021 13:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbhFBNcx (ORCPT ); Wed, 2 Jun 2021 09:32:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45536 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbhFBNcv (ORCPT ); Wed, 2 Jun 2021 09:32:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622640667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wsl3NWN7p0+Kd/t2d7QPZD5qkLCKK1el/ss3zxa6cCc=; b=E8VF2Sh7CcfLSQSD+DURmyqYRAQu8d2TusxeT9c1A3MgJNc8cbdbDnhfjzFD0MyfZb65IL vGx4XCgsKiQd9dNRBLsggMSpyauDAjCJqzLMkere+t57E+L2xa7gmKvsTRZZezdN/rOvUK VtqfUXrZt2+HbB/xpWyd3IetWx/xOGM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-430-Z1tZTHKcNX-6R1vESRQIRw-1; Wed, 02 Jun 2021 09:31:04 -0400 X-MC-Unique: Z1tZTHKcNX-6R1vESRQIRw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B833801B16; Wed, 2 Jun 2021 13:31:03 +0000 (UTC) Received: from localhost (ovpn-12-176.pek2.redhat.com [10.72.12.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FAA119D9B; Wed, 2 Jun 2021 13:30:58 +0000 (UTC) From: Ming Lei To: "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Ming Lei , Bart Van Assche , John Garry , Hannes Reinecke Subject: [PATCH 4/4] scsi: core: only put parent device if host state isn't in SHOST_CREATED Date: Wed, 2 Jun 2021 21:30:29 +0800 Message-Id: <20210602133029.2864069-5-ming.lei@redhat.com> In-Reply-To: <20210602133029.2864069-1-ming.lei@redhat.com> References: <20210602133029.2864069-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org get_device(shost->shost_gendev.parent) is called after host state is changed to SHOST_RUNNING. So scsi_host_dev_release() shouldn't release the parent device if host state is still SHOST_CREATED. Cc: Bart Van Assche Cc: John Garry Cc: Hannes Reinecke Signed-off-by: Ming Lei Reviewed-by: John Garry --- drivers/scsi/hosts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 7049844adb6b..34db5be7a562 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -350,7 +350,7 @@ static void scsi_host_dev_release(struct device *dev) ida_simple_remove(&host_index_ida, shost->host_no); - if (parent) + if (shost->shost_state != SHOST_CREATED) put_device(parent); kfree(shost); }