diff options
author | Jesse Brandeburg <jesse.brandeburg@intel.com> | 2013-09-28 03:13:44 -0400 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2013-10-22 09:02:40 -0400 |
commit | 004173cbbf933b8122aa5bea4211302ca79a0bb0 (patch) | |
tree | 644bfcbd8269a3fb2a7e381c84322eaf126e02d6 /drivers/net/ethernet/intel/i40e/i40e_debugfs.c | |
parent | 520dfd8b09dc9f4da6499b93ef0db7166746e8c3 (diff) |
i40e: fix use of untrusted scalar value warning
This is a fix for an issue reported by coverity, reported by
Hannes Frederic Sowa.
I'm unable to test if this patch actually fixes the coverity
reported issue, feedback is welcome.
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
CC: Hannes Frederic Sowa <hannes@stressinduktion.org>
Tested-by: Kavindya Deegala <kavindya.s.deegala@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/i40e/i40e_debugfs.c')
-rw-r--r-- | drivers/net/ethernet/intel/i40e/i40e_debugfs.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c index c80fcb4d8ff8..387bf94495f0 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c +++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c | |||
@@ -151,9 +151,7 @@ static ssize_t i40e_dbg_dump_write(struct file *filp, | |||
151 | size_t count, loff_t *ppos) | 151 | size_t count, loff_t *ppos) |
152 | { | 152 | { |
153 | struct i40e_pf *pf = filp->private_data; | 153 | struct i40e_pf *pf = filp->private_data; |
154 | char dump_request_buf[16]; | ||
155 | bool seid_found = false; | 154 | bool seid_found = false; |
156 | int bytes_not_copied; | ||
157 | long seid = -1; | 155 | long seid = -1; |
158 | int buflen = 0; | 156 | int buflen = 0; |
159 | int i, ret; | 157 | int i, ret; |
@@ -163,21 +161,12 @@ static ssize_t i40e_dbg_dump_write(struct file *filp, | |||
163 | /* don't allow partial writes */ | 161 | /* don't allow partial writes */ |
164 | if (*ppos != 0) | 162 | if (*ppos != 0) |
165 | return 0; | 163 | return 0; |
166 | if (count >= sizeof(dump_request_buf)) | ||
167 | return -ENOSPC; | ||
168 | |||
169 | bytes_not_copied = copy_from_user(dump_request_buf, buffer, count); | ||
170 | if (bytes_not_copied < 0) | ||
171 | return bytes_not_copied; | ||
172 | if (bytes_not_copied > 0) | ||
173 | count -= bytes_not_copied; | ||
174 | dump_request_buf[count] = '\0'; | ||
175 | 164 | ||
176 | /* decode the SEID given to be dumped */ | 165 | /* decode the SEID given to be dumped */ |
177 | ret = kstrtol(dump_request_buf, 0, &seid); | 166 | ret = kstrtol_from_user(buffer, count, 0, &seid); |
178 | if (ret < 0) { | 167 | |
179 | dev_info(&pf->pdev->dev, "bad seid value '%s'\n", | 168 | if (ret) { |
180 | dump_request_buf); | 169 | dev_info(&pf->pdev->dev, "bad seid value\n"); |
181 | } else if (seid == 0) { | 170 | } else if (seid == 0) { |
182 | seid_found = true; | 171 | seid_found = true; |
183 | 172 | ||
@@ -1023,11 +1012,11 @@ static ssize_t i40e_dbg_command_write(struct file *filp, | |||
1023 | size_t count, loff_t *ppos) | 1012 | size_t count, loff_t *ppos) |
1024 | { | 1013 | { |
1025 | struct i40e_pf *pf = filp->private_data; | 1014 | struct i40e_pf *pf = filp->private_data; |
1015 | char *cmd_buf, *cmd_buf_tmp; | ||
1026 | int bytes_not_copied; | 1016 | int bytes_not_copied; |
1027 | struct i40e_vsi *vsi; | 1017 | struct i40e_vsi *vsi; |
1028 | u8 *print_buf_start; | 1018 | u8 *print_buf_start; |
1029 | u8 *print_buf; | 1019 | u8 *print_buf; |
1030 | char *cmd_buf; | ||
1031 | int vsi_seid; | 1020 | int vsi_seid; |
1032 | int veb_seid; | 1021 | int veb_seid; |
1033 | int cnt; | 1022 | int cnt; |
@@ -1046,6 +1035,12 @@ static ssize_t i40e_dbg_command_write(struct file *filp, | |||
1046 | count -= bytes_not_copied; | 1035 | count -= bytes_not_copied; |
1047 | cmd_buf[count] = '\0'; | 1036 | cmd_buf[count] = '\0'; |
1048 | 1037 | ||
1038 | cmd_buf_tmp = strchr(cmd_buf, '\n'); | ||
1039 | if (cmd_buf_tmp) { | ||
1040 | *cmd_buf_tmp = '\0'; | ||
1041 | count = cmd_buf_tmp - cmd_buf + 1; | ||
1042 | } | ||
1043 | |||
1049 | print_buf_start = kzalloc(I40E_MAX_DEBUG_OUT_BUFFER, GFP_KERNEL); | 1044 | print_buf_start = kzalloc(I40E_MAX_DEBUG_OUT_BUFFER, GFP_KERNEL); |
1050 | if (!print_buf_start) | 1045 | if (!print_buf_start) |
1051 | goto command_write_done; | 1046 | goto command_write_done; |
@@ -1900,6 +1895,7 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp, | |||
1900 | struct i40e_pf *pf = filp->private_data; | 1895 | struct i40e_pf *pf = filp->private_data; |
1901 | int bytes_not_copied; | 1896 | int bytes_not_copied; |
1902 | struct i40e_vsi *vsi; | 1897 | struct i40e_vsi *vsi; |
1898 | char *buf_tmp; | ||
1903 | int vsi_seid; | 1899 | int vsi_seid; |
1904 | int i, cnt; | 1900 | int i, cnt; |
1905 | 1901 | ||
@@ -1918,6 +1914,12 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp, | |||
1918 | count -= bytes_not_copied; | 1914 | count -= bytes_not_copied; |
1919 | i40e_dbg_netdev_ops_buf[count] = '\0'; | 1915 | i40e_dbg_netdev_ops_buf[count] = '\0'; |
1920 | 1916 | ||
1917 | buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n'); | ||
1918 | if (buf_tmp) { | ||
1919 | *buf_tmp = '\0'; | ||
1920 | count = buf_tmp - i40e_dbg_netdev_ops_buf + 1; | ||
1921 | } | ||
1922 | |||
1921 | if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { | 1923 | if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { |
1922 | cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid); | 1924 | cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid); |
1923 | if (cnt != 1) { | 1925 | if (cnt != 1) { |