Skip to contentSkip to conversation

habanalabs: use u64_to_user_ptr() for reading user pointers

PATCH In review Arnd Bergmann 2 participants 2 messages Jun 17, 2019 – Jun 20, 2019 Char and misc drivers

lore
Share & tools
lore

Arnd Bergmann

author maintainer
#0 lore raw

PATCH 1/1 habanalabs: use u64_to_user_ptr() for reading user pointers

We cannot cast a 64-bit integer to a pointer on 32-bit architectures without a warning:

drivers/misc/habanalabs/habanalabs_ioctl.c: In function 'debug_coresight':
drivers/misc/habanalabs/habanalabs_ioctl.c:143:23: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
input = memdup_user((const void __user *) args->input_ptr,

Use the macro that was defined for this purpose.

Fixes 315bc055ed56 ("habanalabs: add new IOCTL for debug, tracing and profiling")
---
 drivers/misc/habanalabs/habanalabs_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/habanalabs_ioctl.c +1 -1
index eeefb22023e9..b7a0eecf6b6c 100644
@@ -140,7 +140,7 @@ static int debug_coresight(struct hl_device *hdev, struct hl_debug_args *args)
 	params->op = args->op;
 
 	if (args->input_ptr && args->input_size) {
-		input = memdup_user((const void __user *) args->input_ptr,
+		input = memdup_user(u64_to_user_ptr(args->input_ptr),
 					args->input_size);
 		if (IS_ERR(input)) {
 			rc = PTR_ERR(input);
Signature · 1 line
2.20.0
#1 lore raw
Quoted 30 lines · Arnd Bergmann

We cannot cast a 64-bit integer to a pointer on 32-bit architectures without a warning:

drivers/misc/habanalabs/habanalabs_ioctl.c: In function 'debug_coresight':
drivers/misc/habanalabs/habanalabs_ioctl.c:143:23: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
input = memdup_user((const void __user *) args->input_ptr,

Use the macro that was defined for this purpose.

Fixes 315bc055ed56 ("habanalabs: add new IOCTL for debug, tracing and profiling")
---
 drivers/misc/habanalabs/habanalabs_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/habanalabs_ioctl.c +1 -2
index eeefb22023e9..b7a0eecf6b6c 100644
@@ -140,7 +140,7 @@ static int debug_coresight(struct hl_device *hdev, struct hl_debug_args *args)
        params->op = args->op;
 
        if (args->input_ptr && args->input_size) {
-               input = memdup_user((const void __user *) args->input_ptr,
+               input = memdup_user(u64_to_user_ptr(args->input_ptr),
                                        args->input_size);
                if (IS_ERR(input)) {
                        rc = PTR_ERR(input);
--
Quoted 2 lines

2.20.0

Thanks!
applied to -fixes

Oded