[RFC] media: atomisp: change copy_from_compatible to iov_iter
From: Joshua Crofts
Date: Wed Apr 08 2026 - 09:49:29 EST
Since the atomisp driver concerns transferring video
data, it would probably be better to use an iov_iter
than copy_to_user calls (scatter-gather i/o and better
pointer safety). Per yesterday's emails, I'm sending an
an example of a function in atomisp_cmd.c where I've
implemented iov_iter usage.
Note, this isn't a patch, more of a question whether this
style of changing the copy_to_user calls is valid (or if
I'm writing garbage code). I'd rather get your opinion
than submitting a patch first.
Thanks for your response!
Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
---
drivers/staging/media/atomisp/pci/atomisp_cmd.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index b3e971be0e..3b987e8e8c 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -15,6 +15,7 @@
#include <linux/kfifo.h>
#include <linux/pm_runtime.h>
#include <linux/timer.h>
+#include <linux/uio.h>
#include <asm/iosf_mbi.h>
@@ -1676,7 +1677,8 @@ int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
{
struct atomisp_device *isp = asd->isp;
struct atomisp_s3a_buf *s3a_buf;
- unsigned long ret;
+ struct iov_iter iter;
+ int ret;
if (flag != 0)
return -EINVAL;
@@ -1709,13 +1711,12 @@ int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
config->exp_id = s3a_buf->s3a_data->exp_id;
config->isp_config_id = s3a_buf->s3a_data->isp_config_id;
- ret = copy_to_user(config->data, asd->params.s3a_user_stat->data,
- asd->params.s3a_output_bytes);
- if (ret) {
- dev_err(isp->dev, "copy to user failed: copied %lu bytes\n",
- ret);
+ ret = import_ubuf(ITER_DEST, (void __user *)config->data, asd->params.s3a_output_bytes, &iter);
+ if (ret)
+ return ret;
+
+ if (copy_to_iter(asd->params.s3a_user_stat->data, asd->params.s3a_output_bytes, &iter) != asd->params.s3a_output_bytes)
return -EFAULT;
- }
/* Move to free buffer list */
list_del_init(&s3a_buf->list);
--
2.47.3