From patchwork Fri Jul 21 12:46:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13321961 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29C98EB64DC for ; Fri, 21 Jul 2023 12:47:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbjGUMr2 (ORCPT ); Fri, 21 Jul 2023 08:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231136AbjGUMrX (ORCPT ); Fri, 21 Jul 2023 08:47:23 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D48BC2D58 for ; Fri, 21 Jul 2023 05:47:08 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1b9cdef8619so12900735ad.0 for ; Fri, 21 Jul 2023 05:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689943628; x=1690548428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zOhQoPjGrp3aso+jrzR34u3Ml2QJYToj9I27g4uhl+E=; b=sLt6bNbNO5+X1FVNrje31z+kzhAtTrYWfTf5ak1d8fmUA7BIhfftjsIIEBLVnc8dLe zroqTQt12W9Le2eqkqBzLc/YbS8Xqo/rxK6KRAuZySb/LGilDP4A16Oslzp8ZqB4fubB QNWnyGSK3/p9z9HwfCb3NvQblxoH2QjVDol04bz5aX+GXEwmkTmTmdyCwrQjtqlnsocf i23s6sLnswwIeIgsRtHpOZiLrcnk2CaPubUmpOrwMzQdmge3kjwOnikBb3cf4K9JMrZF IG9YgqpKp9cQOfkEdjq50lJclhMpknUtxbisbP3OdznFHvqRm4hu2D3Ts44iuxcbFUns DANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689943628; x=1690548428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zOhQoPjGrp3aso+jrzR34u3Ml2QJYToj9I27g4uhl+E=; b=FGlrBnSaqTq/CPk7/iZGwR7qbAgflRVfV8Gf5PEI7lAzMBHrbQDJ4uElvi9up95ZZy oZa4n+hLgVg2eVUmgsDS4h8+FzjCa/bnKe1FLnmkn/Od49Q+X9sFrO5WgfP5grPczG8a 7inpgBLFKPZQhWeA98t1so9usCh633wbItVPVt04HTYideM5WZWHR5Oe5XcdlW0JmGdR bqBNEwngz8ARE/RTFD7qj6PMmMzhCsMVyPZ9SBZIJ2XoNuO2C74muplwWQeF+3FqoBvu HQtbscTLWahoiU9ymwXkN97MF25pqJKm/pjwi6JenifqPrRy7fTDfSakOr3StHqONdUH HCpg== X-Gm-Message-State: ABy/qLYBG5jGiXej+nDstcJFc9lxDdKkCwxutABcax1WkuVeOhUZnLdX GNVbu4X8cb9uweGSoxpkyLg1 X-Google-Smtp-Source: APBJJlEdCdJ54RYTf2M0lyVjCXwtHC0oYWc7MxLH34VQXUF+B57CezarbfLcluW1zYrN+qI7GF9Axg== X-Received: by 2002:a17:902:c409:b0:1b8:918d:ac48 with SMTP id k9-20020a170902c40900b001b8918dac48mr1894397plk.56.1689943628161; Fri, 21 Jul 2023 05:47:08 -0700 (PDT) Received: from localhost.localdomain ([117.206.118.181]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001b8b2fb52d4sm3369828plb.203.2023.07.21.05.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 05:46:57 -0700 (PDT) From: Manivannan Sadhasivam To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH 1/2] OPP: Fix potential null ptr dereference in dev_pm_opp_get_required_pstate() Date: Fri, 21 Jul 2023 18:16:33 +0530 Message-Id: <20230721124634.63612-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721124634.63612-1-manivannan.sadhasivam@linaro.org> References: <20230721124634.63612-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org "opp" pointer is dereferenced before the IS_ERR_OR_NULL() check. Fix it by removing the dereference to cache opp_table and dereference it directly where opp_table is used. This fixes the following smatch warning: drivers/opp/core.c:232 dev_pm_opp_get_required_pstate() warn: variable dereferenced before IS_ERR check 'opp' (see line 230) Fixes: 84cb7ff35fcf ("OPP: pstate is only valid for genpd OPP tables") Signed-off-by: Manivannan Sadhasivam --- drivers/opp/core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 3f46e499d615..98633ccd170a 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -227,20 +227,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_level); unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, unsigned int index) { - struct opp_table *opp_table = opp->opp_table; - if (IS_ERR_OR_NULL(opp) || !opp->available || - index >= opp_table->required_opp_count) { + index >= opp->opp_table->required_opp_count) { pr_err("%s: Invalid parameters\n", __func__); return 0; } /* required-opps not fully initialized yet */ - if (lazy_linking_pending(opp_table)) + if (lazy_linking_pending(opp->opp_table)) return 0; /* The required OPP table must belong to a genpd */ - if (unlikely(!opp_table->required_opp_tables[index]->is_genpd)) { + if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) { pr_err("%s: Performance state is only valid for genpds.\n", __func__); return 0; } From patchwork Fri Jul 21 12:46:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13321962 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF38DEB64DD for ; Fri, 21 Jul 2023 12:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjGUMrf (ORCPT ); Fri, 21 Jul 2023 08:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbjGUMr0 (ORCPT ); Fri, 21 Jul 2023 08:47:26 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E1A3A82 for ; Fri, 21 Jul 2023 05:47:13 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b8bbcfd89aso11428295ad.1 for ; Fri, 21 Jul 2023 05:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689943633; x=1690548433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d4/eRoqwSAGdi8LJemKHI/V1OYM9+swXufBrZM0hUXk=; b=yFN3/VyHs01yi924BoKQA3rrgUaD/Hl40Ot0j1gpDRx8j29mKVke8EQvqAdLCaQK4M 6f/l8ErfCvpGw5LQz/pZ3hjukF7r4W5iVON++Vf79UYo0WmTMnAYbYiGEycqWmdA12ex TciPBsADja5tXbs8y9Uz4bmZ6M34xoiPNRlaF/Wyhku9Dpx5XcuSndO5MIyTelSDWo7m spITXGKc6NN1OMKi7e+1/XE78Lstba3baS5pBazCY6r8aa2wCN3jPKZMNhWZo3GnhTCf QNhdJWhkXOmC7Cpyj8PoynwM48Px4H3uYHPxtug+Cc/QpumNbJ52USlirX5bijsDp2Bn jpBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689943633; x=1690548433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d4/eRoqwSAGdi8LJemKHI/V1OYM9+swXufBrZM0hUXk=; b=Cw50DSc/P/Pkb11zJFSZweCwM3XQukYrrxMSm0ubzdA31SXm3R7ZllQCm1Gpsy6oV7 YOmFrsBNOksGKmTTEokF5nW6QonC1wcc7daqIoiLWcY2F1aAV2XHxE5+XHxWQAcxYI4O RJok1Hf01aN8rnNLqw8DTbOWVU/2liJPB0dLoZo3YZ+tBcTX4J1o1srdu4mkn5bNtw7M BvRGedzL5mds8APpRNIDxBPKD5qqtE0sDWCHBpS/jTonfAzq0FC3a1TTIealT2QC1w+A RO094ZJiWmQ5Z6Zq9kwBB5guEoZfsHiLy3GZTbCKiKqK5sN9RAHj35duJbxvKDuAOPJw 0WHA== X-Gm-Message-State: ABy/qLa3pajf8+uIueI5XyI1XSj5UIjgk4z2ZGPXjxHL8Chvqiv9BZNT q41xjf53gjGk5nXfRkJb/h7H X-Google-Smtp-Source: APBJJlEVBYU2bNbC3uokjbALDALmMS2/XNNHqv6ry6lL/rTHYP0iAZpZI/LXnzDkoB4IkkGjt0gAsA== X-Received: by 2002:a17:903:110c:b0:1b8:525a:f685 with SMTP id n12-20020a170903110c00b001b8525af685mr1631050plh.37.1689943633295; Fri, 21 Jul 2023 05:47:13 -0700 (PDT) Received: from localhost.localdomain ([117.206.118.181]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001b8b2fb52d4sm3369828plb.203.2023.07.21.05.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 05:47:11 -0700 (PDT) From: Manivannan Sadhasivam To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH 2/2] OPP: Fix passing 0 to PTR_ERR in _opp_attach_genpd() Date: Fri, 21 Jul 2023 18:16:34 +0530 Message-Id: <20230721124634.63612-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721124634.63612-1-manivannan.sadhasivam@linaro.org> References: <20230721124634.63612-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org If dev_pm_domain_attach_by_name() returns NULL, then 0 will be passed to PTR_ERR() as reported by the smatch warning below: drivers/opp/core.c:2456 _opp_attach_genpd() warn: passing zero to 'PTR_ERR' Fix it by checking for the non-NULL virt_dev pointer before passing it to PTR_ERR. Otherwise return -ENODEV. Fixes: 4ea9496cbc95 ("opp: Fix error check in dev_pm_opp_attach_genpd()") Signed-off-by: Manivannan Sadhasivam --- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 98633ccd170a..ae359ed6a161 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2377,7 +2377,7 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, virt_dev = dev_pm_domain_attach_by_name(dev, *name); if (IS_ERR_OR_NULL(virt_dev)) { - ret = PTR_ERR(virt_dev) ? : -ENODEV; + ret = virt_dev ? PTR_ERR(virt_dev) : -ENODEV; dev_err(dev, "Couldn't attach to pm_domain: %d\n", ret); goto err; }