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

gnss: sirf: fix error return code in sirf_probe()

Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

This avoids a use-after-free in case the driver is later unbound.

Fixes: d2efbbd18b1e ("gnss: add driver for sirfstar-based receivers")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
[ johan: amend commit message; mention potential use-after-free ]
Cc: stable <stable@vger.kernel.org> # 4.19
Signed-off-by: Johan Hovold <johan@kernel.org>

authored by

Wei Yongjun and committed by
Johan Hovold
43d7ce70 2ef96a5b

+6 -2
+6 -2
drivers/gnss/sirf.c
··· 439 439 440 440 data->on_off = devm_gpiod_get_optional(dev, "sirf,onoff", 441 441 GPIOD_OUT_LOW); 442 - if (IS_ERR(data->on_off)) 442 + if (IS_ERR(data->on_off)) { 443 + ret = PTR_ERR(data->on_off); 443 444 goto err_put_device; 445 + } 444 446 445 447 if (data->on_off) { 446 448 data->wakeup = devm_gpiod_get_optional(dev, "sirf,wakeup", 447 449 GPIOD_IN); 448 - if (IS_ERR(data->wakeup)) 450 + if (IS_ERR(data->wakeup)) { 451 + ret = PTR_ERR(data->wakeup); 449 452 goto err_put_device; 453 + } 450 454 451 455 ret = regulator_enable(data->vcc); 452 456 if (ret)