net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read().
Subsystems (3)
PATCH 1/1 net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read().
copy_to_user() cannot return a negative value: it returns the number of bytes that could not be copied.
Return -EFAULT on failure rather than the number of bytes that could not be copied, as this seems more standard.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c +2 -4
@@ -62,7 +62,6 @@ static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer, {struct ixgbe_adapter *adapter = filp->private_data;char buf[256 ]; -int bytes_not_copied;int len;/* don't allow partial reads */
@@ -73,9 +72,8 @@ static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer, adapter->netdev->name, ixgbe_dbg_reg_ops_buf);if (count < len)return -ENOSPC ; - bytes_not_copied =copy_to_user (buffer, buf, len); -if (bytes_not_copied <0 ) -return bytes_not_copied; +if (copy_to_user (buffer, buf, len) >0 ) +return -EFAULT ; *ppos = len;return len;
Signature · 1 line
1.7.10.4
Quoted 5 lines · Cyril Roelandt
copy_to_user()cannot return a negative value: it returns the number of bytes
that could not be copied.
Quoted 8 lines
Return
-EFAULTon failure rather than the number of bytes that could not be
copied, as this seems more standard.Signed-off-by Cyril Roelandt <[email protected]>--- drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Actually, I already have a similar patch in my queue reported by Dan Carpenter, and created by Josh Hay which fixes this issue. I should be pushing the patch in my queue in the next week. Here is the patch I am referring to:
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.
Cheers,
Jeff