From patchwork Tue Oct 3 15:29:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 730464 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 0B091E7AD6E for ; Tue, 3 Oct 2023 15:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237251AbjJCP3k (ORCPT ); Tue, 3 Oct 2023 11:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbjJCP3i (ORCPT ); Tue, 3 Oct 2023 11:29:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5103695; Tue, 3 Oct 2023 08:29:35 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1D75C433C8; Tue, 3 Oct 2023 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696346974; bh=tuSq7yhyHWSvaiKeFaqV7WZhQUAQixug8q4HdZYlAno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtpKhBPfJ74lU82drgA2oKf+YX3mFR/c11kgGMzndTWpPgOi2hEmENkWW/RUWIKv/ oh5Dc+skDITF3WJQnuoVlHm6/mVWDpQkP0KirEUByb3CB8vIdg1p6Fi22woNdGNiN9 co1KQ++cpjOaRrFfa9mbrrixxxpW1IO4bUCFUzx2a9zr1lZVVEK0+AqM/LzJjKKdqY 94P4HEV9pQQq0kFDPiZjWyPVo8TUZHU/d/LN6AXLrgRclPZV2MdYQ8T6IbkQ/BvcYa 2RHOoi0f+7TTAzD7U84ETiymULbdd37n79WUMPjOY/K/rh3LbCMLgDFuBxIZpVqfeS 176Y8xHTs98QQ== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qnhLF-0003uL-2L; Tue, 03 Oct 2023 17:29:45 +0200 From: Johan Hovold To: Lee Jones Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Stephen Boyd , Caleb Connolly , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH 1/5] mfd: qcom-spmi-pmic: fix reference leaks in revid helper Date: Tue, 3 Oct 2023 17:29:23 +0200 Message-ID: <20231003152927.15000-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003152927.15000-1-johan+linaro@kernel.org> References: <20231003152927.15000-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The Qualcomm SPMI PMIC revid implementation is broken in multiple ways. First, it totally ignores struct device_node reference counting and leaks references to the parent bus node as well as each child it iterates over using an open-coded for_each_child_of_node(). Second, it leaks references to each spmi device on the bus that it iterates over by failing to drop the reference taken by the spmi_device_from_of() helper. Fix the struct device_node leaks by reimplementing the lookup using for_each_child_of_node() and adding the missing reference count decrements. Fix the sibling struct device leaks by dropping the unnecessary lookups of devices with the wrong USID. Note that this still leaves one struct device reference leak in case a base device is found but it is not the parent of the device used for the lookup. This will be addressed in a follow-on patch. Fixes: e9c11c6e3a0e ("mfd: qcom-spmi-pmic: expose the PMIC revid information to clients") Cc: stable@vger.kernel.org # 6.0 Cc: Caleb Connolly Cc: Dmitry Baryshkov Signed-off-by: Johan Hovold --- drivers/mfd/qcom-spmi-pmic.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c index 7e2cd79d17eb..47738f7e492c 100644 --- a/drivers/mfd/qcom-spmi-pmic.c +++ b/drivers/mfd/qcom-spmi-pmic.c @@ -81,7 +81,7 @@ static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) struct spmi_device *sdev; struct qcom_spmi_dev *ctx; struct device_node *spmi_bus; - struct device_node *other_usid = NULL; + struct device_node *child; int function_parent_usid, ret; u32 pmic_addr; @@ -105,28 +105,34 @@ static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) * device for USID 2. */ spmi_bus = of_get_parent(sdev->dev.of_node); - do { - other_usid = of_get_next_child(spmi_bus, other_usid); - - ret = of_property_read_u32_index(other_usid, "reg", 0, &pmic_addr); - if (ret) - return ERR_PTR(ret); + sdev = ERR_PTR(-ENODATA); + for_each_child_of_node(spmi_bus, child) { + ret = of_property_read_u32_index(child, "reg", 0, &pmic_addr); + if (ret) { + of_node_put(child); + sdev = ERR_PTR(ret); + break; + } - sdev = spmi_device_from_of(other_usid); if (pmic_addr == function_parent_usid - (ctx->num_usids - 1)) { - if (!sdev) + sdev = spmi_device_from_of(child); + if (!sdev) { /* * If the base USID for this PMIC hasn't probed yet * but the secondary USID has, then we need to defer * the function driver so that it will attempt to * probe again when the base USID is ready. */ - return ERR_PTR(-EPROBE_DEFER); - return sdev; + sdev = ERR_PTR(-EPROBE_DEFER); + } + of_node_put(child); + break; } - } while (other_usid->sibling); + } + + of_node_put(spmi_bus); - return ERR_PTR(-ENODATA); + return sdev; } static int pmic_spmi_load_revid(struct regmap *map, struct device *dev, From patchwork Tue Oct 3 15:29:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 728859 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 4836AE7AD76 for ; Tue, 3 Oct 2023 15:29:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237132AbjJCP3j (ORCPT ); Tue, 3 Oct 2023 11:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbjJCP3i (ORCPT ); Tue, 3 Oct 2023 11:29:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E5BAB; Tue, 3 Oct 2023 08:29:35 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF7FAC433CB; Tue, 3 Oct 2023 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696346975; bh=w6oW3CA5lhvBRe2ooxRAdYwa2HiP0AiSXwLhfx4hsQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u/bqTduxmjG7fM8rnm8Fuso35m9V9ijdiz/GM66mSY81rVf16I8i2ceQn4yr41eKh hu5DQUBbpwSsvpG9fKoOBsXtgBcGTxIb4zDnOGGbdDDhAIpde18qyutjeClG78vm4X 3H7Pp3vrDinug7UMjQ4eazdvqczupeszGb+RtBDUtYgymoNchYMOkuEBN6Z8ZJ5nrX TBvyJJ8mZskREjk66lsGFGU1CJmn4FmhLvpZ+Bs6QmI05AzvnPswdEbpmcN/I7CPyB AIZtygRliI0v9KWrzXpagYIDHCcJrdSZtLPU1RWcIbgOlQfcZZm2ICUCL+QEbWzdVY SmhZUixDbKppw== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qnhLF-0003uN-2a; Tue, 03 Oct 2023 17:29:45 +0200 From: Johan Hovold To: Lee Jones Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Stephen Boyd , Caleb Connolly , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH 2/5] mfd: qcom-spmi-pmic: fix revid implementation Date: Tue, 3 Oct 2023 17:29:24 +0200 Message-ID: <20231003152927.15000-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003152927.15000-1-johan+linaro@kernel.org> References: <20231003152927.15000-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The Qualcomm SPMI PMIC revid implementation is broken in multiple ways. First, it assumes that just because the sibling base device has been registered that means that it is also bound to a driver, which may not be the case (e.g. due to probe deferral or asynchronous probe). This could trigger a NULL-pointer dereference when attempting to access the driver data of the unbound device. Second, it accesses driver data of a sibling device directly and without any locking, which means that the driver data may be freed while it is being accessed (e.g. on driver unbind). Third, it leaks a struct device reference to the sibling device which is looked up using the spmi_device_from_of() every time a function (child) device is calling the revid function (e.g. on probe). Fix this mess by reimplementing the revid lookup so that it is done only at probe of the PMIC device; the base device fetches the revid info from the hardware, while any secondary SPMI device fetches the information from the base device and caches it so that it can be accessed safely from its children. If the base device has not been probed yet then probe of a secondary device is deferred. Fixes: e9c11c6e3a0e ("mfd: qcom-spmi-pmic: expose the PMIC revid information to clients") Cc: stable@vger.kernel.org # 6.0 Cc: Caleb Connolly Cc: Dmitry Baryshkov Signed-off-by: Johan Hovold --- drivers/mfd/qcom-spmi-pmic.c | 69 +++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c index 47738f7e492c..8e449cff5cec 100644 --- a/drivers/mfd/qcom-spmi-pmic.c +++ b/drivers/mfd/qcom-spmi-pmic.c @@ -30,6 +30,8 @@ struct qcom_spmi_dev { struct qcom_spmi_pmic pmic; }; +static DEFINE_MUTEX(pmic_spmi_revid_lock); + #define N_USIDS(n) ((void *)n) static const struct of_device_id pmic_spmi_id_table[] = { @@ -76,24 +78,21 @@ static const struct of_device_id pmic_spmi_id_table[] = { * * This only supports PMICs with 1 or 2 USIDs. */ -static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) +static struct spmi_device *qcom_pmic_get_base_usid(struct spmi_device *sdev, struct qcom_spmi_dev *ctx) { - struct spmi_device *sdev; - struct qcom_spmi_dev *ctx; struct device_node *spmi_bus; struct device_node *child; int function_parent_usid, ret; u32 pmic_addr; - sdev = to_spmi_device(dev); - ctx = dev_get_drvdata(&sdev->dev); - /* * Quick return if the function device is already in the base * USID. This will always be hit for PMICs with only 1 USID. */ - if (sdev->usid % ctx->num_usids == 0) + if (sdev->usid % ctx->num_usids == 0) { + get_device(&sdev->dev); return sdev; + } function_parent_usid = sdev->usid; @@ -118,10 +117,8 @@ static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) sdev = spmi_device_from_of(child); if (!sdev) { /* - * If the base USID for this PMIC hasn't probed yet - * but the secondary USID has, then we need to defer - * the function driver so that it will attempt to - * probe again when the base USID is ready. + * If the base USID for this PMIC hasn't been + * registered yet then we need to defer. */ sdev = ERR_PTR(-EPROBE_DEFER); } @@ -135,6 +132,35 @@ static struct spmi_device *qcom_pmic_get_base_usid(struct device *dev) return sdev; } +static int pmic_spmi_get_base_revid(struct spmi_device *sdev, struct qcom_spmi_dev *ctx) +{ + struct qcom_spmi_dev *base_ctx; + struct spmi_device *base; + int ret = 0; + + base = qcom_pmic_get_base_usid(sdev, ctx); + if (IS_ERR(base)) + return PTR_ERR(base); + + /* + * Copy revid info from base device if it has probed and is still + * bound to its driver. + */ + mutex_lock(&pmic_spmi_revid_lock); + base_ctx = spmi_device_get_drvdata(base); + if (!base_ctx) { + ret = -EPROBE_DEFER; + goto out_unlock; + } + memcpy(&ctx->pmic, &base_ctx->pmic, sizeof(ctx->pmic)); +out_unlock: + mutex_unlock(&pmic_spmi_revid_lock); + + put_device(&base->dev); + + return ret; +} + static int pmic_spmi_load_revid(struct regmap *map, struct device *dev, struct qcom_spmi_pmic *pmic) { @@ -210,11 +236,7 @@ const struct qcom_spmi_pmic *qcom_pmic_get(struct device *dev) if (!of_match_device(pmic_spmi_id_table, dev->parent)) return ERR_PTR(-EINVAL); - sdev = qcom_pmic_get_base_usid(dev->parent); - - if (IS_ERR(sdev)) - return ERR_CAST(sdev); - + sdev = to_spmi_device(dev->parent); spmi = dev_get_drvdata(&sdev->dev); return &spmi->pmic; @@ -249,16 +271,31 @@ static int pmic_spmi_probe(struct spmi_device *sdev) ret = pmic_spmi_load_revid(regmap, &sdev->dev, &ctx->pmic); if (ret < 0) return ret; + } else { + ret = pmic_spmi_get_base_revid(sdev, ctx); + if (ret) + return ret; } + + mutex_lock(&pmic_spmi_revid_lock); spmi_device_set_drvdata(sdev, ctx); + mutex_unlock(&pmic_spmi_revid_lock); return devm_of_platform_populate(&sdev->dev); } +static void pmic_spmi_remove(struct spmi_device *sdev) +{ + mutex_lock(&pmic_spmi_revid_lock); + spmi_device_set_drvdata(sdev, NULL); + mutex_unlock(&pmic_spmi_revid_lock); +} + MODULE_DEVICE_TABLE(of, pmic_spmi_id_table); static struct spmi_driver pmic_spmi_driver = { .probe = pmic_spmi_probe, + .remove = pmic_spmi_remove, .driver = { .name = "pmic-spmi", .of_match_table = pmic_spmi_id_table, From patchwork Tue Oct 3 15:29:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 728858 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 C2493E7AD75 for ; Tue, 3 Oct 2023 15:29:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbjJCP3i (ORCPT ); Tue, 3 Oct 2023 11:29:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbjJCP3i (ORCPT ); Tue, 3 Oct 2023 11:29:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53781A7; Tue, 3 Oct 2023 08:29:35 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2069C433CC; Tue, 3 Oct 2023 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696346975; bh=HtTtHLoy/MEzOVrBl6HeLbM2k/FSWqbhpLx6b5+quR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HfH+56jDO4zxiShPdqoi4Vuh7ctOnxMEghAm0nReivKZMqBx8zLfJoZmmvdCTfwDJ shNDol7mXZvIwlj7eRp7r+RPzrUyCVyyYyMNUJKCFIQbXkTra8L3xGlgp4cvl6BhEt B0l3woOTIPyump/qHTMvJcgF5qY/KUeIgTR7mH/1G5/+p4GMP0KcOzU2oRQerw6AdR iZDYjBQe7qwuqc/wFGB/Iram0zn1nUamZXGu7n8sWwckC2G4X+Km1hbS243Czp9lnG k04k9ABPRCBhzBDS31TwTQ72/Y13glbigHYdJK/bqM8/qn0dVG0SXasSgImyRImqeM ob+CPFEkpC+dQ== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qnhLF-0003uP-2s; Tue, 03 Oct 2023 17:29:45 +0200 From: Johan Hovold To: Lee Jones Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Stephen Boyd , Caleb Connolly , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/5] mfd: qcom-spmi-pmic: switch to EXPORT_SYMBOL_GPL() Date: Tue, 3 Oct 2023 17:29:25 +0200 Message-ID: <20231003152927.15000-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003152927.15000-1-johan+linaro@kernel.org> References: <20231003152927.15000-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Switch to using EXPORT_SYMBOL_GPL() for the revid helper as there is no reason not to use it. Cc: Caleb Connolly Signed-off-by: Johan Hovold Reviewed-by: Konrad Dybcio --- drivers/mfd/qcom-spmi-pmic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c index 8e449cff5cec..ee55f09da3ba 100644 --- a/drivers/mfd/qcom-spmi-pmic.c +++ b/drivers/mfd/qcom-spmi-pmic.c @@ -241,7 +241,7 @@ const struct qcom_spmi_pmic *qcom_pmic_get(struct device *dev) return &spmi->pmic; } -EXPORT_SYMBOL(qcom_pmic_get); +EXPORT_SYMBOL_GPL(qcom_pmic_get); static const struct regmap_config spmi_regmap_config = { .reg_bits = 16, From patchwork Tue Oct 3 15:29:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 728857 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 3511EE7AD78 for ; Tue, 3 Oct 2023 15:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237805AbjJCP3l (ORCPT ); Tue, 3 Oct 2023 11:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232615AbjJCP3j (ORCPT ); Tue, 3 Oct 2023 11:29:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C4C683; Tue, 3 Oct 2023 08:29:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00D60C433CA; Tue, 3 Oct 2023 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696346975; bh=Ppt/g3Cl4BHkM08VzrqupcDO3feWwrL0moCYx1utEJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVm99Fa6ss1iQNSqspl+Urb3rwwwlivA0jCA8aOX7t/Mj27kTtZ+9oW6JEoQU/Hud WZsLqwUD+XHvM858bygzJNGZY/OToOnDry2MI5InxY3OBibFZu52ehILb2jIXVmbQy 1inWPIP4du8YG8DtLuurmK3YK2nIB9weWJxUGYV85lSeocB10FYxNNokA7CLcwZri/ 6TDmJolb02NDKMYarHu+UqI47KsAHf38wuvWIblb7KFwjfOSUO3aSt1UEtnNv5sc9D as/WnpfEhq6NwxquezjtLgY1YfwLr2kUjrLQIsMhWNBv8+sbu5VrdfdZQrzQ1qAYMx RQTCslknGew5g== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qnhLF-0003uR-38; Tue, 03 Oct 2023 17:29:46 +0200 From: Johan Hovold To: Lee Jones Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Stephen Boyd , Caleb Connolly , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/5] spmi: document spmi_device_from_of() refcounting Date: Tue, 3 Oct 2023 17:29:26 +0200 Message-ID: <20231003152927.15000-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003152927.15000-1-johan+linaro@kernel.org> References: <20231003152927.15000-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a comment documenting that the spmi_device_from_of() takes a reference to the embedded struct device that needs to be dropped after use. Signed-off-by: Johan Hovold Acked-by: Stephen Boyd --- drivers/spmi/spmi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c index 7313d4c18a04..ca2fd4d72fa6 100644 --- a/drivers/spmi/spmi.c +++ b/drivers/spmi/spmi.c @@ -392,6 +392,9 @@ static struct bus_type spmi_bus_type = { * * @np: device node * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * * Returns the struct spmi_device associated with a device node or NULL. */ struct spmi_device *spmi_device_from_of(struct device_node *np) From patchwork Tue Oct 3 15:29:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 730465 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 30FACE7AD77 for ; Tue, 3 Oct 2023 15:29:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237241AbjJCP3k (ORCPT ); Tue, 3 Oct 2023 11:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232496AbjJCP3i (ORCPT ); Tue, 3 Oct 2023 11:29:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53F41A9; Tue, 3 Oct 2023 08:29:35 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED710C433C7; Tue, 3 Oct 2023 15:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696346975; bh=tbdzRhwZFSqvsJIFtunVh/DHqwi88SOjLub9TshtNR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ox3Ejze1ovNPXtV7c7sI+2L1MJYiNnoXZ6s/fRB6CCWoFMy97C01RMVSwC2q7TyyG Rt14gyTXxXyZFzdS3Q/r/bdV3RDPr2JvuJW5TBpbXqeYvYIFne+C0ILvLvxgwk3AfR 6r0H7jN+ndgQXsFZJ1akCEg0NNMko7BvNGDmrsLCyGg5RjQoE1jEtV2u2Q0dp0HeGA +2WlAGSc/A94u0HNQchG8Mw4AKpmYMlBJOaV6eOOTnShc+GfyD6nguVjteXYo1k7gH doIHu5gCOnDDe1od5Wxy/S8begbXwL30aXMYeeRnUSTz+RpZ6/OVpl/wlnxrnCwQnk MdMsYM4gglw+w== Received: from johan by xi.lan with local (Exim 4.96) (envelope-from ) id 1qnhLG-0003uT-0E; Tue, 03 Oct 2023 17:29:46 +0200 From: Johan Hovold To: Lee Jones Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Stephen Boyd , Caleb Connolly , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/5] spmi: rename spmi device lookup helper Date: Tue, 3 Oct 2023 17:29:27 +0200 Message-ID: <20231003152927.15000-6-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231003152927.15000-1-johan+linaro@kernel.org> References: <20231003152927.15000-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Rename the SPMI device helper which is used to lookup a device from its OF node as spmi_find_device_by_of_node() so that it reflects the implementation and matches how other helpers like this are named. This will specifically make it more clear that this is a lookup function which returns a reference counted structure. Signed-off-by: Johan Hovold Acked-by: Stephen Boyd --- drivers/mfd/qcom-spmi-pmic.c | 2 +- drivers/spmi/spmi.c | 6 +++--- include/linux/spmi.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c index ee55f09da3ba..1c17adeb7a6d 100644 --- a/drivers/mfd/qcom-spmi-pmic.c +++ b/drivers/mfd/qcom-spmi-pmic.c @@ -114,7 +114,7 @@ static struct spmi_device *qcom_pmic_get_base_usid(struct spmi_device *sdev, str } if (pmic_addr == function_parent_usid - (ctx->num_usids - 1)) { - sdev = spmi_device_from_of(child); + sdev = spmi_find_device_by_of_node(child); if (!sdev) { /* * If the base USID for this PMIC hasn't been diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c index ca2fd4d72fa6..93cd4a34debc 100644 --- a/drivers/spmi/spmi.c +++ b/drivers/spmi/spmi.c @@ -388,7 +388,7 @@ static struct bus_type spmi_bus_type = { }; /** - * spmi_device_from_of() - get the associated SPMI device from a device node + * spmi_find_device_by_of_node() - look up an SPMI device from a device node * * @np: device node * @@ -397,7 +397,7 @@ static struct bus_type spmi_bus_type = { * * Returns the struct spmi_device associated with a device node or NULL. */ -struct spmi_device *spmi_device_from_of(struct device_node *np) +struct spmi_device *spmi_find_device_by_of_node(struct device_node *np) { struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np); @@ -405,7 +405,7 @@ struct spmi_device *spmi_device_from_of(struct device_node *np) return to_spmi_device(dev); return NULL; } -EXPORT_SYMBOL_GPL(spmi_device_from_of); +EXPORT_SYMBOL_GPL(spmi_find_device_by_of_node); /** * spmi_device_alloc() - Allocate a new SPMI device diff --git a/include/linux/spmi.h b/include/linux/spmi.h index eac1956a8727..2a4ce4144f9f 100644 --- a/include/linux/spmi.h +++ b/include/linux/spmi.h @@ -166,7 +166,7 @@ static inline void spmi_driver_unregister(struct spmi_driver *sdrv) struct device_node; -struct spmi_device *spmi_device_from_of(struct device_node *np); +struct spmi_device *spmi_find_device_by_of_node(struct device_node *np); int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf); int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, size_t len);