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

can: softing: Fix potential memory leak in softing_load_fw()

Do not leak memory by updating pointer with potentially NULL realloc return value.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Alexey Khoroshilov and committed by
Marc Kleine-Budde
ef813c41 a0dfb263

+4 -3
+4 -3
drivers/net/can/softing/softing_fw.c
··· 150 150 const uint8_t *mem, *end, *dat; 151 151 uint16_t type, len; 152 152 uint32_t addr; 153 - uint8_t *buf = NULL; 153 + uint8_t *buf = NULL, *new_buf; 154 154 int buflen = 0; 155 155 int8_t type_end = 0; 156 156 ··· 199 199 if (len > buflen) { 200 200 /* align buflen */ 201 201 buflen = (len + (1024-1)) & ~(1024-1); 202 - buf = krealloc(buf, buflen, GFP_KERNEL); 203 - if (!buf) { 202 + new_buf = krealloc(buf, buflen, GFP_KERNEL); 203 + if (!new_buf) { 204 204 ret = -ENOMEM; 205 205 goto failed; 206 206 } 207 + buf = new_buf; 207 208 } 208 209 /* verify record data */ 209 210 memcpy_fromio(buf, &dpram[addr + offset], len);