Skip to content

Commit

Permalink
staging: wilc1000: refactor handle_set_mcast_filter()
Browse files Browse the repository at this point in the history
Refactor handle_set_mcast_filter() by making use of put_unaligned32() to
pack the data instead of byte operation.

Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ajay Singh authored and Greg Kroah-Hartman committed Jan 18, 2019
1 parent 03cf31c commit a0c6a32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
37 changes: 16 additions & 21 deletions drivers/staging/wilc1000/host_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct wilc_rcvd_mac_info {
u8 status;
};

struct set_multicast {
bool enabled;
struct wilc_set_multicast {
u32 enabled;
u32 cnt;
u8 *mc_list;
};
Expand Down Expand Up @@ -71,7 +71,7 @@ struct wilc_gtk_key {
union message_body {
struct wilc_rcvd_net_info net_info;
struct wilc_rcvd_mac_info mac_info;
struct set_multicast multicast_info;
struct wilc_set_multicast mc_info;
struct remain_ch remain_on_ch;
char *data;
};
Expand Down Expand Up @@ -1067,40 +1067,35 @@ static void handle_set_mcast_filter(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
struct wilc_vif *vif = msg->vif;
struct set_multicast *hif_set_mc = &msg->body.multicast_info;
struct wilc_set_multicast *set_mc = &msg->body.mc_info;
int result;
struct wid wid;
u8 *cur_byte;

wid.id = WID_SETUP_MULTICAST_FILTER;
wid.type = WID_BIN;
wid.size = sizeof(struct set_multicast) + (hif_set_mc->cnt * ETH_ALEN);
wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
wid.val = kmalloc(wid.size, GFP_KERNEL);
if (!wid.val)
goto error;

cur_byte = wid.val;
*cur_byte++ = (hif_set_mc->enabled & 0xFF);
*cur_byte++ = 0;
*cur_byte++ = 0;
*cur_byte++ = 0;
put_unaligned_le32(set_mc->enabled, cur_byte);
cur_byte += 4;

*cur_byte++ = (hif_set_mc->cnt & 0xFF);
*cur_byte++ = ((hif_set_mc->cnt >> 8) & 0xFF);
*cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF);
*cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF);
put_unaligned_le32(set_mc->cnt, cur_byte);
cur_byte += 4;

if (hif_set_mc->cnt > 0 && hif_set_mc->mc_list)
memcpy(cur_byte, hif_set_mc->mc_list,
((hif_set_mc->cnt) * ETH_ALEN));
if (set_mc->cnt > 0 && set_mc->mc_list)
memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);

result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1,
wilc_get_vif_idx(vif));
if (result)
netdev_err(vif->ndev, "Failed to send setup multicast\n");

error:
kfree(hif_set_mc->mc_list);
kfree(set_mc->mc_list);
kfree(wid.val);
kfree(msg);
}
Expand Down Expand Up @@ -2150,7 +2145,7 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
return result;
}

int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
u8 *mc_list)
{
int result;
Expand All @@ -2160,9 +2155,9 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
if (IS_ERR(msg))
return PTR_ERR(msg);

msg->body.multicast_info.enabled = enabled;
msg->body.multicast_info.cnt = count;
msg->body.multicast_info.mc_list = mc_list;
msg->body.mc_info.enabled = enabled;
msg->body.mc_info.cnt = count;
msg->body.mc_info.mc_list = mc_list;

result = wilc_enqueue_work(msg);
if (result) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/wilc1000/host_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr);
int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
struct station_parameters *params);
int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
u8 *mc_list);
int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
u32 duration, u16 chan,
Expand Down
6 changes: 3 additions & 3 deletions drivers/staging/wilc1000/linux_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,12 @@ static void wilc_set_multicast_list(struct net_device *dev)

if (dev->flags & IFF_ALLMULTI ||
dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
wilc_setup_multicast_filter(vif, false, 0, NULL);
wilc_setup_multicast_filter(vif, 0, 0, NULL);
return;
}

if (dev->mc.count == 0) {
wilc_setup_multicast_filter(vif, true, 0, NULL);
wilc_setup_multicast_filter(vif, 1, 0, NULL);
return;
}

Expand All @@ -833,7 +833,7 @@ static void wilc_set_multicast_list(struct net_device *dev)
cur_mc += ETH_ALEN;
}

if (wilc_setup_multicast_filter(vif, true, dev->mc.count, mc_list))
if (wilc_setup_multicast_filter(vif, 1, dev->mc.count, mc_list))
kfree(mc_list);
}

Expand Down

0 comments on commit a0c6a32

Please sign in to comment.