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

hwspinlock: Fix incorrect return pointers

The commit 4f1acd758b08 ("hwspinlock: Add devm_xxx() APIs to request/free
hwlock") introduces one bug, that will return one error pointer if failed
to request one hwlock, but we expect NULL pointer on error for consumers.
This patch will fix this issue.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

authored by

Baolin Wang and committed by
Bjorn Andersson
ddb34f48 c8d04989

+4 -4
+4 -4
drivers/hwspinlock/hwspinlock_core.c
··· 877 877 878 878 ptr = devres_alloc(devm_hwspin_lock_release, sizeof(*ptr), GFP_KERNEL); 879 879 if (!ptr) 880 - return ERR_PTR(-ENOMEM); 880 + return NULL; 881 881 882 882 hwlock = hwspin_lock_request(); 883 - if (!IS_ERR(hwlock)) { 883 + if (hwlock) { 884 884 *ptr = hwlock; 885 885 devres_add(dev, ptr); 886 886 } else { ··· 913 913 914 914 ptr = devres_alloc(devm_hwspin_lock_release, sizeof(*ptr), GFP_KERNEL); 915 915 if (!ptr) 916 - return ERR_PTR(-ENOMEM); 916 + return NULL; 917 917 918 918 hwlock = hwspin_lock_request_specific(id); 919 - if (!IS_ERR(hwlock)) { 919 + if (hwlock) { 920 920 *ptr = hwlock; 921 921 devres_add(dev, ptr); 922 922 } else {