From patchwork Mon Sep 5 15:30:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 603238 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 3EECBECAAD5 for ; Mon, 5 Sep 2022 15:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235786AbiIEPNj (ORCPT ); Mon, 5 Sep 2022 11:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238683AbiIEPNK (ORCPT ); Mon, 5 Sep 2022 11:13:10 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9507D1B7A1; Mon, 5 Sep 2022 08:12:47 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MLsRR6mDYzkq6l; Mon, 5 Sep 2022 23:11:15 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.102.38]) by APP2 (Coremail) with SMTP id Syh0CgBH53DtERZj1M+nAQ--.47246S4; Mon, 05 Sep 2022 23:12:45 +0800 (CST) From: Wei Yongjun To: Pavel Machek , Lee Jones , Ulf Hansson , Christian Mauderer Cc: Wei Yongjun , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] leds: spi-byte: fix unbalanced of_node_get()/of_node_put() Date: Mon, 5 Sep 2022 15:30:23 +0000 Message-Id: <20220905153023.4152525-1-weiyongjun@huaweicloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: Syh0CgBH53Dt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Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Wei Yongjun Enabling CONFIG_OF_DYNAMIC triggers the following error at device remove: OF: ERROR: memory leak, expected refcount 1 instead of 2, \ of_node_get()/of_node_put() unbalanced - destroy cset entry: \ attach overlay node /spi/led-controller@0/led of_get_next_available_child() is used to get child node with refcount incremented in spi_byte_probe(), but missing of_node_put() on it when done. This patch fix it. Signed-off-by: Wei Yongjun --- drivers/leds/leds-spi-byte.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c index 9d23dc9e7639..eaad227b4542 100644 --- a/drivers/leds/leds-spi-byte.c +++ b/drivers/leds/leds-spi-byte.c @@ -91,12 +91,12 @@ static int spi_byte_probe(struct spi_device *spi) dev_err(dev, "Device must have exactly one LED sub-node."); return -EINVAL; } - child = of_get_next_available_child(dev_of_node(dev), NULL); led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); if (!led) return -ENOMEM; + child = of_get_next_available_child(dev_of_node(dev), NULL); of_property_read_string(child, "label", &name); strlcpy(led->name, name, sizeof(led->name)); led->spi = spi; @@ -113,10 +113,12 @@ static int spi_byte_probe(struct spi_device *spi) led->ldev.brightness = led->ldev.max_brightness; } else if (strcmp(state, "off")) { /* all other cases except "off" */ + of_node_put(child); dev_err(dev, "default-state can only be 'on' or 'off'"); return -EINVAL; } } + of_node_put(child); spi_byte_brightness_set_blocking(&led->ldev, led->ldev.brightness);