Skip to contentSkip to conversation

drivers/comedi: use standard array-copy-function

PATCH New Philipp Stanner 1 participant 1 message Nov 3, 2023 Comedi drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers/comedi: use standard array-copy-function

comedi_fops.c utilizes memdup_user() to copy a userspace array.

The new function memdup_array_user() provides a standardized way to copy userspace-arrays. It makes it easier to see that an array is being copied and, additionally, performs a generic overflow-check which might help make the code more robust in case of changes in the future.

Replace memdup_user() with memdup_array_user().

---
Changes in v2:
- Rephrase commit message so that it doesn't sound as if an actual overflow is being fixed here. (Greg K-H)
- Add Reviewed-by from Ian Abbott

---
 drivers/comedi/comedi_fops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/comedi/comedi_fops.c +2 -2
index 1548dea15df1..1b481731df96 100644
@@ -1714,8 +1714,8 @@ static int __comedi_get_user_chanlist(struct comedi_device *dev,
 
 	lockdep_assert_held(&dev->mutex);
 	cmd->chanlist = NULL;
-	chanlist = memdup_user(user_chanlist,
-			       cmd->chanlist_len * sizeof(unsigned int));
+	chanlist = memdup_array_user(user_chanlist,
+				     cmd->chanlist_len, sizeof(unsigned int));
 	if (IS_ERR(chanlist))
 		return PTR_ERR(chanlist);
 
Signature · 1 line
2.41.0