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

drm/amd/amdgpu: Fix missing null check in atombios_i2c.c

Reported by smatch:
amdgpu_atombios_i2c_process_i2c_ch() error: we previously assumed 'buf' could be null

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Ernst Sjöstrand <ernstp@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Ernst Sjöstrand and committed by
Alex Deucher
7d033100 e9c227b2

+9 -2
+9 -2
drivers/gpu/drm/amd/amdgpu/atombios_i2c.c
··· 65 65 args.ucRegIndex = buf[0]; 66 66 if (num) 67 67 num--; 68 - if (num) 69 - memcpy(&out, &buf[1], num); 68 + if (num) { 69 + if (buf) { 70 + memcpy(&out, &buf[1], num); 71 + } else { 72 + DRM_ERROR("hw i2c: missing buf with num > 1\n"); 73 + r = -EINVAL; 74 + goto done; 75 + } 76 + } 70 77 args.lpI2CDataOut = cpu_to_le16(out); 71 78 } else { 72 79 if (num > ATOM_MAX_HW_I2C_READ) {