ChangeSet 1.1587.12.31, 2004/04/30 14:10:12-07:00, eike-hotplug@sf-tec.de [PATCH] Compaq PCI Hotplug: remove useless NULL checks Remove some useless NULL and magic checks from Compaq PCI Hotplug driver. If one of this pointers is invalid we are in bad trouble anyway. drivers/pci/hotplug/cpqphp.h | 48 -------------- drivers/pci/hotplug/cpqphp_core.c | 130 +++++++++----------------------------- drivers/pci/hotplug/cpqphp_ctrl.c | 7 -- 3 files changed, 34 insertions(+), 151 deletions(-) diff -Nru a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h --- a/drivers/pci/hotplug/cpqphp.h Mon May 17 17:02:44 2004 +++ b/drivers/pci/hotplug/cpqphp.h Mon May 17 17:02:44 2004 @@ -257,9 +257,7 @@ struct pci_dev* pci_dev; }; -#define SLOT_MAGIC 0x67267321 struct slot { - u32 magic; struct slot *next; u8 bus; u8 device; @@ -452,40 +450,6 @@ /* inline functions */ - -/* Inline functions to check the sanity of a pointer that is passed to us */ -static inline int slot_paranoia_check (struct slot *slot, const char *function) -{ - if (!slot) { - dbg("%s - slot == NULL", function); - return -1; - } - if (slot->magic != SLOT_MAGIC) { - dbg("%s - bad magic number for slot", function); - return -1; - } - if (!slot->hotplug_slot) { - dbg("%s - slot->hotplug_slot == NULL!", function); - return -1; - } - return 0; -} - -static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function) -{ - struct slot *slot; - - if (!hotplug_slot) { - dbg("%s - hotplug_slot == NULL\n", function); - return NULL; - } - - slot = (struct slot *)hotplug_slot->private; - if (slot_paranoia_check (slot, function)) - return NULL; - return slot; -} - /* * return_resource * @@ -688,9 +652,6 @@ { u8 hp_slot; - if (slot == NULL) - return 1; - hp_slot = slot->device - ctrl->slot_device_offset; return read_amber_LED(ctrl, hp_slot); @@ -701,9 +662,6 @@ { u8 hp_slot; - if (slot == NULL) - return 1; - hp_slot = slot->device - ctrl->slot_device_offset; return is_slot_enabled(ctrl, hp_slot); @@ -715,9 +673,6 @@ u32 status; u8 hp_slot; - if (slot == NULL) - return 1; - hp_slot = slot->device - ctrl->slot_device_offset; dbg("%s: slot->device = %d, ctrl->slot_device_offset = %d \n", __FUNCTION__, slot->device, ctrl->slot_device_offset); @@ -733,9 +688,6 @@ int presence_save = 0; u8 hp_slot; u32 tempdword; - - if (slot == NULL) - return 0; hp_slot = slot->device - ctrl->slot_device_offset; diff -Nru a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c --- a/drivers/pci/hotplug/cpqphp_core.c Mon May 17 17:02:44 2004 +++ b/drivers/pci/hotplug/cpqphp_core.c Mon May 17 17:02:44 2004 @@ -314,7 +314,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; if (slot == NULL) return; @@ -374,7 +374,6 @@ return -ENOMEM; } - new_slot->magic = SLOT_MAGIC; new_slot->ctrl = ctrl; new_slot->bus = ctrl->bus; new_slot->device = slot_device; @@ -600,7 +599,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) { struct pci_func *slot_func; - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; struct controller *ctrl; u8 bus; u8 devfn; @@ -632,25 +631,18 @@ } -static int process_SI (struct hotplug_slot *hotplug_slot) +static int process_SI(struct hotplug_slot *hotplug_slot) { struct pci_func *slot_func; - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; u8 bus; u8 devfn; u8 device; u8 function; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1) return -ENODEV; @@ -672,25 +664,18 @@ } -static int process_SS (struct hotplug_slot *hotplug_slot) +static int process_SS(struct hotplug_slot *hotplug_slot) { struct pci_func *slot_func; - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; u8 bus; u8 devfn; u8 device; u8 function; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1) return -ENODEV; @@ -708,112 +693,70 @@ } -static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value) +static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - if (slot == NULL) - return -ENODEV; - - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - return cpqhp_hardware_test (ctrl, value); } -static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; - + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - *value = get_slot_enabled(ctrl, slot); return 0; } -static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - *value = cpq_get_attention_status(ctrl, slot); return 0; } -static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; - + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - - *value = cpq_get_latch_status (ctrl, slot); + *value = cpq_get_latch_status(ctrl, slot); return 0; } -static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) +static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - - *value = get_presence_status (ctrl, slot); + *value = get_presence_status(ctrl, slot); return 0; } static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - *value = ctrl->speed_capability; return 0; @@ -821,18 +764,11 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); - struct controller *ctrl; - - if (slot == NULL) - return -ENODEV; + struct slot *slot = hotplug_slot->private; + struct controller *ctrl = slot->ctrl; dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); - ctrl = slot->ctrl; - if (ctrl == NULL) - return -ENODEV; - *value = ctrl->speed; return 0; 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:02:44 2004 +++ b/drivers/pci/hotplug/cpqphp_ctrl.c Mon May 17 17:02:44 2004 @@ -143,12 +143,7 @@ */ struct slot *cpqhp_find_slot(struct controller *ctrl, u8 device) { - struct slot *slot; - - if (!ctrl) - return NULL; - - slot = ctrl->slot; + struct slot *slot = ctrl->slot; while (slot && (slot->device != device)) { slot = slot->next;