Skip to content

Commit e0255ae

Browse files
committed
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI fix from James Bottomley: "Eve of merge window fix: The original code was so bogus as to be casting the wrong generic device to an rport and proceeding to take actions based on the bogus values it found. Fortunately it seems the location that is dereferenced always exists, so the code hasn't oopsed yet, but it certainly annoys the memory checkers" * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: scsi_transport_srp: Fix shost to rport translation
2 parents ada7339 + c9ddf73 commit e0255ae

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/scsi/scsi_transport_srp.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct srp_internal {
5151
struct transport_container rport_attr_cont;
5252
};
5353

54+
static int scsi_is_srp_rport(const struct device *dev);
55+
5456
#define to_srp_internal(tmpl) container_of(tmpl, struct srp_internal, t)
5557

5658
#define dev_to_rport(d) container_of(d, struct srp_rport, dev)
@@ -60,9 +62,24 @@ static inline struct Scsi_Host *rport_to_shost(struct srp_rport *r)
6062
return dev_to_shost(r->dev.parent);
6163
}
6264

65+
static int find_child_rport(struct device *dev, void *data)
66+
{
67+
struct device **child = data;
68+
69+
if (scsi_is_srp_rport(dev)) {
70+
WARN_ON_ONCE(*child);
71+
*child = dev;
72+
}
73+
return 0;
74+
}
75+
6376
static inline struct srp_rport *shost_to_rport(struct Scsi_Host *shost)
6477
{
65-
return transport_class_to_srp_rport(&shost->shost_gendev);
78+
struct device *child = NULL;
79+
80+
WARN_ON_ONCE(device_for_each_child(&shost->shost_gendev, &child,
81+
find_child_rport) < 0);
82+
return child ? dev_to_rport(child) : NULL;
6683
}
6784

6885
/**
@@ -600,7 +617,8 @@ enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
600617
struct srp_rport *rport = shost_to_rport(shost);
601618

602619
pr_debug("timeout for sdev %s\n", dev_name(&sdev->sdev_gendev));
603-
return rport->fast_io_fail_tmo < 0 && rport->dev_loss_tmo < 0 &&
620+
return rport && rport->fast_io_fail_tmo < 0 &&
621+
rport->dev_loss_tmo < 0 &&
604622
i->f->reset_timer_if_blocked && scsi_device_blocked(sdev) ?
605623
BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
606624
}

0 commit comments

Comments
 (0)