From patchwork Sat Feb 11 10:42:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 55780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1437389wrn; Sat, 11 Feb 2023 02:57:35 -0800 (PST) X-Google-Smtp-Source: AK7set+xLCxlEWubFekODTO7VIPaj73R84UzaM27LRw/vtr8t1GZujsn0QUmZFJvoaMlKXmg7uFq X-Received: by 2002:a17:906:4413:b0:878:673f:5492 with SMTP id x19-20020a170906441300b00878673f5492mr17651230ejo.40.1676113055126; Sat, 11 Feb 2023 02:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676113055; cv=none; d=google.com; s=arc-20160816; b=Fqj2ql6oE0VkfkOpOBEuLt4rM4TiYoMkUw/49N0nn5+JUoPKdz8l+azwqN6dq02n34 o8PDdIXjl8Xa06gjfh3qpJ1Y1EMRGpXyF+cV6Z+Pkyaa5SFx4TtUvY2huc3NDg1hgCz5 7trViaeoQo20mRd9uiJm+Vf2+xUIjuDnJFrCF7aeSNGaIU4/Ew1mktbR1pNshC8eQHce 5LnBhWpzoBu0QZiFZjvJ0k4KC5HHB9kJkarsuKwwM84i0IC5IfkMiEWUJ7E9+LjX8ccv 0RYfrhvRiNDz/xgvjEg9N73unbX3ws93PedA9i62Ubmdw2HLqCKDED3/yMsw1I7Eq0/e EgEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=X9tHt+Caea/6CuL0bPp1DbZN2qpYRP0bBdO4ax2tMf8=; b=NvSY4Vf9CpZFB49Qfy6b6mmgRnESWG3XG/J8YK5N8/6ChrvzqY9OVJDXPL/dqBrM72 yLGp76pLMKjxU+IeTuC8QHeRzY2VxkY5rtivCaAe0/hOCtwBCnwkq/DBHG8hRg/d6rhP i2HdboxenDf5ptDC8s14vFUr6iikclk/NSOokHJMSnfVUvPwmdo2WOQJy5VNTRNEzNBL SNtWcuK81PYMBLFndK9MxPmLAewf/oDutozbBQZLR7cQk108/+dhHielMLUn8DNtAuJn 9hqJGs/YW4+AcM2Cl/6mZCQ/DDyo7D7wZxIdtXdPHAbmEU2W0WpYHPq/eckFMCV3wB85 l5Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=brMK4e3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020aa7d702000000b004acbbafc603si578026edq.335.2023.02.11.02.57.12; Sat, 11 Feb 2023 02:57:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=brMK4e3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjBKKmg (ORCPT + 99 others); Sat, 11 Feb 2023 05:42:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjBKKmf (ORCPT ); Sat, 11 Feb 2023 05:42:35 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2700B311D6; Sat, 11 Feb 2023 02:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676112134; bh=YWNKXJsGcCGSx3BeuPJ+DwSelvQ5DLVpRbP15fVAw0U=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=brMK4e3yl6tT6M4P6Jq1Jjx5RoM0dOgNE2WNL3D6+Fkto4hauTKf8hC829y4Z8k/3 qTnma4bpWzlQXaMwM7o1e5wYm0IPpVdLYZj63L6w8OUKTwXN/+Det6r1iNUFQ1alpz 7rR6yJdyiFIjQfRnNHUybEOHQZzmsstO1iJjLveQ= Received: by b-5.in.mailobj.net [192.168.90.15] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sat, 11 Feb 2023 11:42:14 +0100 (CET) X-EA-Auth: KWivLFusfe4M1FPFEQqJeQo8HsYkZIK5ja/R4WdeOuBADd0RqXt/X9wMN3obLuKKdS3duyFYHD6akLmUX/+DPU2MGNdvswLc Date: Sat, 11 Feb 2023 16:12:07 +0530 From: Deepak R Varma To: Pavel Machek , Lee Jones , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH] leds: qcom-lpg: Release node reference before returning Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757531922928744788?= X-GMAIL-MSGID: =?utf-8?q?1757531922928744788?= The iterator for_each_available_child_of_node() increments the refcount of the child node it is processing. Release such a reference when the loop needs to breaks due to en error during its execution. Issue identified using for_each_child.cocci Coccinelle semantic patch. Signed-off-by: Deepak R Varma --- Please note: The proposed change is compile tested only. I do not have the necessary hardware to perform additional testing. Please suggest if there is an alternate means available to further test this change. drivers/leds/rgb/leds-qcom-lpg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index 67f48f222109..993fb9cf0204 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -1112,8 +1112,10 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np) i = 0; for_each_available_child_of_node(np, child) { ret = lpg_parse_channel(lpg, child, &led->channels[i]); - if (ret < 0) + if (ret < 0) { + of_node_put(child); return ret; + } info[i].color_index = led->channels[i]->color; info[i].intensity = 0; @@ -1291,8 +1293,10 @@ static int lpg_probe(struct platform_device *pdev) for_each_available_child_of_node(pdev->dev.of_node, np) { ret = lpg_add_led(lpg, np); - if (ret) + if (ret) { + of_node_put(np); return ret; + } } for (i = 0; i < lpg->num_channels; i++)