Skip to content

Commit

Permalink
batman-adv: Only use int up and down gw representation
Browse files Browse the repository at this point in the history
It is not save to provide memory for an int and then cast the pointer to
it to long*. It is better to standardize the up and down gateway
bandwith representation to simple ints and only use long inside
conversation routines.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
  • Loading branch information
Sven Eckelmann committed May 30, 2011
1 parent 747e422 commit 37a4065
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions net/batman-adv/gateway_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ void gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up)
}

static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
long *up, long *down)
int *up, int *down)
{
int ret, multi = 1;
char *slash_ptr, *tmp_ptr;
long ldown, lup;

slash_ptr = strchr(buff, '/');
if (slash_ptr)
Expand All @@ -96,15 +97,15 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
*tmp_ptr = '\0';
}

ret = strict_strtoul(buff, 10, down);
ret = strict_strtoul(buff, 10, &ldown);
if (ret) {
bat_err(net_dev,
"Download speed of gateway mode invalid: %s\n",
buff);
return false;
}

*down *= multi;
*down = ldown * multi;

/* we also got some upload info */
if (slash_ptr) {
Expand All @@ -121,15 +122,15 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
*tmp_ptr = '\0';
}

ret = strict_strtoul(slash_ptr + 1, 10, up);
ret = strict_strtoul(slash_ptr + 1, 10, &lup);
if (ret) {
bat_err(net_dev,
"Upload speed of gateway mode invalid: "
"%s\n", slash_ptr + 1);
return false;
}

*up *= multi;
*up = lup * multi;
}

return true;
Expand All @@ -138,7 +139,8 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count)
{
struct bat_priv *bat_priv = netdev_priv(net_dev);
long gw_bandwidth_tmp = 0, up = 0, down = 0;
long gw_bandwidth_tmp = 0;
int up = 0, down = 0;
bool ret;

ret = parse_gw_bandwidth(net_dev, buff, &up, &down);
Expand All @@ -158,12 +160,11 @@ ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count)
* speeds, hence we need to calculate it back to show the number
* that is going to be propagated
**/
gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp,
(int *)&down, (int *)&up);
gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, &down, &up);

gw_deselect(bat_priv);
bat_info(net_dev, "Changing gateway bandwidth from: '%i' to: '%ld' "
"(propagating: %ld%s/%ld%s)\n",
"(propagating: %d%s/%d%s)\n",
atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp,
(down > 2048 ? down / 1024 : down),
(down > 2048 ? "MBit" : "KBit"),
Expand Down

0 comments on commit 37a4065

Please sign in to comment.