Skip to content

Commit ed53779

Browse files
committed
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI fixes from James Bottomley: "Two small changes, one in the lpfc driver and the other in the core. The core change is an additional footgun guard which prevents users from writing the wrong state to sysfs and causing a hang" * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: lpfc: Fix memory leak in lpfc_create_port() scsi: core: Restrict legal sdev_state transitions via sysfs
2 parents d4b7332 + dc8e483 commit ed53779

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,7 +4812,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
48124812
rc = lpfc_vmid_res_alloc(phba, vport);
48134813

48144814
if (rc)
4815-
goto out;
4815+
goto out_put_shost;
48164816

48174817
/* Initialize all internally managed lists. */
48184818
INIT_LIST_HEAD(&vport->fc_nodes);
@@ -4830,16 +4830,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
48304830

48314831
error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
48324832
if (error)
4833-
goto out_put_shost;
4833+
goto out_free_vmid;
48344834

48354835
spin_lock_irq(&phba->port_list_lock);
48364836
list_add_tail(&vport->listentry, &phba->port_list);
48374837
spin_unlock_irq(&phba->port_list_lock);
48384838
return vport;
48394839

4840-
out_put_shost:
4840+
out_free_vmid:
48414841
kfree(vport->vmid);
48424842
bitmap_free(vport->vmid_priority_range);
4843+
out_put_shost:
48434844
scsi_host_put(shost);
48444845
out:
48454846
return NULL;

drivers/scsi/scsi_sysfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,14 @@ store_state_field(struct device *dev, struct device_attribute *attr,
828828
}
829829

830830
mutex_lock(&sdev->state_mutex);
831+
switch (sdev->sdev_state) {
832+
case SDEV_RUNNING:
833+
case SDEV_OFFLINE:
834+
break;
835+
default:
836+
mutex_unlock(&sdev->state_mutex);
837+
return -EINVAL;
838+
}
831839
if (sdev->sdev_state == SDEV_RUNNING && state == SDEV_RUNNING) {
832840
ret = 0;
833841
} else {

0 commit comments

Comments
 (0)