Commit 55b0d6dd authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Deepak Saxena

[PATCH] PCI Hotplug: Remove type magic from kmalloc

This patch removes the cast of kmalloc's results to the target pointer type.
Also it fixes kmalloc to use sizeof(*foo) instead of sizeof(type_of_foo) as
suggested by Matthew Wilcox. Also removes a few useless checks if a pointer
is NULL before calling kfree: kfree checks this itself.
parent 720c494e
...@@ -738,7 +738,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -738,7 +738,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
pci_bus_read_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, &secondary_bus); pci_bus_read_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, &secondary_bus);
pci_bus_read_config_byte(pci_bus, devfn, PCI_SUBORDINATE_BUS, &temp_byte); pci_bus_read_config_byte(pci_bus, devfn, PCI_SUBORDINATE_BUS, &temp_byte);
bus_node =(struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); bus_node = kmalloc(sizeof(*bus_node), GFP_KERNEL);
if (!bus_node) if (!bus_node)
return -ENOMEM; return -ENOMEM;
...@@ -753,7 +753,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -753,7 +753,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
pci_bus_read_config_byte(pci_bus, devfn, PCI_IO_LIMIT, &b_length); pci_bus_read_config_byte(pci_bus, devfn, PCI_IO_LIMIT, &b_length);
if ((b_base <= b_length) && (save_command & 0x01)) { if ((b_base <= b_length) && (save_command & 0x01)) {
io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); io_node = kmalloc(sizeof(*io_node), GFP_KERNEL);
if (!io_node) if (!io_node)
return -ENOMEM; return -ENOMEM;
...@@ -769,7 +769,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -769,7 +769,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
pci_bus_read_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, &w_length); pci_bus_read_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, &w_length);
if ((w_base <= w_length) && (save_command & 0x02)) { if ((w_base <= w_length) && (save_command & 0x02)) {
mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); mem_node = kmalloc(sizeof(*mem_node), GFP_KERNEL);
if (!mem_node) if (!mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -785,7 +785,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -785,7 +785,7 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
pci_bus_read_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, &w_length); pci_bus_read_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, &w_length);
if ((w_base <= w_length) && (save_command & 0x02)) { if ((w_base <= w_length) && (save_command & 0x02)) {
p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); p_mem_node = kmalloc(sizeof(*p_mem_node), GFP_KERNEL);
if (!p_mem_node) if (!p_mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -813,7 +813,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -813,7 +813,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFFE; temp_register = base & 0xFFFFFFFE;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); io_node = kmalloc(sizeof(*io_node),
GFP_KERNEL);
if (!io_node) if (!io_node)
return -ENOMEM; return -ENOMEM;
...@@ -830,7 +831,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -830,7 +831,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFF0; temp_register = base & 0xFFFFFFF0;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); p_mem_node = kmalloc(sizeof(*p_mem_node),
GFP_KERNEL);
if (!p_mem_node) if (!p_mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -846,7 +848,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -846,7 +848,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFF0; temp_register = base & 0xFFFFFFF0;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); mem_node = kmalloc(sizeof(*mem_node),
GFP_KERNEL);
if (!mem_node) if (!mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -878,7 +881,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -878,7 +881,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFFE; temp_register = base & 0xFFFFFFFE;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); io_node = kmalloc(sizeof(*io_node),
GFP_KERNEL);
if (!io_node) if (!io_node)
return -ENOMEM; return -ENOMEM;
...@@ -894,7 +898,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -894,7 +898,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFF0; temp_register = base & 0xFFFFFFF0;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); p_mem_node = kmalloc(sizeof(*p_mem_node),
GFP_KERNEL);
if (!p_mem_node) if (!p_mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -910,7 +915,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func) ...@@ -910,7 +915,8 @@ int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
temp_register = base & 0xFFFFFFF0; temp_register = base & 0xFFFFFFF0;
temp_register = (~temp_register) + 1; temp_register = (~temp_register) + 1;
mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); mem_node = kmalloc(sizeof(*mem_node),
GFP_KERNEL);
if (!mem_node) if (!mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -1293,7 +1299,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start) ...@@ -1293,7 +1299,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start)
temp_dword = io_base + io_length; temp_dword = io_base + io_length;
if ((io_base) && (temp_dword < 0x10000)) { if ((io_base) && (temp_dword < 0x10000)) {
io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); io_node = kmalloc(sizeof(*io_node), GFP_KERNEL);
if (!io_node) if (!io_node)
return -ENOMEM; return -ENOMEM;
...@@ -1315,7 +1321,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start) ...@@ -1315,7 +1321,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start)
// If we've got a valid memory base, use it // If we've got a valid memory base, use it
temp_dword = mem_base + mem_length; temp_dword = mem_base + mem_length;
if ((mem_base) && (temp_dword < 0x10000)) { if ((mem_base) && (temp_dword < 0x10000)) {
mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); mem_node = kmalloc(sizeof(*mem_node), GFP_KERNEL);
if (!mem_node) if (!mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -1339,7 +1345,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start) ...@@ -1339,7 +1345,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start)
// the base + length isn't greater than 0xFFFF // the base + length isn't greater than 0xFFFF
temp_dword = pre_mem_base + pre_mem_length; temp_dword = pre_mem_base + pre_mem_length;
if ((pre_mem_base) && (temp_dword < 0x10000)) { if ((pre_mem_base) && (temp_dword < 0x10000)) {
p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); p_mem_node = kmalloc(sizeof(*p_mem_node), GFP_KERNEL);
if (!p_mem_node) if (!p_mem_node)
return -ENOMEM; return -ENOMEM;
...@@ -1363,7 +1369,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start) ...@@ -1363,7 +1369,7 @@ int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start)
// The second condition is to ignore bus numbers on // The second condition is to ignore bus numbers on
// populated slots that don't have PCI-PCI bridges // populated slots that don't have PCI-PCI bridges
if (secondary_bus && (secondary_bus != primary_bus)) { if (secondary_bus && (secondary_bus != primary_bus)) {
bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); bus_node = kmalloc(sizeof(*bus_mode), GFP_KERNEL);
if (!bus_node) if (!bus_node)
return -ENOMEM; return -ENOMEM;
......
...@@ -396,7 +396,7 @@ static struct pci_resource *do_pre_bridge_resource_split (struct pci_resource ** ...@@ -396,7 +396,7 @@ static struct pci_resource *do_pre_bridge_resource_split (struct pci_resource **
/* This one isn't an aligned length, so we'll make a new entry /* This one isn't an aligned length, so we'll make a new entry
* and split it up. * and split it up.
*/ */
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -530,7 +530,7 @@ static struct pci_resource *get_io_resource (struct pci_resource **head, u32 siz ...@@ -530,7 +530,7 @@ static struct pci_resource *get_io_resource (struct pci_resource **head, u32 siz
if ((node->length - (temp_dword - node->base)) < size) if ((node->length - (temp_dword - node->base)) < size)
continue; continue;
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -549,7 +549,7 @@ static struct pci_resource *get_io_resource (struct pci_resource **head, u32 siz ...@@ -549,7 +549,7 @@ static struct pci_resource *get_io_resource (struct pci_resource **head, u32 siz
if (node->length > size) { if (node->length > size) {
/* This one is longer than we need /* This one is longer than we need
so we'll make a new entry and split it up */ so we'll make a new entry and split it up */
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -630,7 +630,7 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si ...@@ -630,7 +630,7 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si
if ((max->length - (temp_dword - max->base)) < size) if ((max->length - (temp_dword - max->base)) < size)
continue; continue;
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -648,7 +648,7 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si ...@@ -648,7 +648,7 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si
if ((max->base + max->length) & (size - 1)) { if ((max->base + max->length) & (size - 1)) {
/* This one isn't end aligned properly at the top /* This one isn't end aligned properly at the top
so we'll make a new entry and split it up */ so we'll make a new entry and split it up */
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -669,7 +669,8 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si ...@@ -669,7 +669,8 @@ static struct pci_resource *get_max_resource (struct pci_resource **head, u32 si
for ( i = 0; max_size[i] > size; i++) { for ( i = 0; max_size[i] > size; i++) {
if (max->length > max_size[i]) { if (max->length > max_size[i]) {
split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node),
GFP_KERNEL);
if (!split_node) if (!split_node)
break; /* return (NULL); */ break; /* return (NULL); */
split_node->base = max->base + max_size[i]; split_node->base = max->base + max_size[i];
...@@ -744,7 +745,7 @@ static struct pci_resource *get_resource (struct pci_resource **head, u32 size) ...@@ -744,7 +745,7 @@ static struct pci_resource *get_resource (struct pci_resource **head, u32 size)
if ((node->length - (temp_dword - node->base)) < size) if ((node->length - (temp_dword - node->base)) < size)
continue; continue;
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -764,7 +765,7 @@ static struct pci_resource *get_resource (struct pci_resource **head, u32 size) ...@@ -764,7 +765,7 @@ static struct pci_resource *get_resource (struct pci_resource **head, u32 size)
dbg("%s: too big\n", __FUNCTION__); dbg("%s: too big\n", __FUNCTION__);
/* this one is longer than we need /* this one is longer than we need
so we'll make a new entry and split it up */ so we'll make a new entry and split it up */
split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
if (!split_node) if (!split_node)
return(NULL); return(NULL);
...@@ -882,7 +883,7 @@ struct pci_func *shpchp_slot_create(u8 busnumber) ...@@ -882,7 +883,7 @@ struct pci_func *shpchp_slot_create(u8 busnumber)
struct pci_func *new_slot; struct pci_func *new_slot;
struct pci_func *next; struct pci_func *next;
new_slot = (struct pci_func *) kmalloc(sizeof(struct pci_func), GFP_KERNEL); new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
if (new_slot == NULL) { if (new_slot == NULL) {
return(new_slot); return(new_slot);
...@@ -1856,7 +1857,7 @@ static int update_slot_info (struct slot *slot) ...@@ -1856,7 +1857,7 @@ static int update_slot_info (struct slot *slot)
struct hotplug_slot_info *info; struct hotplug_slot_info *info;
int result; int result;
info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
...@@ -2504,20 +2505,16 @@ static int configure_new_function (struct controller * ctrl, struct pci_func * f ...@@ -2504,20 +2505,16 @@ static int configure_new_function (struct controller * ctrl, struct pci_func * f
/* Make copies of the nodes we are going to pass down so that /* Make copies of the nodes we are going to pass down so that
* if there is a problem,we can just use these to free resources * if there is a problem,we can just use these to free resources
*/ */
hold_bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL);
hold_IO_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL);
hold_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); hold_mem_node = kmalloc(sizeof(*hold_mem_node), GFP_KERNEL);
hold_p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); hold_p_mem_node = kmalloc(sizeof(*hold_p_mem_node), GFP_KERNEL);
if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) { if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
if (hold_bus_node) kfree(hold_bus_node);
kfree(hold_bus_node); kfree(hold_IO_node);
if (hold_IO_node) kfree(hold_mem_node);
kfree(hold_IO_node); kfree(hold_p_mem_node);
if (hold_mem_node)
kfree(hold_mem_node);
if (hold_p_mem_node)
kfree(hold_p_mem_node);
return(1); return(1);
} }
......
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