diff mbox series

[01/11] scsi: scsi_debug: Don't hold driver host struct pointer in host->hostdata[]

Message ID 20230307105555.3745277-2-john.g.garry@oracle.com (mailing list archive)
State Superseded
Headers show
Series scsi_debug: Some minor improvements | expand

Commit Message

John Garry March 7, 2023, 10:55 a.m. UTC
This driver stores just a pointer to the driver host structure in
host->hostdata[]. Most other drivers actually have the driver host
structure allocated in host->hostdata[], but this driver is different as
we allocate that memory separately.

However there is no need to allocate this memory only in host->hostdata[]
when we can already look up the driver host structure from shost->dma_dev.

Also remove a check for !sdbg_host in find_build_dev_info(), as this cannot
be true. Other similar checks will be later removed.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/scsi/scsi_debug.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Bart Van Assche March 7, 2023, 2:58 p.m. UTC | #1
On 3/7/23 02:55, John Garry wrote:
> +#define to_sdebug_host_from_shost(shost)	\
> +	to_sdebug_host(shost->dma_dev)

Please make the name of this macro shorter and following naming 
conventions used elsewhere in the SCSI core. How about the following 
name: shost_to_sdebug_host()?

Thanks,

Bart.
John Garry March 7, 2023, 3:12 p.m. UTC | #2
On 07/03/2023 14:58, Bart Van Assche wrote:
> On 3/7/23 02:55, John Garry wrote:
>> +#define to_sdebug_host_from_shost(shost)    \
>> +    to_sdebug_host(shost->dma_dev)
> 
> Please make the name of this macro shorter and following naming 
> conventions used elsewhere in the SCSI core. How about the following 
> name: shost_to_sdebug_host()?

ok, fine, I can change that. Maybe then I'll also change 
to_sdebug_host() -> dev_to_sdebug_host() to avoid ambiguity.

Thanks,
John
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 226139a8aaac..f713117a5f2e 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -327,6 +327,9 @@  struct sdeb_store_info {
 #define to_sdebug_host(d)	\
 	container_of(d, struct sdebug_host_info, dev)
 
+#define to_sdebug_host_from_shost(shost)	\
+	to_sdebug_host(shost->dma_dev)
+
 enum sdeb_defer_type {SDEB_DEFER_NONE = 0, SDEB_DEFER_HRT = 1,
 		      SDEB_DEFER_WQ = 2, SDEB_DEFER_POLL = 3};
 
@@ -5168,11 +5171,7 @@  static struct sdebug_dev_info *find_build_dev_info(struct scsi_device *sdev)
 	struct sdebug_dev_info *open_devip = NULL;
 	struct sdebug_dev_info *devip;
 
-	sdbg_host = *(struct sdebug_host_info **)shost_priv(sdev->host);
-	if (!sdbg_host) {
-		pr_err("Host info NULL\n");
-		return NULL;
-	}
+	sdbg_host = to_sdebug_host_from_shost(sdev->host);
 
 	list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
 		if ((devip->used) && (devip->channel == sdev->channel) &&
@@ -5409,7 +5408,7 @@  static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
 	hp = sdp->host;
 	if (!hp)
 		goto lie;
-	sdbg_host = *(struct sdebug_host_info **)shost_priv(hp);
+	sdbg_host = to_sdebug_host_from_shost(hp);
 	if (sdbg_host) {
 		list_for_each_entry(devip,
 				    &sdbg_host->dev_info_list,
@@ -5442,7 +5441,7 @@  static int scsi_debug_bus_reset(struct scsi_cmnd *SCpnt)
 		sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
 	hp = sdp->host;
 	if (hp) {
-		sdbg_host = *(struct sdebug_host_info **)shost_priv(hp);
+		sdbg_host = to_sdebug_host_from_shost(hp);
 		if (sdbg_host) {
 			list_for_each_entry(devip,
 					    &sdbg_host->dev_info_list,
@@ -7821,7 +7820,7 @@  static int sdebug_driver_probe(struct device *dev)
 	if (!sdebug_clustering)
 		sdebug_driver_template.dma_boundary = PAGE_SIZE - 1;
 
-	hpnt = scsi_host_alloc(&sdebug_driver_template, sizeof(sdbg_host));
+	hpnt = scsi_host_alloc(&sdebug_driver_template, 0);
 	if (NULL == hpnt) {
 		pr_err("scsi_host_alloc failed\n");
 		error = -ENODEV;
@@ -7864,7 +7863,6 @@  static int sdebug_driver_probe(struct device *dev)
 		hpnt->nr_maps = 3;
 
 	sdbg_host->shost = hpnt;
-	*((struct sdebug_host_info **)hpnt->hostdata) = sdbg_host;
 	if ((hpnt->this_id >= 0) && (sdebug_num_tgts > hpnt->this_id))
 		hpnt->max_id = sdebug_num_tgts + 1;
 	else