media: mc-device.c: don’t memset __user pointer contents [Linux 4.9.187]

This Linux kernel change "media: mc-device.c: don’t memset __user pointer contents" is included in the Linux 4.9.187 release. This change is authored by Hans Verkuil <hverkuil [at]> on Mon May 27 05:31:13 2019 -0400. The commit for this change in Linux stable tree is 36212c3 (patch) which is from upstream commit 518fa4e. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 518fa4e.

media: mc-device.c: don't memset __user pointer contents

[ Upstream commit 518fa4e0e0da97ea2e17c95ab57647ce748a96e2 ]

You can't memset the contents of a __user pointer. Instead, call copy_to_user to
copy links.reserved (which is zeroed) to the user memory.

This fixes this sparse warning:

SPARSE:drivers/media/mc/mc-device.c drivers/media/mc/mc-device.c:521:16:  warning: incorrect type in argument 1 (different address spaces)

Fixes: f49308878d720 ("media: media_device_enum_links32: clean a reserved field")

Signed-off-by: Hans Verkuil <>
Reviewed-by: Sakari Ailus <>
Signed-off-by: Mauro Carvalho Chehab <>
Signed-off-by: Sasha Levin <>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/media/media-device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 6062c0c..73a2dba 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -490,8 +490,9 @@ static long media_device_enum_links32(struct media_device *mdev,
    if (ret)
        return ret;

-   memset(ulinks->reserved, 0, sizeof(ulinks->reserved));
+   if (copy_to_user(ulinks->reserved, links.reserved,
+            sizeof(ulinks->reserved)))
+       return -EFAULT;
    return 0;

Leave a Reply

Your email address will not be published. Required fields are marked *