Skip to content

Commit

Permalink
ehea: Fix mem allocations which require page alignment
Browse files Browse the repository at this point in the history
PAGE_SIZE allocations via slab are not guaranteed to be page-aligned. Fixed
all memory allocations where page alignment is required by firmware.

Signed-off-by: Thomas Klein <tklein@de.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Thomas Klein authored and David S. Miller committed Jan 21, 2009
1 parent 086c1b2 commit 3faf269
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
56 changes: 28 additions & 28 deletions drivers/net/ehea/ehea_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)

memset(stats, 0, sizeof(*stats));

cb2 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
cb2 = (void *)get_zeroed_page(GFP_ATOMIC);
if (!cb2) {
ehea_error("no mem for cb2");
goto out;
Expand Down Expand Up @@ -341,7 +341,7 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)
stats->rx_packets = rx_packets;

out_herr:
kfree(cb2);
free_page((unsigned long)cb2);
out:
return stats;
}
Expand Down Expand Up @@ -915,7 +915,7 @@ int ehea_sense_port_attr(struct ehea_port *port)
struct hcp_ehea_port_cb0 *cb0;

/* may be called via ehea_neq_tasklet() */
cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
if (!cb0) {
ehea_error("no mem for cb0");
ret = -ENOMEM;
Expand Down Expand Up @@ -996,7 +996,7 @@ int ehea_sense_port_attr(struct ehea_port *port)
out_free:
if (ret || netif_msg_probe(port))
ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
kfree(cb0);
free_page((unsigned long)cb0);
out:
return ret;
}
Expand All @@ -1007,7 +1007,7 @@ int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
u64 hret;
int ret = 0;

cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb4 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb4) {
ehea_error("no mem for cb4");
ret = -ENOMEM;
Expand Down Expand Up @@ -1075,7 +1075,7 @@ int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
netif_carrier_on(port->netdev);

kfree(cb4);
free_page((unsigned long)cb4);
out:
return ret;
}
Expand Down Expand Up @@ -1302,7 +1302,7 @@ static int ehea_configure_port(struct ehea_port *port)
struct hcp_ehea_port_cb0 *cb0;

ret = -ENOMEM;
cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb0 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb0)
goto out;

Expand Down Expand Up @@ -1338,7 +1338,7 @@ static int ehea_configure_port(struct ehea_port *port)
ret = 0;

out_free:
kfree(cb0);
free_page((unsigned long)cb0);
out:
return ret;
}
Expand Down Expand Up @@ -1748,7 +1748,7 @@ static int ehea_set_mac_addr(struct net_device *dev, void *sa)
goto out;
}

cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb0 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb0) {
ehea_error("no mem for cb0");
ret = -ENOMEM;
Expand Down Expand Up @@ -1793,7 +1793,7 @@ static int ehea_set_mac_addr(struct net_device *dev, void *sa)
ehea_update_bcmc_registrations();
spin_unlock(&ehea_bcmc_regs.lock);
out_free:
kfree(cb0);
free_page((unsigned long)cb0);
out:
return ret;
}
Expand All @@ -1817,7 +1817,7 @@ static void ehea_promiscuous(struct net_device *dev, int enable)
if ((enable && port->promisc) || (!enable && !port->promisc))
return;

cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
if (!cb7) {
ehea_error("no mem for cb7");
goto out;
Expand All @@ -1836,7 +1836,7 @@ static void ehea_promiscuous(struct net_device *dev, int enable)

port->promisc = enable;
out:
kfree(cb7);
free_page((unsigned long)cb7);
return;
}

Expand Down Expand Up @@ -2217,7 +2217,7 @@ static void ehea_vlan_rx_register(struct net_device *dev,

port->vgrp = grp;

cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb1 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb1) {
ehea_error("no mem for cb1");
goto out;
Expand All @@ -2228,7 +2228,7 @@ static void ehea_vlan_rx_register(struct net_device *dev,
if (hret != H_SUCCESS)
ehea_error("modify_ehea_port failed");

kfree(cb1);
free_page((unsigned long)cb1);
out:
return;
}
Expand All @@ -2241,7 +2241,7 @@ static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
int index;
u64 hret;

cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb1 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb1) {
ehea_error("no mem for cb1");
goto out;
Expand All @@ -2262,7 +2262,7 @@ static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
if (hret != H_SUCCESS)
ehea_error("modify_ehea_port failed");
out:
kfree(cb1);
free_page((unsigned long)cb1);
return;
}

Expand All @@ -2276,7 +2276,7 @@ static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)

vlan_group_set_device(port->vgrp, vid, NULL);

cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb1 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb1) {
ehea_error("no mem for cb1");
goto out;
Expand All @@ -2297,7 +2297,7 @@ static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
if (hret != H_SUCCESS)
ehea_error("modify_ehea_port failed");
out:
kfree(cb1);
free_page((unsigned long)cb1);
return;
}

Expand All @@ -2309,7 +2309,7 @@ int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
u64 dummy64 = 0;
struct hcp_modify_qp_cb0 *cb0;

cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb0 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb0) {
ret = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2372,7 +2372,7 @@ int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)

ret = 0;
out:
kfree(cb0);
free_page((unsigned long)cb0);
return ret;
}

Expand Down Expand Up @@ -2664,7 +2664,7 @@ int ehea_stop_qps(struct net_device *dev)
u64 dummy64 = 0;
u16 dummy16 = 0;

cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb0 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb0) {
ret = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2716,7 +2716,7 @@ int ehea_stop_qps(struct net_device *dev)

ret = 0;
out:
kfree(cb0);
free_page((unsigned long)cb0);

return ret;
}
Expand Down Expand Up @@ -2766,7 +2766,7 @@ int ehea_restart_qps(struct net_device *dev)
u64 dummy64 = 0;
u16 dummy16 = 0;

cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb0 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb0) {
ret = -ENOMEM;
goto out;
Expand Down Expand Up @@ -2819,7 +2819,7 @@ int ehea_restart_qps(struct net_device *dev)
ehea_refill_rq3(pr, 0);
}
out:
kfree(cb0);
free_page((unsigned long)cb0);

return ret;
}
Expand Down Expand Up @@ -2950,7 +2950,7 @@ int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
u64 hret;
int ret;

cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb) {
ret = -ENOMEM;
goto out;
Expand All @@ -2967,7 +2967,7 @@ int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
ret = 0;

out_herr:
kfree(cb);
free_page((unsigned long)cb);
out:
return ret;
}
Expand All @@ -2981,7 +2981,7 @@ int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
*jumbo = 0;

/* (Try to) enable *jumbo frames */
cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
cb4 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb4) {
ehea_error("no mem for cb4");
ret = -ENOMEM;
Expand Down Expand Up @@ -3009,7 +3009,7 @@ int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
} else
ret = -EINVAL;

kfree(cb4);
free_page((unsigned long)cb4);
}
out:
return ret;
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ehea/ehea_qmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle)
unsigned long ret;
u64 *rblock;

rblock = kzalloc(PAGE_SIZE, GFP_KERNEL);
rblock = (void *)get_zeroed_page(GFP_KERNEL);
if (!rblock) {
ehea_error("Cannot allocate rblock memory.");
return;
Expand All @@ -1022,5 +1022,5 @@ void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle)
else
ehea_error("Error data could not be fetched: %llX", res_handle);

kfree(rblock);
free_page((unsigned long)rblock);
}

0 comments on commit 3faf269

Please sign in to comment.