From patchwork Mon Jul 16 11:35:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 10526543 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.web.codeaurora.org (Postfix) with ESMTP id 950666020A for ; Mon, 16 Jul 2018 11:36:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D19B2882E for ; Mon, 16 Jul 2018 11:36:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80D2928898; Mon, 16 Jul 2018 11:36:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 262FF2882E for ; Mon, 16 Jul 2018 11:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731194AbeGPMDq (ORCPT ); Mon, 16 Jul 2018 08:03:46 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:44688 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730304AbeGPMDp (ORCPT ); Mon, 16 Jul 2018 08:03:45 -0400 Received: by mail-lj1-f195.google.com with SMTP id q127-v6so29045564ljq.11 for ; Mon, 16 Jul 2018 04:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l/tofPDhJxcM4c3JuRbs84i7HqZwJjey0utmlS/P9Ns=; b=jF6fPI2mWfgewcHPl3qO64dpAdR4BGrDCKdWxzJuU1uNbSWG4KmLZBdoaCsxth6dDl 6kK43QgwQfTViLl7ExZZfLWaH5G0xwKCuXm1+deVDsAcxgW2ARDB5/tm4tla7k2PVdWJ L6YYgtOH5YES03v+RVsiAKxKHzFJwjJyzXtxc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l/tofPDhJxcM4c3JuRbs84i7HqZwJjey0utmlS/P9Ns=; b=JafhwcJuOwjUjIGDJ/5l9hNfqC7ZHCNlOGlndWO6v77LZgISNY9522oyMXBiDLQE8u BC8+T1gB9JGBJ6/3NVs8aknDQh2ZcP0dMyv4G+8+tCAdw4tnmhxd3L+3R6NK1qXqM4rL ww00skFXWMBD2g8CttzQliQyL9cONFeCBzUyX+OfgOXC3HupnQbDxKE/gX7KNESxxv4w UG23qblYo67mH1oY+dGR/cuyKMWgqeyjX+KTyNta5MVYhsK+OvA7RvBLNBTd0b8q+SY/ YTzWYi6xzxbWsbgbSd9mDOuAvWPATXBRtXhlG/IEKgki+K/YGBPbl0uRnrjX8L8LkWqA 2qzQ== X-Gm-Message-State: AOUpUlF+s1KVKZAQ8Ye9u518PVI8BBsCweGeFzBw49Nh9Kkph3SQ85kr SQGXJNOpFY/q5dCvUKTMW4cz9A== X-Google-Smtp-Source: AAOMgpfitu31qSnhexO6rkYqa8qYSwn+xqBd4riJG0lnpdj8eeiWnDHNqlbHspCPLZqNOaE+VRX3+w== X-Received: by 2002:a2e:557:: with SMTP id 84-v6mr10583839ljf.152.1531741003010; Mon, 16 Jul 2018 04:36:43 -0700 (PDT) Received: from centauri.lan (h-229-118.A785.priv.bahnhof.se. [5.150.229.118]) by smtp.gmail.com with ESMTPSA id v136-v6sm8104913lfa.10.2018.07.16.04.36.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 04:36:42 -0700 (PDT) From: Niklas Cassel To: broonie@kernel.org, Liam Girdwood Cc: linux-arm-msm@vger.kernel.org, Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] regulator: qcom_spmi: Fix warning Bad of_node_put() Date: Mon, 16 Jul 2018 13:35:22 +0200 Message-Id: <20180716113525.9335-2-niklas.cassel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180716113525.9335-1-niklas.cassel@linaro.org> References: <20180716113525.9335-1-niklas.cassel@linaro.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 For of_find_node_by_name(), you typically pass what the previous call returned. Therefore, of_find_node_by_name() increases the refcount of the returned node, and decreases the refcount of the node passed as the first argument. However, in this case we don't pass what the previous call returned, so we have to increase the refcount of the first argument to compensate. Also add a missing of_node_put() for the returned value, since this was previously being leaked. OF: ERROR: Bad of_node_put() on /soc/qcom,spmi@400f000/pmic@3/regulators CPU: 1 PID: 1 Comm: swapper/0 Tainted: G W 4.18.0-rc4-00223-gefd7b360b70e #12 Hardware name: Qualcomm Technologies, Inc. DB820c (DT) Call trace: dump_backtrace+0x0/0x1a8 show_stack+0x14/0x20 dump_stack+0x90/0xb4 of_node_release+0x74/0x78 kobject_put+0x90/0x1f0 of_node_put+0x14/0x20 of_find_node_by_name+0x80/0xd8 qcom_spmi_regulator_probe+0x30c/0x508 Fixes: 0caecaa87202 ("regulator: qcom_spmi: Add support for SAW") Signed-off-by: Niklas Cassel --- drivers/regulator/qcom_spmi-regulator.c | 42 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 9817f1a75342..8b921b1b1df5 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c @@ -1752,7 +1752,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) const char *name; struct device *dev = &pdev->dev; struct device_node *node = pdev->dev.of_node; - struct device_node *syscon; + struct device_node *syscon, *reg_node; + struct property *reg_prop; int ret, lenp; struct list_head *vreg_list; @@ -1780,10 +1781,18 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) for (reg = match->data; reg->name; reg++) { - if (saw_regmap && \ - of_find_property(of_find_node_by_name(node, reg->name), \ - "qcom,saw-slave", &lenp)) { - continue; + if (saw_regmap) { + /* + * Compensate for of_node_put() in + * of_find_node_by_name() + */ + of_node_get(node); + reg_node = of_find_node_by_name(node, reg->name); + reg_prop = of_find_property(reg_node, "qcom,saw-slave", + &lenp); + of_node_put(reg_node); + if (reg_prop) + continue; } vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); @@ -1816,13 +1825,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) if (ret) continue; - if (saw_regmap && \ - of_find_property(of_find_node_by_name(node, reg->name), \ - "qcom,saw-leader", &lenp)) { - spmi_saw_ops = *(vreg->desc.ops); - spmi_saw_ops.set_voltage_sel = \ - spmi_regulator_saw_set_voltage; - vreg->desc.ops = &spmi_saw_ops; + if (saw_regmap) { + /* + * Compensate for of_node_put() in + * of_find_node_by_name() + */ + of_node_get(node); + reg_node = of_find_node_by_name(node, reg->name); + reg_prop = of_find_property(reg_node, "qcom,saw-leader", + &lenp); + of_node_put(reg_node); + if (reg_prop) { + spmi_saw_ops = *(vreg->desc.ops); + spmi_saw_ops.set_voltage_sel = + spmi_regulator_saw_set_voltage; + vreg->desc.ops = &spmi_saw_ops; + } } config.dev = dev;