Skip to content

Commit

Permalink
ehea: fix mutex and spinlock use
Browse files Browse the repository at this point in the history
  Looks like to me that the ehea_fw_handles.lock mutex and the
ehea_bcmc_regs.lock spinlock are taken much longer than necessary and could
as well be pushed inside the functions that need them
(ehea_update_firmware_handles() and ehea_update_bcmc_registrations())
rather than at each callsite.

Signed-off-by: Sebastien Dugue <sebastien.dugue@bull.net>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
  • Loading branch information
Sebastien Dugue authored and Jeff Garzik committed Sep 24, 2008
1 parent d100ba3 commit 2eefbd6
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions drivers/net/ehea/ehea_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ static void ehea_update_firmware_handles(void)
}

out_update:
mutex_lock(&ehea_fw_handles.lock);
kfree(ehea_fw_handles.arr);
ehea_fw_handles.arr = arr;
ehea_fw_handles.num_entries = i;
mutex_unlock(&ehea_fw_handles.lock);
}

static void ehea_update_bcmc_registrations(void)
Expand Down Expand Up @@ -293,9 +295,11 @@ static void ehea_update_bcmc_registrations(void)
}

out_update:
spin_lock(&ehea_bcmc_regs.lock);
kfree(ehea_bcmc_regs.arr);
ehea_bcmc_regs.arr = arr;
ehea_bcmc_regs.num_entries = i;
spin_unlock(&ehea_bcmc_regs.lock);
}

static struct net_device_stats *ehea_get_stats(struct net_device *dev)
Expand Down Expand Up @@ -1770,8 +1774,6 @@ static int ehea_set_mac_addr(struct net_device *dev, void *sa)

memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);

spin_lock(&ehea_bcmc_regs.lock);

/* Deregister old MAC in pHYP */
if (port->state == EHEA_PORT_UP) {
ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
Expand All @@ -1792,7 +1794,6 @@ static int ehea_set_mac_addr(struct net_device *dev, void *sa)

out_upregs:
ehea_update_bcmc_registrations();
spin_unlock(&ehea_bcmc_regs.lock);
out_free:
kfree(cb0);
out:
Expand Down Expand Up @@ -1954,8 +1955,6 @@ static void ehea_set_multicast_list(struct net_device *dev)
}
ehea_promiscuous(dev, 0);

spin_lock(&ehea_bcmc_regs.lock);

if (dev->flags & IFF_ALLMULTI) {
ehea_allmulti(dev, 1);
goto out;
Expand Down Expand Up @@ -1985,7 +1984,6 @@ static void ehea_set_multicast_list(struct net_device *dev)
}
out:
ehea_update_bcmc_registrations();
spin_unlock(&ehea_bcmc_regs.lock);
return;
}

Expand Down Expand Up @@ -2466,8 +2464,6 @@ static int ehea_up(struct net_device *dev)
if (port->state == EHEA_PORT_UP)
return 0;

mutex_lock(&ehea_fw_handles.lock);

ret = ehea_port_res_setup(port, port->num_def_qps,
port->num_add_tx_qps);
if (ret) {
Expand Down Expand Up @@ -2504,8 +2500,6 @@ static int ehea_up(struct net_device *dev)
}
}

spin_lock(&ehea_bcmc_regs.lock);

ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
if (ret) {
ret = -EIO;
Expand All @@ -2527,10 +2521,8 @@ static int ehea_up(struct net_device *dev)
ehea_info("Failed starting %s. ret=%i", dev->name, ret);

ehea_update_bcmc_registrations();
spin_unlock(&ehea_bcmc_regs.lock);

ehea_update_firmware_handles();
mutex_unlock(&ehea_fw_handles.lock);

return ret;
}
Expand Down Expand Up @@ -2580,9 +2572,6 @@ static int ehea_down(struct net_device *dev)
if (port->state == EHEA_PORT_DOWN)
return 0;

mutex_lock(&ehea_fw_handles.lock);

spin_lock(&ehea_bcmc_regs.lock);
ehea_drop_multicast_list(dev);
ehea_broadcast_reg_helper(port, H_DEREG_BCMC);

Expand All @@ -2591,15 +2580,13 @@ static int ehea_down(struct net_device *dev)
port->state = EHEA_PORT_DOWN;

ehea_update_bcmc_registrations();
spin_unlock(&ehea_bcmc_regs.lock);

ret = ehea_clean_all_portres(port);
if (ret)
ehea_info("Failed freeing resources for %s. ret=%i",
dev->name, ret);

ehea_update_firmware_handles();
mutex_unlock(&ehea_fw_handles.lock);

return ret;
}
Expand Down Expand Up @@ -3378,7 +3365,6 @@ static int __devinit ehea_probe_adapter(struct of_device *dev,
ehea_error("Invalid ibmebus device probed");
return -EINVAL;
}
mutex_lock(&ehea_fw_handles.lock);

adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
if (!adapter) {
Expand Down Expand Up @@ -3462,7 +3448,6 @@ static int __devinit ehea_probe_adapter(struct of_device *dev,

out:
ehea_update_firmware_handles();
mutex_unlock(&ehea_fw_handles.lock);
return ret;
}

Expand All @@ -3481,8 +3466,6 @@ static int __devexit ehea_remove(struct of_device *dev)

flush_scheduled_work();

mutex_lock(&ehea_fw_handles.lock);

ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
tasklet_kill(&adapter->neq_tasklet);

Expand All @@ -3492,7 +3475,6 @@ static int __devexit ehea_remove(struct of_device *dev)
kfree(adapter);

ehea_update_firmware_handles();
mutex_unlock(&ehea_fw_handles.lock);

return 0;
}
Expand Down

0 comments on commit 2eefbd6

Please sign in to comment.