Skip to contentSkip to conversation

arch: mips: sibyte: Return -EFAULT if copy_to_user() fails

PATCH In review Wang Qing 3 participants 3 messages Mar 1, 2021 MIPS

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

PATCH 1/1 arch: mips: sibyte: Return -EFAULT if copy_to_user() fails

The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete.

---
 arch/mips/sibyte/common/sb_tbprof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/sibyte/common/sb_tbprof.c +1 -1
index f80d7a7..eac125f
@@ -465,7 +465,7 @@ static ssize_t sbprof_tb_read(struct file *filp, char *buf,
 		if (err) {
 			*offp = cur_off + cur_count - err;
 			mutex_unlock(&sbp.lock);
-			return err;
+			return -EFAULT;
 		}
 		pr_debug(DEVNAME ": read from sample %d, %d bytes\n",
 			 cur_sample, cur_count);
Signature · 1 line
2.7.4
#1 lore raw

Hello!

Quoted 2 lines · Wang Qing

The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete.

Then 'err' is hardly a good name for that variable. :-)

Quoted 11 lines
---
  arch/mips/sibyte/common/sb_tbprof.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/sibyte/common/sb_tbprof.c +0 -0
index f80d7a7..eac125f

arch/mips/sibyte/common/sb_tbprof.c static ssize_t sbprof_tb_read(struct file *filp, char *buf, · line 471

Quoted 8 lines
arch/mips/sibyte/common/sb_tbprof.c +1 -1
@@ -465,7 +465,7 @@ static ssize_t sbprof_tb_read(struct file *filp, char *buf,
  		if (err) {
  			*offp = cur_off + cur_count - err;
  			mutex_unlock(&sbp.lock);
-			return err;
+			return -EFAULT;
  		}
  		pr_debug(DEVNAME ": read from sample %d, %d bytes\n",
  			 cur_sample, cur_count);

MBR, Sergei

#2 lore raw
Quoted 4 lines · Sergei Shtylyov
Quoted 2 lines

The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete.

Then 'err' is hardly a good name for that variable. :-)

Something like `left' might be better, especially as it's the sole use.
Also it's been like this from the beginning, so:

Fixes bb9b813bb665 ("[MIPS] Sibyte: Fix ZBbus profiler")

or maybe:

Fixes d619f38fdacb ("[MIPS] Add bcm1480 ZBus trace support, fix wait related bugs")

(since the file was renamed from a different name with the latter commit) would I think be helpful for backports too. It looks like potentially quite a nasty bug to me if someone actually uses this piece (I haven't).

Maciej