Patchwork [V1,net-next,08/10] net/mlx4_core: Replace sscanf() with kstrtoint()

login
register
mail settings
Submitter Or Gerlitz
Date June 25, 2013, 9:09 a.m.
Message ID <1372151378-21468-9-git-send-email-ogerlitz@mellanox.com>
Download mbox | patch
Permalink /patch/254066/
State Accepted
Delegated to: David Miller
Headers show

Comments

Or Gerlitz - June 25, 2013, 9:09 a.m.
From: Dotan Barak <dotanb@dev.mellanox.com>

It is not safe to use sscanf.

Signed-off-by: Dotan Barak <dotanb@dev.mellanox.com>
Signed-off-by: Vladimir Sokolovsky <vlad@mellanox.com>
Signed-off-by: Amir Vadai <amirv@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx4/main.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 2f4a260..81e4529 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -839,11 +839,11 @@  static ssize_t set_port_ib_mtu(struct device *dev,
 		return -EINVAL;
 	}
 
-	err = sscanf(buf, "%d", &mtu);
-	if (err > 0)
+	err = kstrtoint(buf, 0, &mtu);
+	if (!err)
 		ibta_mtu = int_to_ibta_mtu(mtu);
 
-	if (err <= 0 || ibta_mtu < 0) {
+	if (err || ibta_mtu < 0) {
 		mlx4_err(mdev, "%s is invalid IBTA mtu\n", buf);
 		return -EINVAL;
 	}