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

drm/i915/gt: Cleanup kasan warning for on-stack (unsigned long) casting

Kasan is gving a warning for passing a u32 parameter into find_first_bit
(casting to a unsigned long *, with appropriate length restrictions):

[ 44.678262] BUG: KASAN: stack-out-of-bounds in find_first_bit+0x2e/0x50
[ 44.678295] Read of size 8 at addr ffff888233f4fc30 by task core_hotunplug/474
[ 44.678326]
[ 44.678358] CPU: 0 PID: 474 Comm: core_hotunplug Not tainted 5.9.0+ #608
[ 44.678465] Hardware name: BESSTAR (HK) LIMITED GN41/Default string, BIOS BLT-BI-MINIPC-F4G-EX3R110-GA65A-101-D 10/12/2018
[ 44.678500] Call Trace:
[ 44.678534] dump_stack+0x84/0xba
[ 44.678569] print_address_description.constprop.0+0x21/0x220
[ 44.678605] ? kmsg_dump_rewind_nolock+0x5f/0x5f
[ 44.678638] ? _raw_spin_lock_irqsave+0x6d/0xb0
[ 44.678669] ? _raw_write_lock_irqsave+0xb0/0xb0
[ 44.678702] ? set_task_cpu+0x1e0/0x1e0
[ 44.678733] ? find_first_bit+0x2e/0x50
[ 44.678763] kasan_report.cold+0x20/0x42
[ 44.678794] ? find_first_bit+0x2e/0x50
[ 44.678825] __asan_load8+0x69/0x90
[ 44.678856] find_first_bit+0x2e/0x50
[ 44.679027] __caps_show.isra.0+0x9e/0x1f0 [i915]

Since we are only using the shorter type for our own convenience,
accommodate kasan and use unsigned long.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201013110845.16127-1-chris@chris-wilson.co.uk

+3 -7
+3 -7
drivers/gpu/drm/i915/gt/sysfs_engines.c
··· 79 79 80 80 static ssize_t 81 81 __caps_show(struct intel_engine_cs *engine, 82 - u32 caps, char *buf, bool show_unknown) 82 + unsigned long caps, char *buf, bool show_unknown) 83 83 { 84 84 const char * const *repr; 85 85 int count, n; 86 86 ssize_t len; 87 - 88 - BUILD_BUG_ON(!typecheck(typeof(caps), engine->uabi_capabilities)); 89 87 90 88 switch (engine->class) { 91 89 case VIDEO_DECODE_CLASS: ··· 101 103 count = 0; 102 104 break; 103 105 } 104 - GEM_BUG_ON(count > BITS_PER_TYPE(typeof(caps))); 106 + GEM_BUG_ON(count > BITS_PER_LONG); 105 107 106 108 len = 0; 107 - for_each_set_bit(n, 108 - (unsigned long *)&caps, 109 - show_unknown ? BITS_PER_TYPE(typeof(caps)) : count) { 109 + for_each_set_bit(n, &caps, show_unknown ? BITS_PER_LONG : count) { 110 110 if (n >= count || !repr[n]) { 111 111 if (GEM_WARN_ON(show_unknown)) 112 112 len += snprintf(buf + len, PAGE_SIZE - len,