Skip to contentSkip to conversation

Staging: intel_sst: return -EFAULT if copy_to_user()

PATCH In review Dan Carpenter 3 participants 7 messages Oct 15, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Staging: intel_sst: return -EFAULT if copy_to_user()

copy_to_user() returns the number of bytes remaining to be copied but we want to return an error code. And that error code is -EFAULT not -EIO.

drivers/staging/intel_sst/intel_sst_app_interface.c +3 -1
index baf0ddc..5ead4d1 100644
@@ -865,6 +865,8 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
 				str_info->src = SST_DRV;
 				retval = copy_to_user(&str_param->stream_id,
 						&retval, sizeof(__u32));
+				if (retval)
+					retval = -EFAULT;
 			} else {
 				if (retval = -SST_ERR_INVALID_PARAMS)
 					retval = -EINVAL;
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol, sizeof(get_vol));
 		if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}
 		/*sst_print_get_vol_info(str_id, &get_vol);*/
#1 lore raw

RE: [patch 1/2] Staging: intel_sst: return -EFAULT if

Quoted 30 lines

copy_to_user() returns the number of bytes remaining to be copied but we want to return an error code. And that error code is -EFAULT not -EIO.

drivers/staging/intel_sst/intel_sst_app_interface.c +2 -0
index baf0ddc..5ead4d1 100644
@@ -865,6 +865,8 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd,
 unsigned long arg)
 				str_info->src = SST_DRV;
 				retval = copy_to_user(&str_param->stream_id,
 						&retval, sizeof(__u32));
+				if (retval)
+					retval = -EFAULT;
 			} else {
 				if (retval = -SST_ERR_INVALID_PARAMS)
drivers/staging/intel_sst/intel_sst_app_interface.c +1 -1
 					retval = -EINVAL;
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd,
 unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol, sizeof(get_vol));
 		if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}
Quoted 1 line

/*sst_print_get_vol_info(str_id, &get_vol);*/

Since retval is not used and value assigned is supposed to be -EFAULT, how about this?

	if(copy_to_user())
			return -EIO;

~Vinod

#2 lore raw

Re: [patch 1/2] Staging: intel_sst: return -EFAULT if

In reply to Dan Carpenter
Quoted 12 lines · Vinod
Quoted 10 lines
drivers/staging/intel_sst/intel_sst_app_interface.c +1 -1
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd,
 unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol, sizeof(get_vol));
 		if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}

/*sst_print_get_vol_info(str_id, &get_vol);*/

Since retval is not used and value assigned is supposed to be -EFAULT, how about this?

Quoted 3 lines
	if(copy_to_user())
			return -EIO;

No. No. retval is used. We can't return directly because we need to call unlock_kernel().

regards,
dan carpenter

#3 lore raw

RE: [patch 1/2] Staging: intel_sst: return -EFAULT if

In reply to Dan Carpenter
Quoted 17 lines
Quoted 1 line

Review long intel_sst_ioctl(struct file *file_ptr, unsigned int

Quoted 1 line
(quoted diff) +0 -0
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int

cmd,

Quoted 11 lines
Quoted 9 lines
drivers/staging/intel_sst/intel_sst_app_interface.c +1 -1
 unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol, sizeof(get_vol));
 		if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}

/*sst_print_get_vol_info(str_id, &get_vol);*/

Since retval is not used and value assigned is supposed to be -EFAULT, how about this?

Quoted 3 lines
	if(copy_to_user())
			return -EIO;
Quoted 2 lines

No. No. retval is used. We can't return directly because we need to call unlock_kernel().

Kernel locking is already gone :) [1].

The point here was we don't need to store return value from this function Anyway you could have done it this way

	if(copy_to_user()) {
		retval = -EIO;
		break;
	}

~Vinod

[1]: http://mailman.alsa-project.org/pipermail/alsa-devel/2010-October/032690.html

#5 lore raw

Re: [patch 1/2] Staging: intel_sst: return -EFAULT if

In reply to Dan Carpenter
Quoted 17 lines · On Fri, 15 Oct 2010 07:29:01 +0200 Dan Carpenter <[email protected]> wrote:
Quoted 12 lines · Vinod
Quoted 10 lines
drivers/staging/intel_sst/intel_sst_app_interface.c +1 -1
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr,
 unsigned int cmd, unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol,
 sizeof(get_vol)); if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}

/*sst_print_get_vol_info(str_id, &get_vol);*/

Since retval is not used and value assigned is supposed to be -EFAULT, how about this?

Quoted 3 lines
	if(copy_to_user())
			return -EIO;
Quoted 2 lines

No. No. retval is used. We can't return directly because we need to call unlock_kernel().

Dan - your tree is a couple of patches stale at this point if it has the lock_kernel in it - the lock_kernel has gone in the latest submission.

#6 lore raw

Re: [patch 1/2] Staging: intel_sst: return -EFAULT if

In reply to Dan Carpenter
Quoted 20 lines · Alan Cox
Quoted 17 lines · On Fri, 15 Oct 2010 07:29:01 +0200 Dan Carpenter <[email protected]> wrote:
Quoted 15 lines · Vinod
Quoted 10 lines
drivers/staging/intel_sst/intel_sst_app_interface.c +1 -1
@@ -938,7 +940,7 @@ long intel_sst_ioctl(struct file *file_ptr,
 unsigned int cmd, unsigned long arg)
 		retval = copy_to_user((struct snd_sst_vol *)arg,
 						&get_vol,
 sizeof(get_vol)); if (retval) {
-			retval = -EIO;
+			retval = -EFAULT;
 			break;
 		}

/*sst_print_get_vol_info(str_id, &get_vol);*/

Since retval is not used and value assigned is supposed to be -EFAULT, how about this?

	if(copy_to_user())
			return -EIO;
Quoted 6 lines
Quoted 2 lines

No. No. retval is used. We can't return directly because we need to call unlock_kernel().

Dan - your tree is a couple of patches stale at this point if it has the lock_kernel in it - the lock_kernel has gone in the latest submission.

Yes. That went in last night. Vinod already told me.

I'll submit another patch which changes the file to the

	if (copy_to_user())
		retval = -EFAULT;

format. It will apply on top of the patches I sent already.

There are some other bugs I noticed when I wrote that so it's worth it to clean it up.

regards,
dan carpenter