Re: AMD, please run Smatch on your driver

2017-11-07 Thread Harry Wentland
Thanks, Dan, for bringing this to our attention. We (the display guys here) 
weren't aware of smatch and will give it a spin and try to address some of the 
remaining items (after your, Dave's, and Ernst's patches).

Harry

On 2017-11-06 06:34 AM, Dan Carpenter wrote:
> Linux-next was offline for the last month and the AMD drm driver went
> through major changes.  Anyway, I'm a bit overwhelmed by the number of
> warnings and I'm not going to be able to go through them all so I'm just
> sending them to you unfiltered.
> 
> Part of the problem is that I'm not running the released version of
> Smatch myself.  That has two effects.  1) The released version is
> crappier than I had imagined.  2) I get *way* more warnings than you see
> which is overwhelming...  So this is mostly my fault and I will try to
> do better.
> 
> Here are the current warnings from Friday's linux-next, lightly edited.
> I know that everyone hates a big dump of static checker warnings...
> Speaking of being ignored, I sent a fix for this one back in August but
> never heard back:
> 
>   drivers/gpu/drm/amd/amdgpu/ci_dpm.c:4553 ci_set_mc_special_registers()
>   error: buffer overflow 'table->mc_reg_address' 16 <= 16
> 
> https://lists.freedesktop.org/archives/amd-gfx/2017-August/012333.html
> 
> So this is partly your fault as well because if you cleaned up static
> checker warnings little by little, then they wouldn't pile up like this.
> Eventually, everyone is going to have to start running Smatch for
> themselves because it scales better than relying on me to do it.
> 
> regards,
> dan carpenter
> 
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:2224 amdgpu_device_init() warn: 
> 'adev->rio_mem' was not released on error
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:2395 amdgpu_device_init() warn: 
> 'adev->rio_mem' was not released on error
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3373 amdgpu_debugfs_regs_write() 
> warn: 'mutex:&adev->pm.mutex' is sometimes locked here and sometimes unlocked.
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3377 amdgpu_debugfs_regs_write() 
> warn: 'mutex:&adev->pm.mutex' is sometimes locked here and sometimes unlocked.
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3771 amdgpu_debugfs_gpr_read() 
> error: buffer overflow 'data' 1024 <= 4095
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c:155 amdgpu_driver_load_kms() warn: we 
> tested 'r' before and it was 'false'
> drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:689 amdgpu_gem_op_ioctl() warn: 
> should 'robj->tbo.mem.page_alignment << 12' be a 64 bit type?
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:196 amdgpu_cs_parser_init() warn: 
> 'mutex:&p->ctx->lock' is sometimes locked here and sometimes unlocked.
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:674 amdgpu_cs_parser_bos() warn: we 
> tested 'r' before and it was 'false'
> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:755 amdgpu_cs_parser_fini() warn: 
> 'mutex:&parser->ctx->lock' is sometimes locked here and sometimes unlocked.
> drivers/gpu/drm/amd/amdgpu/atombios_i2c.c:72 
> amdgpu_atombios_i2c_process_i2c_ch() warn: impossible condition '(num > 255) 
> => (0-255 > 255)'
> drivers/gpu/drm/amd/amdgpu/amdgpu_queue_mgr.c:217 amdgpu_queue_mgr_map() 
> warn: variable dereferenced before check 'mgr' (see line 215)
> drivers/gpu/drm/amd/amdgpu/kv_dpm.c:1618 kv_get_acp_boot_level() warn: always 
> true condition '(table->entries[i]->clk >= 0) => (0-u32max >= 0)'
> drivers/gpu/drm/amd/amdgpu/ci_dpm.c:4560 ci_set_mc_special_registers() error: 
> buffer overflow 'table->mc_reg_address' 16 <= 16
> drivers/gpu/drm/amd/amdgpu/ci_dpm.c:5065 
> ci_request_link_speed_change_before_state_change() warn: missing break? 
> reassigning 'pi->force_pcie_gen'
> drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c:5256 gfx_v7_0_get_cu_info() error: 
> buffer overflow 'cu_info->bitmap' 4 <= 4
> drivers/gpu/drm/amd/amdgpu/si.c:1288 si_common_early_init() warn: 
> inconsistent indenting
> drivers/gpu/drm/amd/amdgpu/dce_v6_0.c:3026 dce_v6_0_pageflip_irq() warn: 
> inconsistent indenting
> drivers/gpu/drm/amd/amdgpu/si_dpm.c:6242 
> si_request_link_speed_change_before_state_change() warn: missing break? 
> reassigning 'si_pi->force_pcie_gen'
> drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c:5222 gfx_v8_0_pre_soft_reset() warn: 
> inconsistent indenting
> drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c:7105 gfx_v8_0_get_cu_info() error: 
> buffer overflow 'cu_info->bitmap' 4 <= 4
> drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:3077 gfx_v9_0_soft_reset() warn: we 
> tested 'grbm_soft_reset' before and it was 'true'
> drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:3644 gfx_v9_0_ring_emit_ib_gfx() warn: 
> inconsistent indenting
> drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:4457 gfx_v9_0_get_cu_info() error: 
> buffer overflow 'cu_info->bitmap' 4 <= 4
> drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c:605 amdgpu_cgs_lock_grbm_idx() warn: 
> 'mutex:&adev->grbm_idx_mutex' is sometimes locked here and sometimes unlocked.
> drivers/gpu/drm/amd/amdgpu/../scheduler/gpu_scheduler.c:696 amd_sched_init() 
> warn: call of 'kthread_c

AMD, please run Smatch on your driver

2017-11-06 Thread Dan Carpenter
Linux-next was offline for the last month and the AMD drm driver went
through major changes.  Anyway, I'm a bit overwhelmed by the number of
warnings and I'm not going to be able to go through them all so I'm just
sending them to you unfiltered.

Part of the problem is that I'm not running the released version of
Smatch myself.  That has two effects.  1) The released version is
crappier than I had imagined.  2) I get *way* more warnings than you see
which is overwhelming...  So this is mostly my fault and I will try to
do better.

Here are the current warnings from Friday's linux-next, lightly edited.
I know that everyone hates a big dump of static checker warnings...
Speaking of being ignored, I sent a fix for this one back in August but
never heard back:

  drivers/gpu/drm/amd/amdgpu/ci_dpm.c:4553 ci_set_mc_special_registers()
  error: buffer overflow 'table->mc_reg_address' 16 <= 16

https://lists.freedesktop.org/archives/amd-gfx/2017-August/012333.html

So this is partly your fault as well because if you cleaned up static
checker warnings little by little, then they wouldn't pile up like this.
Eventually, everyone is going to have to start running Smatch for
themselves because it scales better than relying on me to do it.

regards,
dan carpenter

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:2224 amdgpu_device_init() warn: 
'adev->rio_mem' was not released on error
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:2395 amdgpu_device_init() warn: 
'adev->rio_mem' was not released on error
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3373 amdgpu_debugfs_regs_write() 
warn: 'mutex:&adev->pm.mutex' is sometimes locked here and sometimes unlocked.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3377 amdgpu_debugfs_regs_write() 
warn: 'mutex:&adev->pm.mutex' is sometimes locked here and sometimes unlocked.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:3771 amdgpu_debugfs_gpr_read() 
error: buffer overflow 'data' 1024 <= 4095
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c:155 amdgpu_driver_load_kms() warn: we 
tested 'r' before and it was 'false'
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:689 amdgpu_gem_op_ioctl() warn: should 
'robj->tbo.mem.page_alignment << 12' be a 64 bit type?
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:196 amdgpu_cs_parser_init() warn: 
'mutex:&p->ctx->lock' is sometimes locked here and sometimes unlocked.
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:674 amdgpu_cs_parser_bos() warn: we 
tested 'r' before and it was 'false'
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:755 amdgpu_cs_parser_fini() warn: 
'mutex:&parser->ctx->lock' is sometimes locked here and sometimes unlocked.
drivers/gpu/drm/amd/amdgpu/atombios_i2c.c:72 
amdgpu_atombios_i2c_process_i2c_ch() warn: impossible condition '(num > 255) => 
(0-255 > 255)'
drivers/gpu/drm/amd/amdgpu/amdgpu_queue_mgr.c:217 amdgpu_queue_mgr_map() warn: 
variable dereferenced before check 'mgr' (see line 215)
drivers/gpu/drm/amd/amdgpu/kv_dpm.c:1618 kv_get_acp_boot_level() warn: always 
true condition '(table->entries[i]->clk >= 0) => (0-u32max >= 0)'
drivers/gpu/drm/amd/amdgpu/ci_dpm.c:4560 ci_set_mc_special_registers() error: 
buffer overflow 'table->mc_reg_address' 16 <= 16
drivers/gpu/drm/amd/amdgpu/ci_dpm.c:5065 
ci_request_link_speed_change_before_state_change() warn: missing break? 
reassigning 'pi->force_pcie_gen'
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c:5256 gfx_v7_0_get_cu_info() error: buffer 
overflow 'cu_info->bitmap' 4 <= 4
drivers/gpu/drm/amd/amdgpu/si.c:1288 si_common_early_init() warn: inconsistent 
indenting
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c:3026 dce_v6_0_pageflip_irq() warn: 
inconsistent indenting
drivers/gpu/drm/amd/amdgpu/si_dpm.c:6242 
si_request_link_speed_change_before_state_change() warn: missing break? 
reassigning 'si_pi->force_pcie_gen'
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c:5222 gfx_v8_0_pre_soft_reset() warn: 
inconsistent indenting
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c:7105 gfx_v8_0_get_cu_info() error: buffer 
overflow 'cu_info->bitmap' 4 <= 4
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:3077 gfx_v9_0_soft_reset() warn: we 
tested 'grbm_soft_reset' before and it was 'true'
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:3644 gfx_v9_0_ring_emit_ib_gfx() warn: 
inconsistent indenting
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c:4457 gfx_v9_0_get_cu_info() error: buffer 
overflow 'cu_info->bitmap' 4 <= 4
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c:605 amdgpu_cgs_lock_grbm_idx() warn: 
'mutex:&adev->grbm_idx_mutex' is sometimes locked here and sometimes unlocked.
drivers/gpu/drm/amd/amdgpu/../scheduler/gpu_scheduler.c:696 amd_sched_init() 
warn: call of 'kthread_create_on_node' with non-constant format argument
drivers/gpu/drm/amd/amdgpu/../powerplay/smumgr/tonga_smumgr.c:3128 
tonga_set_mc_special_registers() error: buffer overflow 'table->mc_reg_address' 
16 <= 16
drivers/gpu/drm/amd/amdgpu/../powerplay/smumgr/polaris10_smumgr.c:916 
polaris10_calculate_sclk_params() warn: should 'clock << 
table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv' be a 64 bit type?
drivers/gpu/drm/amd/amdgp