Skip to content

Commit

Permalink
PCI: Remove assignment from "if" conditions
Browse files Browse the repository at this point in the history
The following Coccinelle semantic patch was used to find and correct cases
of assignments in "if" conditions:

@@
expression var, expr;
statement S;
@@

+ var = expr;
  if(
- (var = expr)
+ var
  ) S

Signed-off-by: Quentin Lambert <lambert.quentin@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Quentin Lambert authored and Bjorn Helgaas committed Sep 24, 2014
1 parent 656f978 commit 79e50e7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 30 deletions.
3 changes: 2 additions & 1 deletion drivers/pci/hotplug/acpi_pcihp.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle)
{
acpi_handle bridge_handle, parent_handle;

if (!(bridge_handle = acpi_pci_get_bridge_handle(pbus)))
bridge_handle = acpi_pci_get_bridge_handle(pbus);
if (!bridge_handle)
return 0;
if ((ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))))
return 0;
Expand Down
9 changes: 6 additions & 3 deletions drivers/pci/hotplug/cpci_hotplug_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ disable_slot(struct hotplug_slot *hotplug_slot)

/* Unconfigure device */
dbg("%s - unconfiguring slot %s", __func__, slot_name(slot));
if ((retval = cpci_unconfigure_slot(slot))) {
retval = cpci_unconfigure_slot(slot);
if (retval) {
err("%s - could not unconfigure slot %s",
__func__, slot_name(slot));
goto disable_error;
Expand All @@ -141,9 +142,11 @@ disable_slot(struct hotplug_slot *hotplug_slot)
}
cpci_led_on(slot);

if (controller->ops->set_power)
if ((retval = controller->ops->set_power(slot, 0)))
if (controller->ops->set_power) {
retval = controller->ops->set_power(slot, 0);
if (retval)
goto disable_error;
}

if (update_adapter_status(slot->hotplug_slot, 0))
warn("failure to update adapter file");
Expand Down
5 changes: 3 additions & 2 deletions drivers/pci/hotplug/cpcihp_zt5550.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
dbg("registered controller");

/* Look for first device matching cPCI bus's bridge vendor and device IDs */
if (!(bus0_dev = pci_get_device(PCI_VENDOR_ID_DEC,
PCI_DEVICE_ID_DEC_21154, NULL))) {
bus0_dev = pci_get_device(PCI_VENDOR_ID_DEC,
PCI_DEVICE_ID_DEC_21154, NULL);
if (!bus0_dev) {
status = -ENODEV;
goto init_register_error;
}
Expand Down
15 changes: 10 additions & 5 deletions drivers/pci/hotplug/ibmphp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ static int enable_slot(struct hotplug_slot *hs)
debug("ENABLING SLOT........\n");
slot_cur = hs->private;

if ((rc = validate(slot_cur, ENABLE))) {
rc = validate(slot_cur, ENABLE);
if (rc) {
err("validate function failed\n");
goto error_nopower;
}
Expand Down Expand Up @@ -1335,17 +1336,20 @@ static int __init ibmphp_init(void)
for (i = 0; i < 16; i++)
irqs[i] = 0;

if ((rc = ibmphp_access_ebda()))
rc = ibmphp_access_ebda();
if (rc)
goto error;
debug("after ibmphp_access_ebda()\n");

if ((rc = ibmphp_rsrc_init()))
rc = ibmphp_rsrc_init();
if (rc)
goto error;
debug("AFTER Resource & EBDA INITIALIZATIONS\n");

max_slots = get_max_slots();

if ((rc = ibmphp_register_pci()))
rc = ibmphp_register_pci();
if (rc)
goto error;

if (init_ops()) {
Expand All @@ -1354,7 +1358,8 @@ static int __init ibmphp_init(void)
}

ibmphp_print_test();
if ((rc = ibmphp_hpc_start_poll_thread()))
rc = ibmphp_hpc_start_poll_thread();
if (rc)
goto error;

exit:
Expand Down
6 changes: 4 additions & 2 deletions drivers/pci/hotplug/ibmphp_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
case PCI_HEADER_TYPE_NORMAL:
debug ("single device case.... vendor id = %x, hdr_type = %x, class = %x\n", vendor_id, hdr_type, class);
assign_alt_irq (cur_func, class_code);
if ((rc = configure_device (cur_func)) < 0) {
rc = configure_device(cur_func);
if (rc < 0) {
/* We need to do this in case some other BARs were properly inserted */
err ("was not able to configure devfunc %x on bus %x.\n",
cur_func->device, cur_func->busno);
Expand All @@ -157,7 +158,8 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
break;
case PCI_HEADER_TYPE_MULTIDEVICE:
assign_alt_irq (cur_func, class_code);
if ((rc = configure_device (cur_func)) < 0) {
rc = configure_device(cur_func);
if (rc < 0) {
/* We need to do this in case some other BARs were properly inserted */
err ("was not able to configure devfunc %x on bus %x...bailing out\n",
cur_func->device, cur_func->busno);
Expand Down
30 changes: 21 additions & 9 deletions drivers/pci/hotplug/ibmphp_res.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ int __init ibmphp_rsrc_init (void)
if ((curr->rsrc_type & RESTYPE) == MMASK) {
/* no bus structure exists in place yet */
if (list_empty (&gbuses)) {
if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, MEM, 1);
if (rc)
return rc;
list_add_tail (&newbus->bus_list, &gbuses);
debug ("gbuses = NULL, Memory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
Expand All @@ -237,7 +238,8 @@ int __init ibmphp_rsrc_init (void)
return rc;
} else {
/* went through all the buses and didn't find ours, need to create a new bus node */
if ((rc = alloc_bus_range (&newbus, &newrange, curr, MEM, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, MEM, 1);
if (rc)
return rc;

list_add_tail (&newbus->bus_list, &gbuses);
Expand All @@ -248,7 +250,8 @@ int __init ibmphp_rsrc_init (void)
/* prefetchable memory */
if (list_empty (&gbuses)) {
/* no bus structure exists in place yet */
if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, PFMEM, 1);
if (rc)
return rc;
list_add_tail (&newbus->bus_list, &gbuses);
debug ("gbuses = NULL, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
Expand All @@ -261,7 +264,8 @@ int __init ibmphp_rsrc_init (void)
return rc;
} else {
/* went through all the buses and didn't find ours, need to create a new bus node */
if ((rc = alloc_bus_range (&newbus, &newrange, curr, PFMEM, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, PFMEM, 1);
if (rc)
return rc;
list_add_tail (&newbus->bus_list, &gbuses);
debug ("1st Bus, PFMemory Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
Expand All @@ -271,7 +275,8 @@ int __init ibmphp_rsrc_init (void)
/* IO */
if (list_empty (&gbuses)) {
/* no bus structure exists in place yet */
if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, IO, 1);
if (rc)
return rc;
list_add_tail (&newbus->bus_list, &gbuses);
debug ("gbuses = NULL, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
Expand All @@ -283,7 +288,8 @@ int __init ibmphp_rsrc_init (void)
return rc;
} else {
/* went through all the buses and didn't find ours, need to create a new bus node */
if ((rc = alloc_bus_range (&newbus, &newrange, curr, IO, 1)))
rc = alloc_bus_range(&newbus, &newrange, curr, IO, 1);
if (rc)
return rc;
list_add_tail (&newbus->bus_list, &gbuses);
debug ("1st Bus, IO Primary Bus %x [%x - %x]\n", newbus->busno, newrange->start, newrange->end);
Expand Down Expand Up @@ -1153,7 +1159,9 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
}
} else {
/* in the same range */
if ((len_tmp = res_cur->start - 1 - res_prev->end - 1) >= res->len) {
len_tmp = res_cur->start - 1 - res_prev->end - 1;

if (len_tmp >= res->len) {
if ((len_tmp < len_cur) || (len_cur == 0)) {
if (((res_prev->end + 1) % tmp_divide) == 0) {
/* just perfect, starting address's divisible by length */
Expand Down Expand Up @@ -1212,7 +1220,9 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
break;
}
while (range) {
if ((len_tmp = range->end - range->start) >= res->len) {
len_tmp = range->end - range->start;

if (len_tmp >= res->len) {
if ((len_tmp < len_cur) || (len_cur == 0)) {
if ((range->start % tmp_divide) == 0) {
/* just perfect, starting address's divisible by length */
Expand Down Expand Up @@ -1276,7 +1286,9 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
break;
}
while (range) {
if ((len_tmp = range->end - range->start) >= res->len) {
len_tmp = range->end - range->start;

if (len_tmp >= res->len) {
if ((len_tmp < len_cur) || (len_cur == 0)) {
if ((range->start % tmp_divide) == 0) {
/* just perfect, starting address's divisible by length */
Expand Down
12 changes: 8 additions & 4 deletions drivers/pci/hotplug/shpchp_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ static int change_bus_speed(struct controller *ctrl, struct slot *p_slot,
int rc = 0;

ctrl_dbg(ctrl, "Change speed to %d\n", speed);
if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed);
if (rc) {
ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n",
__func__);
return WRONG_BUS_FREQUENCY;
Expand Down Expand Up @@ -261,14 +262,16 @@ static int board_added(struct slot *p_slot)
}

if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz);
if (rc) {
ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n",
__func__);
return WRONG_BUS_FREQUENCY;
}

/* turn on board, blink green LED, turn off Amber LED */
if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
rc = p_slot->hpc_ops->slot_enable(p_slot);
if (rc) {
ctrl_err(ctrl, "Issue of Slot Enable command failed\n");
return rc;
}
Expand Down Expand Up @@ -296,7 +299,8 @@ static int board_added(struct slot *p_slot)
return rc;

/* turn on board, blink green LED, turn off Amber LED */
if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
rc = p_slot->hpc_ops->slot_enable(p_slot);
if (rc) {
ctrl_err(ctrl, "Issue of Slot Enable command failed\n");
return rc;
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/pci/hotplug/shpchp_hpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
u8 m66_cap = !!(slot_reg & MHZ66_CAP);
u8 pi, pcix_cap;

if ((retval = hpc_get_prog_int(slot, &pi)))
retval = hpc_get_prog_int(slot, &pi);
if (retval)
return retval;

switch (pi) {
Expand Down
13 changes: 10 additions & 3 deletions drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,19 @@ int pci_save_state(struct pci_dev *dev)
for (i = 0; i < 16; i++)
pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]);
dev->state_saved = true;
if ((i = pci_save_pcie_state(dev)) != 0)

i = pci_save_pcie_state(dev);
if (i != 0)
return i;
if ((i = pci_save_pcix_state(dev)) != 0)

i = pci_save_pcix_state(dev);
if (i != 0)
return i;
if ((i = pci_save_vc_state(dev)) != 0)

i = pci_save_vc_state(dev);
if (i != 0)
return i;

return 0;
}
EXPORT_SYMBOL(pci_save_state);
Expand Down

0 comments on commit 79e50e7

Please sign in to comment.