Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2345102imm; Mon, 16 Jul 2018 06:34:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcF84gR0OVNKSL2gnE92VrYDMFI7t59gZ+7acYFGVLNJv6wuYS/wkzTZlnxkt86jTz8+09b X-Received: by 2002:a17:902:b612:: with SMTP id b18-v6mr16465315pls.131.1531748052759; Mon, 16 Jul 2018 06:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531748052; cv=none; d=google.com; s=arc-20160816; b=xVN4D/yU2u/H1P/vMQCiZiGxtLl0u+smUqeqbOpQp90fLGIdRWOjrTm7dO08a9CihL lp5gCuWKSA93ugLSlheCE2RMUI9cOdifbpVe00+iL7usHpQdAeu4U6Hl53vciOAbX0hT SDarfLANBaDkk63gsYo9uUpdJXIFg07CysLbaTF3pkq2CpVDPALInqiPxoRIvF/bwt9V LUuXGkch+1TaNzcs40mnq6i/e+/uAV0fao467VDEeaS1p8N0UF4VYKcwaE5t9ZD1cH4g h/qlIpgwWCtkC+pfSEIdIcFUwSPXryh52fSZcUwejsXKthupiUXunpHt6SSBUrWwox+s Alrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=yShMAaA+3wrToiOuYhqJLwnCV7tYvrx9fUOx2YE4kSU=; b=ZZw0upnowcLUf8HLRvvnfet4budUFNS61wSBYu/T6kXYQzXwpovz8AZCLzWeYaISNV gJM+3E0goxGPjPLb6to+dajMqIakz0D13+SbnlDpWL7fXV6crqWiA968QWLBboX2VYdV uPfliwor3r/kP3QaUqHdVCTNWKP9vmDsAFqMMlTjhNPVLWyJ3hMDjtKQypaHYRFRFCp+ b7+WSQnyLf5+B+UhgV0n3bDcJvs/+TrTLc7QkbLJCbutLBq28FXGSGrMefRqR04t1B+8 KzlWLwRfsAxq6HdpFa2dj71Mm4zg5cRokjkRx/srMOrCLFGZlALb3/u44HaLpUROkimm 0ujQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ajnR8T6r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k90-v6si33605699pfa.77.2018.07.16.06.33.58; Mon, 16 Jul 2018 06:34:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ajnR8T6r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727866AbeGPOAj (ORCPT + 99 others); Mon, 16 Jul 2018 10:00:39 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43777 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbeGPOAi (ORCPT ); Mon, 16 Jul 2018 10:00:38 -0400 Received: by mail-lj1-f195.google.com with SMTP id r13-v6so29946484ljg.10 for ; Mon, 16 Jul 2018 06:33:10 -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=yShMAaA+3wrToiOuYhqJLwnCV7tYvrx9fUOx2YE4kSU=; b=ajnR8T6rt5JMTJPD3F3S501SEo5tVzodar6zcmqv9k1r3DXXlaUiqTKBJ8NRULC24S IV/gI8DdqKRkjQjKPANw5wbfQ/RaeePFjlgznhMQLzhti7m0hIcjuNUTukhkWOtWpNGu ezROY3o5iQM8tN0GltTKH/40Klq2qrJNY4auc= 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=yShMAaA+3wrToiOuYhqJLwnCV7tYvrx9fUOx2YE4kSU=; b=gTDAV1slE7Dk9Y+SyfThLeO1vfd0bqldv24yUO67sFBT2rLHZ3IAJtj7lW2Jl31RsV 9eROYY6Fn9ntikUtBh6UzWskKy9FveByirxbBiai8B0KfRK0AlueZSom2yCGVPsJfCHr LscnltDD5FIkIiOKq0ZK4ASXJQG1xl5bX0X14jJ+y8n0iXitmNUXxlgbvC7Q0evJSFF5 DUubkXIysYDbNR8/qLHiwlI1ZtXMdQ6+3Xyk4e+fykU2Rj40L7nPuWGseTj+aCj41ElQ H7liQPjtmmKJINAR6flzrmFYo8IYmxo+OFRuP/FHMF3ML3xKDs3TonliWZKqlcWD8HQr ep0g== X-Gm-Message-State: AOUpUlGORCXpY/dbIh/tFPWA07VitpFBvzFEQxHP9ZObVMpOd3k/zkT4 wEhZmlkO9a0vPSBqo4ohi6szWw== X-Received: by 2002:a2e:1b83:: with SMTP id c3-v6mr4016734ljf.0.1531747989459; Mon, 16 Jul 2018 06:33:09 -0700 (PDT) Received: from centauri.lan (h-229-118.A785.priv.bahnhof.se. [5.150.229.118]) by smtp.gmail.com with ESMTPSA id a14-v6sm3820390ljb.49.2018.07.16.06.33.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 06:33:08 -0700 (PDT) From: Niklas Cassel To: broonie@kernel.org, Liam Girdwood Cc: linux-arm-msm@vger.kernel.org, johan@kernel.org, Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] regulator: qcom_spmi: Fix warning Bad of_node_put() Date: Mon, 16 Jul 2018 15:32:51 +0200 Message-Id: <20180716133255.1506-2-niklas.cassel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180716133255.1506-1-niklas.cassel@linaro.org> References: <20180716133255.1506-1-niklas.cassel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. of_find_node_by_name() is incorrectly used, and produces a warning. Fix the warning by using the more suitable function of_get_child_by_name(). 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 --- Changes since v1: -Use of_get_child_by_name() instead of of_find_node_by_name(). drivers/regulator/qcom_spmi-regulator.c | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 9817f1a75342..4cc14c65d86b 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,13 @@ 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) { + reg_node = of_get_child_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 +1820,17 @@ 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) { + reg_node = of_get_child_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; -- 2.17.1