From patchwork Fri Oct 5 13:08:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sharat Masetty X-Patchwork-Id: 10628019 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E0F71515 for ; Fri, 5 Oct 2018 13:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC975290F3 for ; Fri, 5 Oct 2018 13:08:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0E8529104; Fri, 5 Oct 2018 13:08:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85AF9290F3 for ; Fri, 5 Oct 2018 13:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbeJEUH1 (ORCPT ); Fri, 5 Oct 2018 16:07:27 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51668 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727733AbeJEUH0 (ORCPT ); Fri, 5 Oct 2018 16:07:26 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2AFE660C63; Fri, 5 Oct 2018 13:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1538744927; bh=wXu4dIPgV5pFyjrXhdosShO9LaZEbOdeBTECG0NPiMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f6HvJ48bTr1WM7kzUb1wZP6HfBKqo+2X/I6TvBb5GW5jZ0EWvzejB3wO8XDa/6g6q s600ZVeetH7E6Q4tntqTQ9EwJZL7xoqlpU0Ia5bZoXGWJ+fxPfmVaZATYzozXSyBJv TuoX9Doth10eQGifCO3MZhMHF0Oz1DN2KwQD4dmU= Received: from smasetty-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: smasetty@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 037DC607A2; Fri, 5 Oct 2018 13:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1538744926; bh=wXu4dIPgV5pFyjrXhdosShO9LaZEbOdeBTECG0NPiMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WZqg3sxA1OqTihzpvT6f1b6S6Y0QiN78JTbLaqA1BdZiSpCfRZG3S+Of9DOxcZxKT ElJxuLcvvJMOkVkjiUcMFk40mauQT7qqu9ku41ndtc9xof4rSOsLBrjfFQ3uDo4dF3 rBZE4Xa0VL9GMacazUIG6RofYbfusvsf8qHvvCe4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 037DC607A2 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=smasetty@codeaurora.org From: Sharat Masetty To: freedreno@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, jcrouse@codeaurora.org Subject: [v2 1/7] soc: qcom: llcc-slice: Add error checks for API functions Date: Fri, 5 Oct 2018 18:38:29 +0530 Message-Id: <1538744915-25490-2-git-send-email-smasetty@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538744915-25490-1-git-send-email-smasetty@codeaurora.org> References: <1538744915-25490-1-git-send-email-smasetty@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jordan Crouse 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 Reviewed-by: Vivek Gautam --- drivers/soc/qcom/llcc-slice.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/llcc-slice.c b/drivers/soc/qcom/llcc-slice.c index d789267..6a03e4e 100644 --- a/drivers/soc/qcom/llcc-slice.c +++ b/drivers/soc/qcom/llcc-slice.c @@ -94,7 +94,8 @@ struct llcc_slice_desc *llcc_slice_getd(u32 uid) */ 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); @@ -141,6 +142,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); @@ -175,6 +179,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); @@ -202,6 +209,9 @@ int llcc_slice_deactivate(struct llcc_slice_desc *desc) */ 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); @@ -212,6 +222,9 @@ int llcc_get_slice_id(struct llcc_slice_desc *desc) */ 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);