public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read().
@ 2012-11-16  3:26 Cyril Roelandt
  2012-11-16  4:42 ` Jeff Kirsher
  0 siblings, 1 reply; 2+ messages in thread
From: Cyril Roelandt @ 2012-11-16  3:26 UTC (permalink / raw)
  To: jeffrey.t.kirsher; +Cc: e1000-devel, netdev, linux-kernel, Cyril Roelandt

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.

Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
index 8d3a218..77a3598 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
@@ -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;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read().
  2012-11-16  3:26 [PATCH] net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read() Cyril Roelandt
@ 2012-11-16  4:42 ` Jeff Kirsher
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Kirsher @ 2012-11-16  4:42 UTC (permalink / raw)
  To: Cyril Roelandt
  Cc: e1000-devel, netdev, linux-kernel, Hay, Joshua A, Dan Carpenter

[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]

On Fri, 2012-11-16 at 04:26 +0100, Cyril Roelandt wrote:
> 
> 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.
> 
> Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>
> ---
>  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.
    
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>

Cheers,
Jeff

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-16  4:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-16  3:26 [PATCH] net/ethernet/intel/ixgbe/ixgbe_debugfs.c: fix error handling in ixgbe_dbg_reg_ops_read() Cyril Roelandt
2012-11-16  4:42 ` Jeff Kirsher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox