summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Crouse <jcrouse@codeaurora.org>2018-10-05 15:08:29 +0200
committerAndy Gross <andy.gross@linaro.org>2018-11-14 18:59:03 +0100
commite0f2cfeb59c81cbcfc7fbcb7ec0636020499813b (patch)
treefe997857155d9e83d67cf88e403879af6b3c8e24
parentsoc: qcom/llcc: add MODULE_LICENSE tag (diff)
downloadlinux-e0f2cfeb59c81cbcfc7fbcb7ec0636020499813b.tar.xz
linux-e0f2cfeb59c81cbcfc7fbcb7ec0636020499813b.zip
soc: qcom: llcc-slice: Add error checks for API functions
llcc_slice_getd can return a ERR_PTR code on failure. Add a IS_ERR_OR_NULL check to subsequent API calls that use struct llcc_slice_desc to guard against faults and to let the leaf drivers get away with safely using a ERR_PTR() encoded "pointer" in the aftermath of a llcc_slice_getd error. Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org> Reviewed-by: Vivek Gautam <vivek.gautam@codeaurora.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r--drivers/soc/qcom/llcc-slice.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/soc/qcom/llcc-slice.c b/drivers/soc/qcom/llcc-slice.c
index 7f55203d28d7..6a7d0162fe0e 100644
--- a/drivers/soc/qcom/llcc-slice.c
+++ b/drivers/soc/qcom/llcc-slice.c
@@ -96,7 +96,8 @@ EXPORT_SYMBOL_GPL(llcc_slice_getd);
*/
void llcc_slice_putd(struct llcc_slice_desc *desc)
{
- kfree(desc);
+ if (!IS_ERR_OR_NULL(desc))
+ kfree(desc);
}
EXPORT_SYMBOL_GPL(llcc_slice_putd);
@@ -143,6 +144,9 @@ int llcc_slice_activate(struct llcc_slice_desc *desc)
int ret;
u32 act_ctrl_val;
+ if (IS_ERR_OR_NULL(desc))
+ return -EINVAL;
+
mutex_lock(&drv_data->lock);
if (test_bit(desc->slice_id, drv_data->bitmap)) {
mutex_unlock(&drv_data->lock);
@@ -177,6 +181,9 @@ int llcc_slice_deactivate(struct llcc_slice_desc *desc)
u32 act_ctrl_val;
int ret;
+ if (IS_ERR_OR_NULL(desc))
+ return -EINVAL;
+
mutex_lock(&drv_data->lock);
if (!test_bit(desc->slice_id, drv_data->bitmap)) {
mutex_unlock(&drv_data->lock);
@@ -204,6 +211,9 @@ EXPORT_SYMBOL_GPL(llcc_slice_deactivate);
*/
int llcc_get_slice_id(struct llcc_slice_desc *desc)
{
+ if (IS_ERR_OR_NULL(desc))
+ return -EINVAL;
+
return desc->slice_id;
}
EXPORT_SYMBOL_GPL(llcc_get_slice_id);
@@ -214,6 +224,9 @@ EXPORT_SYMBOL_GPL(llcc_get_slice_id);
*/
size_t llcc_get_slice_size(struct llcc_slice_desc *desc)
{
+ if (IS_ERR_OR_NULL(desc))
+ return 0;
+
return desc->slice_size;
}
EXPORT_SYMBOL_GPL(llcc_get_slice_size);