Commit c88c3d97 authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Greg Kroah-Hartman

[PATCH] PCI Hotplug: Convert error paths in ibmphp to use goto

This patch converts the error paths in several functions in ibmphp to use
goto to the end of the function to kill code duplication.

It also kills some memsets of pointer members of a struct where the struct
itself is freed directly after.

This one has 2 modification from the first version: the if is back as
discussed and one extra long line (>> 150 chars) is wrapped now.
parent a6776ea2
...@@ -89,36 +89,34 @@ static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count) ...@@ -89,36 +89,34 @@ static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
controller = kmalloc (sizeof (struct controller), GFP_KERNEL); controller = kmalloc (sizeof (struct controller), GFP_KERNEL);
if (!controller) if (!controller)
return NULL; goto error;
memset (controller, 0, sizeof (*controller)); memset (controller, 0, sizeof (*controller));
slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL); slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL);
if (!slots) { if (!slots)
kfree (controller); goto error_contr;
return NULL;
}
memset (slots, 0, sizeof (*slots) * slot_count); memset (slots, 0, sizeof (*slots) * slot_count);
controller->slots = slots; controller->slots = slots;
buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL); buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL);
if (!buses) { if (!buses)
kfree (controller->slots); goto error_slots;
kfree (controller);
return NULL;
}
memset (buses, 0, sizeof (*buses) * bus_count); memset (buses, 0, sizeof (*buses) * bus_count);
controller->buses = buses; controller->buses = buses;
return controller; return controller;
error_slots:
kfree(controller->slots);
error_contr:
kfree(controller);
error:
return NULL;
} }
static void free_ebda_hpc (struct controller *controller) static void free_ebda_hpc (struct controller *controller)
{ {
kfree (controller->slots); kfree (controller->slots);
controller->slots = NULL;
kfree (controller->buses); kfree (controller->buses);
controller->buses = NULL;
controller->ctrl_dev = NULL;
kfree (controller); kfree (controller);
} }
...@@ -286,7 +284,8 @@ static void __init print_ebda_hpc (void) ...@@ -286,7 +284,8 @@ static void __init print_ebda_hpc (void)
int __init ibmphp_access_ebda (void) int __init ibmphp_access_ebda (void)
{ {
u8 format, num_ctlrs, rio_complete, hs_complete; u8 format, num_ctlrs, rio_complete, hs_complete;
u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, rc, re, rc_id, re_id, base; u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base;
int rc = 0;
rio_complete = 0; rio_complete = 0;
...@@ -324,10 +323,8 @@ int __init ibmphp_access_ebda (void) ...@@ -324,10 +323,8 @@ int __init ibmphp_access_ebda (void)
format = readb (io_mem + offset); format = readb (io_mem + offset);
offset += 1; offset += 1;
if (format != 4) { if (format != 4)
iounmap (io_mem); goto error_nodev;
return -ENODEV;
}
debug ("hot blk format: %x\n", format); debug ("hot blk format: %x\n", format);
/* hot swap sub blk */ /* hot swap sub blk */
base = offset; base = offset;
...@@ -339,18 +336,16 @@ int __init ibmphp_access_ebda (void) ...@@ -339,18 +336,16 @@ int __init ibmphp_access_ebda (void)
rc_id = readw (io_mem + sub_addr); /* sub blk id */ rc_id = readw (io_mem + sub_addr); /* sub blk id */
sub_addr += 2; sub_addr += 2;
if (rc_id != 0x5243) { if (rc_id != 0x5243)
iounmap (io_mem); goto error_nodev;
return -ENODEV;
}
/* rc sub blk signature */ /* rc sub blk signature */
num_ctlrs = readb (io_mem + sub_addr); num_ctlrs = readb (io_mem + sub_addr);
sub_addr += 1; sub_addr += 1;
hpc_list_ptr = alloc_ebda_hpc_list (); hpc_list_ptr = alloc_ebda_hpc_list ();
if (!hpc_list_ptr) { if (!hpc_list_ptr) {
iounmap (io_mem); rc = -ENOMEM;
return -ENOMEM; goto out;
} }
hpc_list_ptr->format = format; hpc_list_ptr->format = format;
hpc_list_ptr->num_ctlrs = num_ctlrs; hpc_list_ptr->num_ctlrs = num_ctlrs;
...@@ -361,16 +356,15 @@ int __init ibmphp_access_ebda (void) ...@@ -361,16 +356,15 @@ int __init ibmphp_access_ebda (void)
debug ("offset of hpc data structure enteries: %x\n ", sub_addr); debug ("offset of hpc data structure enteries: %x\n ", sub_addr);
sub_addr = base + re; /* re sub blk */ sub_addr = base + re; /* re sub blk */
/* FIXME: rc is never used/checked */
rc = readw (io_mem + sub_addr); /* next sub blk */ rc = readw (io_mem + sub_addr); /* next sub blk */
sub_addr += 2; sub_addr += 2;
re_id = readw (io_mem + sub_addr); /* sub blk id */ re_id = readw (io_mem + sub_addr); /* sub blk id */
sub_addr += 2; sub_addr += 2;
if (re_id != 0x5245) { if (re_id != 0x5245)
iounmap (io_mem); goto error_nodev;
return -ENODEV;
}
/* signature of re */ /* signature of re */
num_entries = readw (io_mem + sub_addr); num_entries = readw (io_mem + sub_addr);
...@@ -378,8 +372,8 @@ int __init ibmphp_access_ebda (void) ...@@ -378,8 +372,8 @@ int __init ibmphp_access_ebda (void)
sub_addr += 2; /* offset of RSRC_ENTRIES blk */ sub_addr += 2; /* offset of RSRC_ENTRIES blk */
rsrc_list_ptr = alloc_ebda_rsrc_list (); rsrc_list_ptr = alloc_ebda_rsrc_list ();
if (!rsrc_list_ptr ) { if (!rsrc_list_ptr ) {
iounmap (io_mem); rc = -ENOMEM;
return -ENOMEM; goto out;
} }
rsrc_list_ptr->format = format; rsrc_list_ptr->format = format;
rsrc_list_ptr->num_entries = num_entries; rsrc_list_ptr->num_entries = num_entries;
...@@ -391,9 +385,8 @@ int __init ibmphp_access_ebda (void) ...@@ -391,9 +385,8 @@ int __init ibmphp_access_ebda (void)
debug ("offset of rsrc data structure enteries: %x\n ", sub_addr); debug ("offset of rsrc data structure enteries: %x\n ", sub_addr);
hs_complete = 1; hs_complete = 1;
} } else {
/* found rio table */ /* found rio table, blk_id == 0x4752 */
else if (blk_id == 0x4752) {
debug ("now enter io table ---\n"); debug ("now enter io table ---\n");
debug ("rio blk id: %x\n", blk_id); debug ("rio blk id: %x\n", blk_id);
...@@ -406,41 +399,36 @@ int __init ibmphp_access_ebda (void) ...@@ -406,41 +399,36 @@ int __init ibmphp_access_ebda (void)
rio_table_ptr->riodev_count = readb (io_mem + offset + 2); rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
rio_table_ptr->offset = offset +3 ; rio_table_ptr->offset = offset +3 ;
debug ("info about rio table hdr ---\n"); debug("info about rio table hdr ---\n");
debug ("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ", rio_table_ptr->ver_num, rio_table_ptr->scal_count, rio_table_ptr->riodev_count, rio_table_ptr->offset); debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",
rio_table_ptr->ver_num, rio_table_ptr->scal_count,
rio_table_ptr->riodev_count, rio_table_ptr->offset);
rio_complete = 1; rio_complete = 1;
} }
} }
if (!hs_complete && !rio_complete) { if (!hs_complete && !rio_complete)
iounmap (io_mem); goto error_nodev;
return -ENODEV;
}
if (rio_table_ptr) { if (rio_table_ptr) {
if (rio_complete == 1 && rio_table_ptr->ver_num == 3) { if (rio_complete && rio_table_ptr->ver_num == 3) {
rc = ebda_rio_table (); rc = ebda_rio_table ();
if (rc) { if (rc)
iounmap (io_mem); goto out;
return rc;
}
} }
} }
rc = ebda_rsrc_controller (); rc = ebda_rsrc_controller ();
if (rc) { if (rc)
iounmap (io_mem); goto out;
return rc;
}
rc = ebda_rsrc_rsrc (); rc = ebda_rsrc_rsrc ();
if (rc) { goto out;
iounmap (io_mem); error_nodev:
return rc; rc = -ENODEV;
} out:
iounmap (io_mem); iounmap (io_mem);
return 0; return rc;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment