Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3838507pxv; Mon, 28 Jun 2021 14:19:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaTvTqDWu07xW99ZhH8TOrZNqF+WTQ4pO/c2lqalVHSkzbiLOilxEUOvd0bWNBkunup7f0 X-Received: by 2002:a05:6602:2595:: with SMTP id p21mr1145566ioo.51.1624915164689; Mon, 28 Jun 2021 14:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624915164; cv=none; d=google.com; s=arc-20160816; b=G3gt3y4WqTJFtMEqkhI7gMroDjH9fv7P8mawz0WWwoGohCbAtbxbF28xdR22MahxNa zY0d+Ok+zjCPk9L8y2UstUwObuCdYzkeKJoTjLiEZcErjoW/Z5P9PIOvFfwTOqLNnAh5 cSwSd0QU9YVhcs/RrriXU56Sbs13eKDtxr1X9txzzDaE5EYJHvTRYgDqRda5zrwssAuL 1xiGVXPLltlcKvr++DDlKkdDQxxs4H2OOLCIM1SSWEr2ZMRvEJXUJOxwNxv3yk+ZiUKo Rv8Pmx81S6dFjy5lj6U4+BOEzt2XxQ51PXlZsEaT4BD7cPFq02JdH8Hy1C0+P6uZ89Jt Wcbw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z17y2tkrRf1/z8yzMooJpwIk5mCvAb0e4fNiLP4ps50=; b=mgdqNrQZ6VFDjBagLsFE04Kdzq5Xc8ZYja+VraPahKqK4nZx9/WcybwAwVoBulHgmF x916j8iDqnjWthU+rzAry1bzBaW1a/u3EnVpo6pwTxIN6RVKkqadg8SY++dyRzJeu78v ZRJjw7Nl+sKWI6coe77HXCo7TgQZ2/88SY7byi8XNT6FZ2mmonr8AC8kswD1rlbTTKkf L9raAqAE1ZzqfBvEEusjCTc1o/5tiSlIJxiKB8FUcC/nP4yoXcZHk5WvC2jnziQlmR0e Z4iMFuWDcJXzXTTBU14wHrMsv8EBGZf6nsKqZ4WVCbLBWGKRdV1/OWvDG/YX70IslFpg w2Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V0v4SZxi; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si18089249ilm.75.2021.06.28.14.19.11; Mon, 28 Jun 2021 14:19:24 -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=@kernel.org header.s=k20201202 header.b=V0v4SZxi; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238508AbhF1PVg (ORCPT + 99 others); Mon, 28 Jun 2021 11:21:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235325AbhF1O6d (ORCPT ); Mon, 28 Jun 2021 10:58:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E028A61D54; Mon, 28 Jun 2021 14:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891236; bh=BuOye9YrRd0Abg5wazBV93wK0pvQjc3DrbI37RjN448=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V0v4SZxiQikI3stF24AARqP3NdOnbRbfgXUVwP4NgliDTMN3isHN/iUSCPe6u5wxB ZMjitOWoSqkC240K8/Rolbcy1+GopkvGFUxmz1Tn0DdMWPwOaUJaeTF+v9cnNMcV1U t27mI4hnXsllrDPVlaruLFw8cA59qDUKi9VqCk/e/+4mUnZMC9Ijy7T3suEo87EJHh 34iJy2zh48XexSp83nIQB5grbTY3YXDN1Lz+7Ivw/50HBh7nKjN8YdkmYPZbKvY/mL 7G/FWhzKzDnvnMgWn1hRxzpBC9lPVnZQJ0OHqSELlhwgZjFic6G+AiCNVJ0N8XEhTo 49b5B8eop3lig== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ming Lei , Bart Van Assche , Hannes Reinecke , John Garry , "Martin K . Petersen" , Sasha Levin Subject: [PATCH 4.9 36/71] scsi: core: Put .shost_dev in failure path if host state changes to RUNNING Date: Mon, 28 Jun 2021 10:39:28 -0400 Message-Id: <20210628144003.34260-37-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+00:00 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 11714026c02d613c30a149c3f4c4a15047744529 ] scsi_host_dev_release() only frees dev_name when host state is SHOST_CREATED. After host state has changed to SHOST_RUNNING, scsi_host_dev_release() no longer cleans up. Fix this by doing a put_device(&shost->shost_dev) in the failure path when host state is SHOST_RUNNING. Move get_device(&shost->shost_gendev) before device_add(&shost->shost_dev) so that scsi_host_cls_release() can do a put on this reference. Link: https://lore.kernel.org/r/20210602133029.2864069-4-ming.lei@redhat.com Cc: Bart Van Assche Cc: Hannes Reinecke Reported-by: John Garry Tested-by: John Garry 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index dc09f10d5d4b..604cf3385aae 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -265,12 +265,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); @@ -307,6 +306,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 is SHOST_RUNNING so we have to explicitly release + * ->shost_dev. + */ + put_device(&shost->shost_dev); device_del(&shost->shost_gendev); out_destroy_freelist: device_disable_async_suspend(&shost->shost_gendev); -- 2.30.2