Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: bpf: fix gcc warning and unify __u64 into u64

I've got multiple reports of:
error: cast from pointer to integer of different size
[-Werror=pointer-to-int-cast].

Let's use the same trick than kernel/bpf/helpers.c to shut up that warning.

Even if we were on an architecture with addresses on more than 64 bits,
this isn't much of an issue as the address is not used as a pointer,
but as an hash and the caller is not supposed to go back to the kernel
address ever.

And while we change those, make sure we use u64 instead of __u64 for
consistency

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202406280633.OPB5uIFj-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202406282304.UydSVncq-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202406282242.Fk738zzy-lkp@intel.com/
Reported-by: Mirsad Todorovac <mtodorovac69@gmail.com>
Fixes: 67eccf151d76 ("HID: add source argument to HID low level functions")
Link: https://patch.msgid.link/20240701-fix-cki-v2-2-20564e2e1393@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

+12 -12
+3 -3
drivers/hid/bpf/hid_bpf_dispatch.c
··· 440 440 size, 441 441 rtype, 442 442 reqtype, 443 - (__u64)ctx, 443 + (u64)(long)ctx, 444 444 true); /* prevent infinite recursions */ 445 445 446 446 if (ret > 0) ··· 483 483 if (!dma_data) 484 484 return -ENOMEM; 485 485 486 - ret = hid_ops->hid_hw_output_report(hdev, dma_data, size, (__u64)ctx, true); 486 + ret = hid_ops->hid_hw_output_report(hdev, dma_data, size, (u64)(long)ctx, true); 487 487 488 488 kfree(dma_data); 489 489 return ret; ··· 505 505 if (ret) 506 506 return ret; 507 507 508 - return hid_ops->hid_input_report(ctx->hid, type, buf, size, 0, (__u64)ctx, true, 508 + return hid_ops->hid_input_report(ctx->hid, type, buf, size, 0, (u64)(long)ctx, true, 509 509 lock_already_taken); 510 510 } 511 511
+1 -1
drivers/hid/bpf/hid_bpf_struct_ops.c
··· 261 261 hid_put_device(hdev); 262 262 } 263 263 264 - static int __hid_bpf_device_event(struct hid_bpf_ctx *ctx, enum hid_report_type type, __u64 source) 264 + static int __hid_bpf_device_event(struct hid_bpf_ctx *ctx, enum hid_report_type type, u64 source) 265 265 { 266 266 return 0; 267 267 }
+2 -2
drivers/hid/hid-core.c
··· 2412 2412 unsigned char reportnum, __u8 *buf, 2413 2413 size_t len, enum hid_report_type rtype, 2414 2414 enum hid_class_request reqtype, 2415 - __u64 source, bool from_bpf) 2415 + u64 source, bool from_bpf) 2416 2416 { 2417 2417 unsigned int max_buffer_size = HID_MAX_BUFFER_SIZE; 2418 2418 int ret; ··· 2454 2454 } 2455 2455 EXPORT_SYMBOL_GPL(hid_hw_raw_request); 2456 2456 2457 - int __hid_hw_output_report(struct hid_device *hdev, __u8 *buf, size_t len, __u64 source, 2457 + int __hid_hw_output_report(struct hid_device *hdev, __u8 *buf, size_t len, u64 source, 2458 2458 bool from_bpf) 2459 2459 { 2460 2460 unsigned int max_buffer_size = HID_MAX_BUFFER_SIZE;
+3 -3
drivers/hid/hidraw.c
··· 140 140 141 141 if ((report_type == HID_OUTPUT_REPORT) && 142 142 !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) { 143 - ret = __hid_hw_output_report(dev, buf, count, (__u64)file, false); 143 + ret = __hid_hw_output_report(dev, buf, count, (u64)(long)file, false); 144 144 /* 145 145 * compatibility with old implementation of USB-HID and I2C-HID: 146 146 * if the device does not support receiving output reports, ··· 151 151 } 152 152 153 153 ret = __hid_hw_raw_request(dev, buf[0], buf, count, report_type, 154 - HID_REQ_SET_REPORT, (__u64)file, false); 154 + HID_REQ_SET_REPORT, (u64)(long)file, false); 155 155 156 156 out_free: 157 157 kfree(buf); ··· 228 228 } 229 229 230 230 ret = __hid_hw_raw_request(dev, report_number, buf, count, report_type, 231 - HID_REQ_GET_REPORT, (__u64)file, false); 231 + HID_REQ_GET_REPORT, (u64)(long)file, false); 232 232 233 233 if (ret < 0) 234 234 goto out_free;
+3 -3
include/linux/hid_bpf.h
··· 68 68 unsigned char reportnum, __u8 *buf, 69 69 size_t len, enum hid_report_type rtype, 70 70 enum hid_class_request reqtype, 71 - __u64 source, bool from_bpf); 71 + u64 source, bool from_bpf); 72 72 int (*hid_hw_output_report)(struct hid_device *hdev, __u8 *buf, size_t len, 73 - __u64 source, bool from_bpf); 73 + u64 source, bool from_bpf); 74 74 int (*hid_input_report)(struct hid_device *hid, enum hid_report_type type, 75 75 u8 *data, u32 size, int interrupt, u64 source, bool from_bpf, 76 76 bool lock_already_taken); ··· 115 115 * Context: Interrupt context. 116 116 */ 117 117 int (*hid_device_event)(struct hid_bpf_ctx *ctx, enum hid_report_type report_type, 118 - __u64 source); 118 + u64 source); 119 119 120 120 /** 121 121 * @hid_rdesc_fixup: called when the probe function parses the report descriptor