* [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user
@ 2025-09-17 12:48 Thorsten Blum
2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Thorsten Blum @ 2025-09-17 12:48 UTC (permalink / raw)
To: Jeff Hugo, Carl Vanderlip, Oded Gabbay
Cc: Thorsten Blum, linux-arm-msm, dri-devel, linux-kernel
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify qaic_attach_slice_bo_ioctl().
No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/accel/qaic/qaic_data.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index 797289e9d780..202bdca58847 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -18,6 +18,7 @@
#include <linux/scatterlist.h>
#include <linux/spinlock.h>
#include <linux/srcu.h>
+#include <linux/string.h>
#include <linux/types.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
@@ -984,18 +985,12 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
user_data = u64_to_user_ptr(args->data);
- slice_ent = kzalloc(arg_size, GFP_KERNEL);
- if (!slice_ent) {
- ret = -EINVAL;
+ slice_ent = memdup_user(user_data, arg_size);
+ if (IS_ERR(slice_ent)) {
+ ret = PTR_ERR(slice_ent);
goto unlock_dev_srcu;
}
- ret = copy_from_user(slice_ent, user_data, arg_size);
- if (ret) {
- ret = -EFAULT;
- goto free_slice_ent;
- }
-
obj = drm_gem_object_lookup(file_priv, args->hdr.handle);
if (!obj) {
ret = -ENOENT;
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user 2025-09-17 12:48 [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum @ 2025-09-17 12:48 ` Thorsten Blum 2025-10-06 20:12 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo 2025-09-17 12:54 ` [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Karol Wachowski ` (2 subsequent siblings) 3 siblings, 2 replies; 7+ messages in thread From: Thorsten Blum @ 2025-09-17 12:48 UTC (permalink / raw) To: Jeff Hugo, Carl Vanderlip, Oded Gabbay Cc: Thorsten Blum, linux-arm-msm, dri-devel, linux-kernel Replace kcalloc() followed by copy_from_user() with memdup_array_user() to improve and simplify both __qaic_execute_bo_ioctl() and qaic_perf_stats_bo_ioctl(). In __qaic_execute_bo_ioctl(), return early if an error occurs and remove the obsolete 'free_exec' label. Since memdup_array_user() already checks for multiplication overflow, remove the manual check in __qaic_execute_bo_ioctl(). Remove any unused local variables accordingly. Since 'ret = copy_from_user()' has been removed, initialize 'ret = 0' to preserve the same return value on success. No functional changes intended. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> --- drivers/accel/qaic/qaic_data.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c index 202bdca58847..adabc4028bb2 100644 --- a/drivers/accel/qaic/qaic_data.c +++ b/drivers/accel/qaic/qaic_data.c @@ -1295,8 +1295,6 @@ static int __qaic_execute_bo_ioctl(struct drm_device *dev, void *data, struct dr int usr_rcu_id, qdev_rcu_id; struct qaic_device *qdev; struct qaic_user *usr; - u8 __user *user_data; - unsigned long n; u64 received_ts; u32 queue_level; u64 submit_ts; @@ -1309,20 +1307,12 @@ static int __qaic_execute_bo_ioctl(struct drm_device *dev, void *data, struct dr received_ts = ktime_get_ns(); size = is_partial ? sizeof(struct qaic_partial_execute_entry) : sizeof(*exec); - n = (unsigned long)size * args->hdr.count; - if (args->hdr.count == 0 || n / args->hdr.count != size) + if (args->hdr.count == 0) return -EINVAL; - user_data = u64_to_user_ptr(args->data); - - exec = kcalloc(args->hdr.count, size, GFP_KERNEL); - if (!exec) - return -ENOMEM; - - if (copy_from_user(exec, user_data, n)) { - ret = -EFAULT; - goto free_exec; - } + exec = memdup_array_user(u64_to_user_ptr(args->data), args->hdr.count, size); + if (IS_ERR(exec)) + return PTR_ERR(exec); usr = file_priv->driver_priv; usr_rcu_id = srcu_read_lock(&usr->qddev_lock); @@ -1383,7 +1373,6 @@ static int __qaic_execute_bo_ioctl(struct drm_device *dev, void *data, struct dr srcu_read_unlock(&qdev->dev_lock, qdev_rcu_id); unlock_usr_srcu: srcu_read_unlock(&usr->qddev_lock, usr_rcu_id); -free_exec: kfree(exec); return ret; } @@ -1736,7 +1725,8 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void *data, struct drm_file struct qaic_device *qdev; struct qaic_user *usr; struct qaic_bo *bo; - int ret, i; + int ret = 0; + int i; usr = file_priv->driver_priv; usr_rcu_id = srcu_read_lock(&usr->qddev_lock); @@ -1757,18 +1747,12 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void *data, struct drm_file goto unlock_dev_srcu; } - ent = kcalloc(args->hdr.count, sizeof(*ent), GFP_KERNEL); - if (!ent) { - ret = -EINVAL; + ent = memdup_array_user(u64_to_user_ptr(args->data), args->hdr.count, sizeof(*ent)); + if (IS_ERR(ent)) { + ret = PTR_ERR(ent); goto unlock_dev_srcu; } - ret = copy_from_user(ent, u64_to_user_ptr(args->data), args->hdr.count * sizeof(*ent)); - if (ret) { - ret = -EFAULT; - goto free_ent; - } - for (i = 0; i < args->hdr.count; i++) { obj = drm_gem_object_lookup(file_priv, ent[i].handle); if (!obj) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user 2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum @ 2025-10-06 20:12 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo 1 sibling, 0 replies; 7+ messages in thread From: Jeff Hugo @ 2025-10-06 20:12 UTC (permalink / raw) To: Thorsten Blum, Carl Vanderlip, Oded Gabbay Cc: linux-arm-msm, dri-devel, linux-kernel On 9/17/2025 6:48 AM, Thorsten Blum wrote: > Replace kcalloc() followed by copy_from_user() with memdup_array_user() > to improve and simplify both __qaic_execute_bo_ioctl() and > qaic_perf_stats_bo_ioctl(). > > In __qaic_execute_bo_ioctl(), return early if an error occurs and remove > the obsolete 'free_exec' label. > > Since memdup_array_user() already checks for multiplication overflow, > remove the manual check in __qaic_execute_bo_ioctl(). Remove any unused > local variables accordingly. > > Since 'ret = copy_from_user()' has been removed, initialize 'ret = 0' to > preserve the same return value on success. > > No functional changes intended. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user 2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum 2025-10-06 20:12 ` Jeff Hugo @ 2025-10-06 20:14 ` Jeff Hugo 1 sibling, 0 replies; 7+ messages in thread From: Jeff Hugo @ 2025-10-06 20:14 UTC (permalink / raw) To: Thorsten Blum, Carl Vanderlip, Oded Gabbay Cc: linux-arm-msm, dri-devel, linux-kernel On 9/17/2025 6:48 AM, Thorsten Blum wrote: > Replace kcalloc() followed by copy_from_user() with memdup_array_user() > to improve and simplify both __qaic_execute_bo_ioctl() and > qaic_perf_stats_bo_ioctl(). > > In __qaic_execute_bo_ioctl(), return early if an error occurs and remove > the obsolete 'free_exec' label. > > Since memdup_array_user() already checks for multiplication overflow, > remove the manual check in __qaic_execute_bo_ioctl(). Remove any unused > local variables accordingly. > > Since 'ret = copy_from_user()' has been removed, initialize 'ret = 0' to > preserve the same return value on success. > > No functional changes intended. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Applied to drm-misc-next. -Jeff ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user 2025-09-17 12:48 [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum 2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum @ 2025-09-17 12:54 ` Karol Wachowski 2025-10-06 20:05 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo 3 siblings, 0 replies; 7+ messages in thread From: Karol Wachowski @ 2025-09-17 12:54 UTC (permalink / raw) To: Thorsten Blum, Jeff Hugo, Carl Vanderlip, Oded Gabbay Cc: linux-arm-msm, dri-devel, linux-kernel Reviewed-by: Karol Wachowski <karol.wachowski@linux.intel.com> On 9/17/2025 2:48 PM, Thorsten Blum wrote: > Replace kzalloc() followed by copy_from_user() with memdup_user() to > improve and simplify qaic_attach_slice_bo_ioctl(). > > No functional changes intended. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> > --- > drivers/accel/qaic/qaic_data.c | 13 ++++--------- > 1 file changed, 4 insertions(+), 9 deletions(-) > > diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c > index 797289e9d780..202bdca58847 100644 > --- a/drivers/accel/qaic/qaic_data.c > +++ b/drivers/accel/qaic/qaic_data.c > @@ -18,6 +18,7 @@ > #include <linux/scatterlist.h> > #include <linux/spinlock.h> > #include <linux/srcu.h> > +#include <linux/string.h> > #include <linux/types.h> > #include <linux/uaccess.h> > #include <linux/wait.h> > @@ -984,18 +985,12 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi > > user_data = u64_to_user_ptr(args->data); > > - slice_ent = kzalloc(arg_size, GFP_KERNEL); > - if (!slice_ent) { > - ret = -EINVAL; > + slice_ent = memdup_user(user_data, arg_size); > + if (IS_ERR(slice_ent)) { > + ret = PTR_ERR(slice_ent); > goto unlock_dev_srcu; > } > > - ret = copy_from_user(slice_ent, user_data, arg_size); > - if (ret) { > - ret = -EFAULT; > - goto free_slice_ent; > - } > - > obj = drm_gem_object_lookup(file_priv, args->hdr.handle); > if (!obj) { > ret = -ENOENT; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user 2025-09-17 12:48 [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum 2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum 2025-09-17 12:54 ` [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Karol Wachowski @ 2025-10-06 20:05 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo 3 siblings, 0 replies; 7+ messages in thread From: Jeff Hugo @ 2025-10-06 20:05 UTC (permalink / raw) To: Thorsten Blum, Carl Vanderlip, Oded Gabbay Cc: linux-arm-msm, dri-devel, linux-kernel On 9/17/2025 6:48 AM, Thorsten Blum wrote: > Replace kzalloc() followed by copy_from_user() with memdup_user() to > improve and simplify qaic_attach_slice_bo_ioctl(). > > No functional changes intended. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user 2025-09-17 12:48 [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum ` (2 preceding siblings ...) 2025-10-06 20:05 ` Jeff Hugo @ 2025-10-06 20:14 ` Jeff Hugo 3 siblings, 0 replies; 7+ messages in thread From: Jeff Hugo @ 2025-10-06 20:14 UTC (permalink / raw) To: Thorsten Blum, Carl Vanderlip, Oded Gabbay Cc: linux-arm-msm, dri-devel, linux-kernel On 9/17/2025 6:48 AM, Thorsten Blum wrote: > Replace kzalloc() followed by copy_from_user() with memdup_user() to > improve and simplify qaic_attach_slice_bo_ioctl(). > > No functional changes intended. > > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Applied to drm-misc-next. -Jeff ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-06 20:14 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-17 12:48 [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Thorsten Blum 2025-09-17 12:48 ` [PATCH 2/2] accel/qaic: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum 2025-10-06 20:12 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo 2025-09-17 12:54 ` [PATCH 1/2] accel/qaic: Replace kzalloc + copy_from_user with memdup_user Karol Wachowski 2025-10-06 20:05 ` Jeff Hugo 2025-10-06 20:14 ` Jeff Hugo
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.