From patchwork Mon May 3 15:03:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 430725 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.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT 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 30892C433ED for ; Mon, 3 May 2021 15:03:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F78611C9 for ; Mon, 3 May 2021 15:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbhECPEs (ORCPT ); Mon, 3 May 2021 11:04:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:40894 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbhECPEk (ORCPT ); Mon, 3 May 2021 11:04:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A0124B1C4; Mon, 3 May 2021 15:03:44 +0000 (UTC) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , John Garry , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 06/18] scsi: Use dummy inquiry data for the host device Date: Mon, 3 May 2021 17:03:21 +0200 Message-Id: <20210503150333.130310-7-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210503150333.130310-1-hare@suse.de> References: <20210503150333.130310-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Attach the dummy inquiry data to the scsi host device and use it to check if any given device is a scsi host device. Signed-off-by: Hannes Reinecke --- drivers/scsi/scsi_scan.c | 17 +++++++++++++++-- drivers/scsi/scsi_sysfs.c | 3 ++- include/scsi/scsi_host.h | 7 ++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index a50abba41ac1..55fa7f7317a2 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1940,9 +1940,11 @@ struct scsi_device *scsi_get_host_dev(struct Scsi_Host *shost) goto out; sdev = scsi_alloc_sdev(starget, 0, NULL); - if (sdev) + if (sdev) { sdev->borken = 0; - else + sdev->inquiry = (unsigned char *)scsi_null_inquiry; + sdev->inquiry_len = sizeof(scsi_null_inquiry); + } else scsi_target_reap(starget); put_device(&starget->dev); out: @@ -1967,3 +1969,14 @@ void scsi_free_host_dev(struct scsi_device *sdev) } EXPORT_SYMBOL(scsi_free_host_dev); +/** + * scsi_device_is_host_dev - Check if a scsi device is a host device + * @sdev: SCSI device to test + * + * Returns: true if @sdev is a host device, false otherwise + */ +bool scsi_device_is_host_dev(struct scsi_device *sdev) +{ + return ((const unsigned char *)sdev->inquiry == scsi_null_inquiry); +} +EXPORT_SYMBOL_GPL(scsi_device_is_host_dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 6d2a28294092..d5260d1b7b38 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -498,7 +498,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) kfree_rcu(vpd_pg80, rcu); if (vpd_pg89) kfree_rcu(vpd_pg89, rcu); - kfree(sdev->inquiry); + if (!scsi_device_is_host_dev(sdev)) + kfree(sdev->inquiry); kfree(sdev); if (parent) diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 3f3ebfdedeb2..f492e9034a62 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -804,14 +804,15 @@ void scsi_host_busy_iter(struct Scsi_Host *, struct class_container; /* - * These two functions are used to allocate and free a pseudo device - * which will connect to the host adapter itself rather than any - * physical device. You must deallocate when you are done with the + * These three functions are used to allocate, free, and test for + * a pseudo device which will connect to the host adapter itself rather + * than any physical device. You must deallocate when you are done with the * thing. This physical pseudo-device isn't real and won't be available * from any high-level drivers. */ extern void scsi_free_host_dev(struct scsi_device *); extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *); +bool scsi_device_is_host_dev(struct scsi_device *); /* * DIF defines the exchange of protection information between