Commit 37a4065e authored by Sven Eckelmann's avatar Sven Eckelmann

batman-adv: Only use int up and down gw representation

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: default avatarSven Eckelmann <sven@narfation.org>
parent 747e4221
...@@ -76,10 +76,11 @@ void gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *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, static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
long *up, long *down) int *up, int *down)
{ {
int ret, multi = 1; int ret, multi = 1;
char *slash_ptr, *tmp_ptr; char *slash_ptr, *tmp_ptr;
long ldown, lup;
slash_ptr = strchr(buff, '/'); slash_ptr = strchr(buff, '/');
if (slash_ptr) if (slash_ptr)
...@@ -96,7 +97,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, ...@@ -96,7 +97,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
*tmp_ptr = '\0'; *tmp_ptr = '\0';
} }
ret = strict_strtoul(buff, 10, down); ret = strict_strtoul(buff, 10, &ldown);
if (ret) { if (ret) {
bat_err(net_dev, bat_err(net_dev,
"Download speed of gateway mode invalid: %s\n", "Download speed of gateway mode invalid: %s\n",
...@@ -104,7 +105,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, ...@@ -104,7 +105,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
return false; return false;
} }
*down *= multi; *down = ldown * multi;
/* we also got some upload info */ /* we also got some upload info */
if (slash_ptr) { if (slash_ptr) {
...@@ -121,7 +122,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, ...@@ -121,7 +122,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
*tmp_ptr = '\0'; *tmp_ptr = '\0';
} }
ret = strict_strtoul(slash_ptr + 1, 10, up); ret = strict_strtoul(slash_ptr + 1, 10, &lup);
if (ret) { if (ret) {
bat_err(net_dev, bat_err(net_dev,
"Upload speed of gateway mode invalid: " "Upload speed of gateway mode invalid: "
...@@ -129,7 +130,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, ...@@ -129,7 +130,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
return false; return false;
} }
*up *= multi; *up = lup * multi;
} }
return true; return true;
...@@ -138,7 +139,8 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, ...@@ -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) ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count)
{ {
struct bat_priv *bat_priv = netdev_priv(net_dev); 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; bool ret;
ret = parse_gw_bandwidth(net_dev, buff, &up, &down); ret = parse_gw_bandwidth(net_dev, buff, &up, &down);
...@@ -158,12 +160,11 @@ ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count) ...@@ -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 * speeds, hence we need to calculate it back to show the number
* that is going to be propagated * that is going to be propagated
**/ **/
gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, &down, &up);
(int *)&down, (int *)&up);
gw_deselect(bat_priv); gw_deselect(bat_priv);
bat_info(net_dev, "Changing gateway bandwidth from: '%i' to: '%ld' " 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, atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp,
(down > 2048 ? down / 1024 : down), (down > 2048 ? down / 1024 : down),
(down > 2048 ? "MBit" : "KBit"), (down > 2048 ? "MBit" : "KBit"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment