scsi: scsi_debug: Don't hold driver host struct pointer in host->hostdata[]
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 before allocating the shost memory. 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, so add a macro for this - shost_to_sdebug_host(). Rename to_sdebug_host() -> dev_to_sdebug_host() to avoid ambiguity. 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> Link: https://lore.kernel.org/r/20230313093114.1498305-2-john.g.garry@oracle.com Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
parent
fe15c26ee2
commit
785d6b7cf3
|
@ -324,9 +324,12 @@ struct sdeb_store_info {
|
|||
void *map_storep; /* provisioning map */
|
||||
};
|
||||
|
||||
#define to_sdebug_host(d) \
|
||||
#define dev_to_sdebug_host(d) \
|
||||
container_of(d, struct sdebug_host_info, dev)
|
||||
|
||||
#define shost_to_sdebug_host(shost) \
|
||||
dev_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};
|
||||
|
||||
|
@ -5166,11 +5169,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 = shost_to_sdebug_host(sdev->host);
|
||||
|
||||
list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
|
||||
if ((devip->used) && (devip->channel == sdev->channel) &&
|
||||
|
@ -5407,7 +5406,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 = shost_to_sdebug_host(hp);
|
||||
if (sdbg_host) {
|
||||
list_for_each_entry(devip,
|
||||
&sdbg_host->dev_info_list,
|
||||
|
@ -5440,7 +5439,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 = shost_to_sdebug_host(hp);
|
||||
if (sdbg_host) {
|
||||
list_for_each_entry(devip,
|
||||
&sdbg_host->dev_info_list,
|
||||
|
@ -7165,7 +7164,7 @@ static void sdebug_release_adapter(struct device *dev)
|
|||
{
|
||||
struct sdebug_host_info *sdbg_host;
|
||||
|
||||
sdbg_host = to_sdebug_host(dev);
|
||||
sdbg_host = dev_to_sdebug_host(dev);
|
||||
kfree(sdbg_host);
|
||||
}
|
||||
|
||||
|
@ -7812,14 +7811,14 @@ static int sdebug_driver_probe(struct device *dev)
|
|||
struct Scsi_Host *hpnt;
|
||||
int hprot;
|
||||
|
||||
sdbg_host = to_sdebug_host(dev);
|
||||
sdbg_host = dev_to_sdebug_host(dev);
|
||||
|
||||
sdebug_driver_template.can_queue = sdebug_max_queue;
|
||||
sdebug_driver_template.cmd_per_lun = sdebug_max_queue;
|
||||
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;
|
||||
|
@ -7862,7 +7861,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
|
||||
|
@ -7936,7 +7934,7 @@ static void sdebug_driver_remove(struct device *dev)
|
|||
struct sdebug_host_info *sdbg_host;
|
||||
struct sdebug_dev_info *sdbg_devinfo, *tmp;
|
||||
|
||||
sdbg_host = to_sdebug_host(dev);
|
||||
sdbg_host = dev_to_sdebug_host(dev);
|
||||
|
||||
scsi_remove_host(sdbg_host->shost);
|
||||
|
||||
|
|
Loading…
Reference in New Issue