diff options
author | Sven Eckelmann <sven@narfation.org> | 2011-05-14 17:14:51 -0400 |
---|---|---|
committer | Sven Eckelmann <sven@narfation.org> | 2011-05-30 01:39:32 -0400 |
commit | 37a4065ec79dcf172c44cb2741c1b9983ecfc492 (patch) | |
tree | c147618cee2f3743ab34ae8195da490a7e73c266 /net/batman-adv/gateway_common.c | |
parent | 747e4221a03cde62402b614ca1f8e961b8416130 (diff) |
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: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/gateway_common.c')
-rw-r--r-- | net/batman-adv/gateway_common.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c index 50d3a59a3d73..ed3bd366a2a9 100644 --- a/net/batman-adv/gateway_common.c +++ b/net/batman-adv/gateway_common.c | |||
@@ -76,10 +76,11 @@ void gw_bandwidth_to_kbit(uint8_t gw_srv_class, int *down, int *up) | |||
76 | } | 76 | } |
77 | 77 | ||
78 | static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, | 78 | static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, |
79 | long *up, long *down) | 79 | int *up, int *down) |
80 | { | 80 | { |
81 | int ret, multi = 1; | 81 | int ret, multi = 1; |
82 | char *slash_ptr, *tmp_ptr; | 82 | char *slash_ptr, *tmp_ptr; |
83 | long ldown, lup; | ||
83 | 84 | ||
84 | slash_ptr = strchr(buff, '/'); | 85 | slash_ptr = strchr(buff, '/'); |
85 | if (slash_ptr) | 86 | if (slash_ptr) |
@@ -96,7 +97,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, | |||
96 | *tmp_ptr = '\0'; | 97 | *tmp_ptr = '\0'; |
97 | } | 98 | } |
98 | 99 | ||
99 | ret = strict_strtoul(buff, 10, down); | 100 | ret = strict_strtoul(buff, 10, &ldown); |
100 | if (ret) { | 101 | if (ret) { |
101 | bat_err(net_dev, | 102 | bat_err(net_dev, |
102 | "Download speed of gateway mode invalid: %s\n", | 103 | "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 | return false; | 105 | return false; |
105 | } | 106 | } |
106 | 107 | ||
107 | *down *= multi; | 108 | *down = ldown * multi; |
108 | 109 | ||
109 | /* we also got some upload info */ | 110 | /* we also got some upload info */ |
110 | if (slash_ptr) { | 111 | if (slash_ptr) { |
@@ -121,7 +122,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, | |||
121 | *tmp_ptr = '\0'; | 122 | *tmp_ptr = '\0'; |
122 | } | 123 | } |
123 | 124 | ||
124 | ret = strict_strtoul(slash_ptr + 1, 10, up); | 125 | ret = strict_strtoul(slash_ptr + 1, 10, &lup); |
125 | if (ret) { | 126 | if (ret) { |
126 | bat_err(net_dev, | 127 | bat_err(net_dev, |
127 | "Upload speed of gateway mode invalid: " | 128 | "Upload speed of gateway mode invalid: " |
@@ -129,7 +130,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, | |||
129 | return false; | 130 | return false; |
130 | } | 131 | } |
131 | 132 | ||
132 | *up *= multi; | 133 | *up = lup * multi; |
133 | } | 134 | } |
134 | 135 | ||
135 | return true; | 136 | return true; |
@@ -138,7 +139,8 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff, | |||
138 | ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count) | 139 | ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count) |
139 | { | 140 | { |
140 | struct bat_priv *bat_priv = netdev_priv(net_dev); | 141 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
141 | long gw_bandwidth_tmp = 0, up = 0, down = 0; | 142 | long gw_bandwidth_tmp = 0; |
143 | int up = 0, down = 0; | ||
142 | bool ret; | 144 | bool ret; |
143 | 145 | ||
144 | ret = parse_gw_bandwidth(net_dev, buff, &up, &down); | 146 | 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 | * speeds, hence we need to calculate it back to show the number | 160 | * speeds, hence we need to calculate it back to show the number |
159 | * that is going to be propagated | 161 | * that is going to be propagated |
160 | **/ | 162 | **/ |
161 | gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, | 163 | gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, &down, &up); |
162 | (int *)&down, (int *)&up); | ||
163 | 164 | ||
164 | gw_deselect(bat_priv); | 165 | gw_deselect(bat_priv); |
165 | bat_info(net_dev, "Changing gateway bandwidth from: '%i' to: '%ld' " | 166 | bat_info(net_dev, "Changing gateway bandwidth from: '%i' to: '%ld' " |
166 | "(propagating: %ld%s/%ld%s)\n", | 167 | "(propagating: %d%s/%d%s)\n", |
167 | atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp, | 168 | atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp, |
168 | (down > 2048 ? down / 1024 : down), | 169 | (down > 2048 ? down / 1024 : down), |
169 | (down > 2048 ? "MBit" : "KBit"), | 170 | (down > 2048 ? "MBit" : "KBit"), |