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

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>

authored by

Jordan Crouse and committed by
Andy Gross
e0f2cfeb 8c1919a2

+14 -1
+14 -1
drivers/soc/qcom/llcc-slice.c
··· 96 96 */ 97 97 void llcc_slice_putd(struct llcc_slice_desc *desc) 98 98 { 99 - kfree(desc); 99 + if (!IS_ERR_OR_NULL(desc)) 100 + kfree(desc); 100 101 } 101 102 EXPORT_SYMBOL_GPL(llcc_slice_putd); 102 103 ··· 144 143 int ret; 145 144 u32 act_ctrl_val; 146 145 146 + if (IS_ERR_OR_NULL(desc)) 147 + return -EINVAL; 148 + 147 149 mutex_lock(&drv_data->lock); 148 150 if (test_bit(desc->slice_id, drv_data->bitmap)) { 149 151 mutex_unlock(&drv_data->lock); ··· 181 177 u32 act_ctrl_val; 182 178 int ret; 183 179 180 + if (IS_ERR_OR_NULL(desc)) 181 + return -EINVAL; 182 + 184 183 mutex_lock(&drv_data->lock); 185 184 if (!test_bit(desc->slice_id, drv_data->bitmap)) { 186 185 mutex_unlock(&drv_data->lock); ··· 211 204 */ 212 205 int llcc_get_slice_id(struct llcc_slice_desc *desc) 213 206 { 207 + if (IS_ERR_OR_NULL(desc)) 208 + return -EINVAL; 209 + 214 210 return desc->slice_id; 215 211 } 216 212 EXPORT_SYMBOL_GPL(llcc_get_slice_id); ··· 224 214 */ 225 215 size_t llcc_get_slice_size(struct llcc_slice_desc *desc) 226 216 { 217 + if (IS_ERR_OR_NULL(desc)) 218 + return 0; 219 + 227 220 return desc->slice_size; 228 221 } 229 222 EXPORT_SYMBOL_GPL(llcc_get_slice_size);