From: Tejun Heo Date: Fri, 4 Aug 2006 18:59:19 +0000 (+0900) Subject: [PATCH] libata: fix ata_device_add() error path X-Git-Tag: accepted/tizen/common/20141203.182822~35688^2~9^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77f3f879387cc5fce6c7a4ca7777c586fe6291cd;p=platform%2Fkernel%2Flinux-arm64.git [PATCH] libata: fix ata_device_add() error path In the error path, ata_device_add() * dereferences null host_set->ports[] element. * calls scsi_remove_host() on not-yet-added shost. This patch fixes both bugs. The first problem was spotted and initial patch submitted by Dave Jones . The second problem was mentioned and fixed by Jeff Garzik in a larger cleanup patch. Cc: Dave Jones Cc: Jeff Garzik Signed-off-by: Tejun Heo --- diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 509b0488..16fc2dd 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c @@ -5511,10 +5511,10 @@ int ata_device_add(const struct ata_probe_ent *ent) err_out: for (i = 0; i < count; i++) { struct ata_port *ap = host_set->ports[i]; - - scsi_remove_host(ap->host); - ap->ops->port_stop(ap); - scsi_host_put(ap->host); + if (ap) { + ap->ops->port_stop(ap); + scsi_host_put(ap->host); + } } err_free_ret: kfree(host_set);