netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
To: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	b.a.t.m.a.n-ZwoEplunGu2X36UT3dwllkB+6BGkLq7r@public.gmane.org
Subject: [PATCH 08/17] batman-adv: Only use int up and down gw representation
Date: Mon, 30 May 2011 09:22:53 +0200	[thread overview]
Message-ID: <1306740182-2665-9-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1306740182-2665-1-git-send-email-sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>

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-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
---
 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 50d3a59..ed3bd36 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)
 }
 
 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)
@@ -96,7 +97,7 @@ 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",
@@ -104,7 +105,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
 		return false;
 	}
 
-	*down *= multi;
+	*down = ldown * multi;
 
 	/* we also got some upload info */
 	if (slash_ptr) {
@@ -121,7 +122,7 @@ 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: "
@@ -129,7 +130,7 @@ static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
 			return false;
 		}
 
-		*up *= multi;
+		*up = lup * multi;
 	}
 
 	return true;
@@ -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);
@@ -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"),
-- 
1.7.5.3

  parent reply	other threads:[~2011-05-30  7:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-30  7:22 batman-adv 2011-05-30 Sven Eckelmann
     [not found] ` <1306740182-2665-1-git-send-email-sven-KaDOiPu9UxWEi8DpZVb4nw@public.gmane.org>
2011-05-30  7:22   ` [PATCH 01/17] batman-adv: move neigh_node->if_incoming->if_status check in find_router() Sven Eckelmann
2011-05-30  7:22   ` [PATCH 02/17] batman-adv: Use kzalloc rather than kmalloc followed by memset with 0 Sven Eckelmann
2011-05-30  7:22   ` [PATCH 03/17] batman-adv: Annotate functions with format strings Sven Eckelmann
2011-05-30  7:22   ` [PATCH 04/17] batman-adv: Print jiffies as unsigned long Sven Eckelmann
2011-05-30  7:22   ` [PATCH 05/17] batman-adv: Remove comparising < 0 for unsigned type Sven Eckelmann
2011-05-30  7:22   ` [PATCH 06/17] batman-adv: Don't do pointer arithmetic with void* Sven Eckelmann
2011-05-30  7:22   ` [PATCH 07/17] batman-adv: Add const type qualifier for pointers Sven Eckelmann
2011-05-30  7:22   ` Sven Eckelmann [this message]
2011-05-30  7:22   ` [PATCH 09/17] batman-adv: Remove explicit casts cast from void* for store Sven Eckelmann
2011-05-30  7:22   ` [PATCH 10/17] batman-adv: Remove casts from type x to type x Sven Eckelmann
2011-06-01  3:52   ` batman-adv 2011-05-30 David Miller
2011-05-30  7:22 ` [PATCH 11/17] batman-adv: Calculate sizeof using variable insead of types Sven Eckelmann
2011-05-30  7:22 ` [PATCH 12/17] batman-adv: Use rcu_dereference_protected by update-side Sven Eckelmann
2011-05-30  7:22 ` [PATCH 13/17] batman-adv: move smallest_signed_int(), seq_before() and seq_after() into main.h Sven Eckelmann
2011-05-30  7:22 ` [PATCH 14/17] batman-adv: Check type of x and y in seq_(before|after) Sven Eckelmann
2011-05-30  7:23 ` [PATCH 15/17] batman-adv: use is_broadcast_ether_addr() instead of compare_eth(.., brd_addr) Sven Eckelmann
2011-05-30  7:23 ` [PATCH 16/17] batman-adv: a multiline comment should precede the variable it is describing Sven Eckelmann
2011-05-30  7:23 ` [PATCH 17/17] batman-adv: Ensure that we really have route changes in update_route Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1306740182-2665-9-git-send-email-sven@narfation.org \
    --to=sven-kadoipu9uxwei8dpzvb4nw@public.gmane.org \
    --cc=b.a.t.m.a.n-ZwoEplunGu2X36UT3dwllkB+6BGkLq7r@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).