dect
/
linux-2.6
Archived
13
0
Fork 0

ixgbe: eliminate Smatch warnings in ixgbe_debugfs.c

This patch replaces calls to copy_to_user, copy_from_user, and the associated
logic, with calls to simple_read_from_buffer and simple_write_to_buffer
respectively.  This was done to eliminate warnings generated by the Smatch
static analysis tool.

v2- Fix return values based community feedback

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
CC: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Josh Hay <joshua.a.hay@intel.com>
Tested-by: Phil Schmitt <phillip.j.schmitt@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
This commit is contained in:
joshua.a.hay@intel.com 2012-11-28 05:49:20 +00:00 committed by Jeff Kirsher
parent 1b4c44e636
commit 3288d73578
1 changed files with 48 additions and 39 deletions

View File

@ -47,23 +47,27 @@ static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ixgbe_adapter *adapter = filp->private_data; struct ixgbe_adapter *adapter = filp->private_data;
char buf[256]; char *buf;
int bytes_not_copied;
int len; int len;
/* don't allow partial reads */ /* don't allow partial reads */
if (*ppos != 0) if (*ppos != 0)
return 0; return 0;
len = snprintf(buf, sizeof(buf), "%s: %s\n", buf = kasprintf(GFP_KERNEL, "%s: %s\n",
adapter->netdev->name, ixgbe_dbg_reg_ops_buf); adapter->netdev->name,
if (count < len) ixgbe_dbg_reg_ops_buf);
return -ENOSPC; if (!buf)
bytes_not_copied = copy_to_user(buffer, buf, len); return -ENOMEM;
if (bytes_not_copied < 0)
return bytes_not_copied;
*ppos = len; if (count < strlen(buf)) {
kfree(buf);
return -ENOSPC;
}
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
kfree(buf);
return len; return len;
} }
@ -79,7 +83,7 @@ static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ixgbe_adapter *adapter = filp->private_data; struct ixgbe_adapter *adapter = filp->private_data;
int bytes_not_copied; int len;
/* don't allow partial writes */ /* don't allow partial writes */
if (*ppos != 0) if (*ppos != 0)
@ -87,14 +91,15 @@ static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
if (count >= sizeof(ixgbe_dbg_reg_ops_buf)) if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
return -ENOSPC; return -ENOSPC;
bytes_not_copied = copy_from_user(ixgbe_dbg_reg_ops_buf, buffer, count); len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
if (bytes_not_copied < 0) sizeof(ixgbe_dbg_reg_ops_buf)-1,
return bytes_not_copied; ppos,
else if (bytes_not_copied < count) buffer,
count -= bytes_not_copied; count);
else if (len < 0)
return -ENOSPC; return len;
ixgbe_dbg_reg_ops_buf[count] = '\0';
ixgbe_dbg_reg_ops_buf[len] = '\0';
if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) { if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
u32 reg, value; u32 reg, value;
@ -147,23 +152,27 @@ static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ixgbe_adapter *adapter = filp->private_data; struct ixgbe_adapter *adapter = filp->private_data;
char buf[256]; char *buf;
int bytes_not_copied;
int len; int len;
/* don't allow partial reads */ /* don't allow partial reads */
if (*ppos != 0) if (*ppos != 0)
return 0; return 0;
len = snprintf(buf, sizeof(buf), "%s: %s\n", buf = kasprintf(GFP_KERNEL, "%s: %s\n",
adapter->netdev->name, ixgbe_dbg_netdev_ops_buf); adapter->netdev->name,
if (count < len) ixgbe_dbg_netdev_ops_buf);
return -ENOSPC; if (!buf)
bytes_not_copied = copy_to_user(buffer, buf, len); return -ENOMEM;
if (bytes_not_copied < 0)
return bytes_not_copied;
*ppos = len; if (count < strlen(buf)) {
kfree(buf);
return -ENOSPC;
}
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
kfree(buf);
return len; return len;
} }
@ -179,7 +188,7 @@ static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct ixgbe_adapter *adapter = filp->private_data; struct ixgbe_adapter *adapter = filp->private_data;
int bytes_not_copied; int len;
/* don't allow partial writes */ /* don't allow partial writes */
if (*ppos != 0) if (*ppos != 0)
@ -187,15 +196,15 @@ static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
if (count >= sizeof(ixgbe_dbg_netdev_ops_buf)) if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
return -ENOSPC; return -ENOSPC;
bytes_not_copied = copy_from_user(ixgbe_dbg_netdev_ops_buf, len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf,
buffer, count); sizeof(ixgbe_dbg_netdev_ops_buf)-1,
if (bytes_not_copied < 0) ppos,
return bytes_not_copied; buffer,
else if (bytes_not_copied < count) count);
count -= bytes_not_copied; if (len < 0)
else return len;
return -ENOSPC;
ixgbe_dbg_netdev_ops_buf[count] = '\0'; ixgbe_dbg_netdev_ops_buf[len] = '\0';
if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev); adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);