ChangeSet 1.1587.12.51, 2004/04/30 14:48:46-07:00, eike-hotplug@sf-tec.de [PATCH] Compaq PCI Hotplug: kill useless kmalloc casts 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. drivers/pci/hotplug/cpqphp_ctrl.c | 40 +++++++++++++++++--------------------- 1 files changed, 18 insertions(+), 22 deletions(-) diff -Nru a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c --- a/drivers/pci/hotplug/cpqphp_ctrl.c Mon May 17 17:00:45 2004 +++ b/drivers/pci/hotplug/cpqphp_ctrl.c Mon May 17 17:00:45 2004 @@ -454,7 +454,7 @@ if (node->length & (alignment -1)) { /* this one isn't an aligned length, so we'll make a new entry * and split it up. */ - split_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); if (!split_node) return NULL; @@ -582,7 +582,7 @@ if ((node->length - (temp_dword - node->base)) < size) continue; - split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); if (!split_node) return NULL; @@ -601,7 +601,7 @@ if (node->length > size) { /* this one is longer than we need * 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) return NULL; @@ -678,7 +678,7 @@ if ((max->length - (temp_dword - max->base)) < size) continue; - split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); if (!split_node) return NULL; @@ -695,7 +695,7 @@ if ((max->base + max->length) & (size - 1)) { /* this one isn't end aligned properly at the top * so we'll make a new entry and split it up */ - split_node = kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); if (!split_node) return NULL; @@ -776,7 +776,7 @@ if ((node->length - (temp_dword - node->base)) < size) continue; - split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + split_node = kmalloc(sizeof(*split_node), GFP_KERNEL); if (!split_node) return NULL; @@ -795,7 +795,7 @@ dbg("%s: too big\n", __FUNCTION__); /* this one is longer than we need * 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) return NULL; @@ -985,7 +985,7 @@ struct pci_func *new_slot; 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) { /* I'm not dead yet! @@ -1870,7 +1870,7 @@ struct hotplug_slot_info *info; int result; - info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); + info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) return -ENOMEM; @@ -2361,7 +2361,7 @@ * Returns 0 if success * */ -static u32 configure_new_device(struct controller *ctrl, struct pci_func *func, +static u32 configure_new_device(struct controller * ctrl, struct pci_func * func, u8 behind_bridge, struct resource_lists * resources) { u8 temp_byte, function, max_functions, stop_it; @@ -2590,20 +2590,16 @@ /* 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 */ - hold_bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); - hold_IO_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); - hold_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); - hold_p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); + hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL); + hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL); + hold_mem_node = kmalloc(sizeof(*hold_mem_node), 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) - kfree(hold_bus_node); - if (hold_IO_node) - kfree(hold_IO_node); - if (hold_mem_node) - kfree(hold_mem_node); - if (hold_p_mem_node) - kfree(hold_p_mem_node); + kfree(hold_bus_node); + kfree(hold_IO_node); + kfree(hold_mem_node); + kfree(hold_p_mem_node); return 1; }