Skip to contentSkip to conversation

ISDN: fix copy_to_user() unused result warning in isdn_ppp

PATCH In review Jesper Juhl 2 participants 3 messages Feb 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ISDN: fix copy_to_user() unused result warning in isdn_ppp

From: Jesper Juhl <[email protected]>

Fix compile warning about copy_to_user() unused result in isdn_ppp.c
drivers/isdn/i4l/isdn_ppp.c:785: warning: ignoring return value of `copy_to_user', declared with attribute warn_unused_result

---

 drivers/isdn/i4l/isdn_ppp.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)
drivers/isdn/i4l/isdn_ppp.c +4 -1
@@ -782,7 +782,10 @@ isdn_ppp_read(int min, struct file *file
 	is->first = b;
 
 	spin_unlock_irqrestore(&is->buflock, flags);
-	copy_to_user(buf, save_buf, count);
+	if (copy_to_user(buf, save_buf, count)) {
+		kfree(save_buf);
+		return -EFAULT;
+	}
 	kfree(save_buf);
 
 	return count;
#1 lore raw
Quoted 18 lines · Jesper Juhl

From: Jesper Juhl <[email protected]>

Fix compile warning about copy_to_user() unused result in isdn_ppp.c
drivers/isdn/i4l/isdn_ppp.c:785: warning: ignoring return value of `copy_to_user', declared with attribute warn_unused_result

---

 drivers/isdn/i4l/isdn_ppp.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)
drivers/isdn/i4l/isdn_ppp.c +0 -0
@@ -782,7 +782,10 @@ isdn_ppp_read(int min, struct file *file
 	is->first = b;

drivers/isdn/i4l/isdn_ppp.c isdn_ppp_read(int min, struct file *file · line 791

Quoted 10 lines
drivers/isdn/i4l/isdn_ppp.c +4 -1
 
 	spin_unlock_irqrestore(&is->buflock, flags);
-	copy_to_user(buf, save_buf, count);
+	if (copy_to_user(buf, save_buf, count)) {
+		kfree(save_buf);
+		return -EFAULT;
+	}
 	kfree(save_buf);
 
 	return count;

What about:

drivers/isdn/i4l/isdn_ppp.c 2006-02-21 23:07:57.000000000 +0100 renamed from drivers/isdn/i4l/isdn_ppp.c 2006-01-03 04:21:10.000000000 +0100 +2 -1
@@ -782,7 +782,8 @@ isdn_ppp_read(int min, struct file *file
 	is->first = b;
 
 	spin_unlock_irqrestore(&is->buflock, flags);
-	copy_to_user(buf, save_buf, count);
+	if (copy_to_user(buf, save_buf, count))
+		count = -EFAULT;
 	kfree(save_buf);
 
 	return count;

should result in a conditional move instead of jumps.

But I'm OK with the original patch as well, for both version you can add

Signature · 3 lines
Karsten Keil
SuSE Labs
ISDN development
#2 lore raw
Quoted 45 lines · Karsten Keil
Quoted 18 lines · Jesper Juhl

From: Jesper Juhl <[email protected]>

Fix compile warning about copy_to_user() unused result in isdn_ppp.c
drivers/isdn/i4l/isdn_ppp.c:785: warning: ignoring return value of `copy_to_user', declared with attribute warn_unused_result

---

 drivers/isdn/i4l/isdn_ppp.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)
drivers/isdn/i4l/isdn_ppp.c 2006-02-21 23:07:57.000000000 +0100 renamed from drivers/isdn/i4l/isdn_ppp.c 2006-01-03 04:21:10.000000000 +0100 +0 -0
@@ -782,7 +782,10 @@ isdn_ppp_read(int min, struct file *file
      is->first = b;

drivers/isdn/i4l/isdn_ppp.c 2006-02-21 23:07:57.000000000 +0100 isdn_ppp_read(int min, struct file *file · line 791

Quoted 10 lines
drivers/isdn/i4l/isdn_ppp.c 2006-02-21 23:07:57.000000000 +0100 renamed from drivers/isdn/i4l/isdn_ppp.c 2006-01-03 04:21:10.000000000 +0100 +4 -1
 
      spin_unlock_irqrestore(&is->buflock, flags);
-     copy_to_user(buf, save_buf, count);
+     if (copy_to_user(buf, save_buf, count)) {
+             kfree(save_buf);
+             return -EFAULT;
+     }
      kfree(save_buf);
 
      return count;

What about:

drivers/isdn/i4l/isdn_ppp.c 2006-02-21 23:07:57.000000000 +0100 renamed from drivers/isdn/i4l/isdn_ppp.c 2006-01-03 04:21:10.000000000 +0100 +2 -1
@@ -782,7 +782,8 @@ isdn_ppp_read(int min, struct file *file
        is->first = b;
 
        spin_unlock_irqrestore(&is->buflock, flags);
-       copy_to_user(buf, save_buf, count);
+       if (copy_to_user(buf, save_buf, count))
+               count = -EFAULT;
        kfree(save_buf);
 
        return count;
Quoted 2 lines

should result in a conditional move instead of jumps.

I actually considered that, but decided against it since I thought it would be confusing use / misuse of 'count'.

Either version is fine by me. It's not likely to get hit in any case due to the verify_area() call further up in the code.

Quoted 4 lines

But I'm OK with the original patch as well, for both version you can add

Thanks.

Andrew: could you please apply either my or Karsten's version to -mm ?

--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html