boot: fix crash on early memory allocations
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
be49cc4839
commit
1d1dad34ce
10 changed files with 120 additions and 32 deletions
|
|
@ -302,7 +302,7 @@ static struct sata_device *init_sata_port(struct ahci_host *host, u32 port, int
|
|||
struct ahci_identify ident;
|
||||
int ret = ahci_identify(&abar->ports[port], &ident, packet);
|
||||
if (ret < 0) {
|
||||
kprintf(LOG_ERROR "AHCI: identify failed on port %d\n", port);
|
||||
kerr("AHCI: identify failed on port %d\n", port);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -335,18 +335,12 @@ static struct sata_device *init_sata_port(struct ahci_host *host, u32 port, int
|
|||
cd_device_count++;
|
||||
else
|
||||
sata_device_count++;
|
||||
const char *type_str = packet ? "ATAPI" : (sdev->media_type == 2 ? "SSD" : "HDD");
|
||||
kprintf(LOG_INFO "/dev/%s: %s at port %d: %zd sectors, %zdb, model: %s\n", sdev->name, type_str, port, sdev->sector_count,
|
||||
sdev->sector_size, sdev->model);
|
||||
|
||||
struct block_device *bdev = kzalloc(sizeof(struct block_device), ALLOC_KERN);
|
||||
if (!bdev)
|
||||
return sdev;
|
||||
|
||||
struct block_device *bdev;
|
||||
block_device_register(sdev->name, 0, &ahci_block_ops, &bdev);
|
||||
bdev->priv = sdev;
|
||||
bdev->size = sdev->sector_count;
|
||||
bdev->block_size = sdev->sector_size;
|
||||
bdev->ops = ahci_block_ops;
|
||||
bdev->disk.is_disk = true;
|
||||
|
||||
strncpy(bdev->name, name, sizeof(bdev->name) - 1);
|
||||
|
|
@ -383,15 +377,9 @@ static void ahci_probe_ports(struct ahci_host *host)
|
|||
|
||||
static int ahci_init_device(struct pci_device *device, size_t ahci_dev_no)
|
||||
{
|
||||
struct block_device *bdev = kzalloc(sizeof(struct block_device), ALLOC_KERN);
|
||||
if (!bdev)
|
||||
return -ENOMEM;
|
||||
|
||||
struct ahci_host *host = kzalloc(sizeof(struct ahci_host), ALLOC_KERN);
|
||||
if (!host) {
|
||||
kfree(bdev);
|
||||
if (!host)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
host->abar = map_mmio_dev(device->bar5, PAGE_SIZE);
|
||||
host->device = device;
|
||||
|
|
|
|||
Loading…
Reference in a new issue