From patchwork Thu Sep 26 23:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813728 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5918CEBF61 for ; Thu, 26 Sep 2024 23:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HGJHwDpR/ji/cnkncpEc2TmRR9IZ/lolVNsmw4iGQAY=; b=obd0uiT+2KAV4XwdFqF9Th44ZF qlaFXWv7AzYqVSjBx5N+7HOG099GtjREztCw14kgcqTLC6Su3+6JbEAr+8Gmml7CAUbbrmQgx114p MyOOAI2GPpZjqejhfvANG0LmgMMEXTcD+omfFFwAopqqnO8DvdctPqxJlDdONSo2a+61HuSE8QtXZ 7AshX82CRFCk+AE/7ltrYDd0fKSiPPM3WTkBcyb7WFVgvDXz2V0iYn87r8H42WY1F1w1Mc896w18P 5aqZqT3TPIWd+GGxaxWPUe0Ts2sLCzPyO/9COAkimp5Grv5LQaILNYEOT2lrtAKLoiL6IMLmOHnuD XzEw+Pyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxpq-00000009ZcD-3byM; Thu, 26 Sep 2024 23:23:46 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnU-00000009YrT-3jB6; Thu, 26 Sep 2024 23:21:22 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a8d6d0fe021so244076466b.1; Thu, 26 Sep 2024 16:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392879; x=1727997679; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HGJHwDpR/ji/cnkncpEc2TmRR9IZ/lolVNsmw4iGQAY=; b=Q4Humw6c9oLMoIjMIu3RO/Tjdw3/jraIZtf5/IT6GgfKZDQ9qOX8AGn203R9IKTbls IAb/inU+vRzYgRaJAtTUhQ3FNAJjc+12ZqX9WzrmV1abe9uvKEYlyWaFIF/mb8xiLGmK YIw0Z0QtZPSg82jGeUMsopqrI5BiGUcG+hSHJ+dr7spKAummSdtRDfjMPcrvFo5zH3XM 2zMNPRs4yzJ67bpr7kV99kjOs18K59aQp5jxSE0ffgMesay43RPJyGQoqLVQWM6PsDVT N1c/cOnVgt2x0V6/4tnO4nIeX8SA3UABla+3y0Yj643MtBnmhEaowD4EScWnkRWH1XTX QwLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392879; x=1727997679; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HGJHwDpR/ji/cnkncpEc2TmRR9IZ/lolVNsmw4iGQAY=; b=txJqfybt8NLoaJEdygLMbooc86UX91PM3N/OE0mndq3G+DnesY73SJAW+tm6ksZ1Je O1wYYdwb7UvEf6bPhkH8/vEIowslYRFHOuh7IaHn42aBbLn/ZAx66hJfdpd2JzF8CTDR GtPGvIujMOg9xKJAfdS01PqnoK0d4FvMwlg+b3nV82sh27drcs6EM2Ln2rcfoklsZZ2u yfumMXIK1V+dhRHRBq3zcM5/1UHZVznqKWadKnO9CV2Cl41hqj2KwKVqLT5VdNpGagM7 qoTS2nBMDUsqh0fdtf8CVpiSwT1rhW1Cp7/+ErbqPWzh9hcmAayMEY8hHCmJPXU8/x3r +ALg== X-Forwarded-Encrypted: i=1; AJvYcCUpRo2xWbqgXUZo6xRseHpG1Ffk1rrYMBsLXrPSL1AdNGRvsv6qm6ru2Da372ZUS/GwuZVyoBXQd9C7ibpsPoo=@lists.infradead.org, AJvYcCVSStKCugo+ODfBy6GWIKc7VQpCA9ZYSEjezj2PgNQxs7aeL/MuLqqUtG7BGeG6dMJF2eunyblYAzHXZNM/PX2l@lists.infradead.org X-Gm-Message-State: AOJu0YzZwx4AtnHhkEvJ8Pu7yUy0z6cJTRgyizS1D+eoWQ0lmlVDOP2I 8vqllNOsGANKevoFmgmnPGhlA+a4sthGXB91UT2+GDpfocHU3ZAvnKgJ0SMB X-Google-Smtp-Source: AGHT+IGY5Dz4pgmEK6u+H4dMIOw35D4e/9hhSxXD8+4Iw9UMbO9AvkfpZ6JWD1p0Ig/DDcHSjiCZSw== X-Received: by 2002:a17:907:a41:b0:a86:91c3:9517 with SMTP id a640c23a62f3a-a93c496167fmr87272966b.35.1727392878703; Thu, 26 Sep 2024 16:21:18 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:18 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:52 +0200 Subject: [PATCH 01/18] leds: flash: mt6360: fix device_for_each_child_node() refcounting in error paths MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-1-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco , stable@vger.kernel.org X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1575; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=1/lxG5uyf8ycEv9Q6sKFSvHVcULTiG1X47zomtk2GFw=; b=l7jxa1PVRIFHMQnforadtxXgycvAan+1W9FAPjf/oLjtSQJykU+rNGG9xia/dfVKvn20xfSza 2IKbNR03aEtAABYWTigl5u7JrFYAD61XGGxXgkaMcyX799cHVY4tp95 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162120_965004_907F2D2E X-CRM114-Status: GOOD ( 14.75 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The device_for_each_child_node() macro requires explicit calls to fwnode_handle_put() upon early exits to avoid memory leaks, and in this case the error paths are handled after jumping to 'out_flash_realease', which misses that required call to to decrement the refcount of the child node. A more elegant and robust solution is using the scoped variant of the loop, which automatically handles such early exits. Fix the child node refcounting in the error paths by using device_for_each_child_node_scoped(). Cc: stable@vger.kernel.org Fixes: 679f8652064b ("leds: Add mt6360 driver") Signed-off-by: Javier Carrasco --- drivers/leds/flash/leds-mt6360.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/leds/flash/leds-mt6360.c b/drivers/leds/flash/leds-mt6360.c index 4c74f1cf01f0..676236c19ec4 100644 --- a/drivers/leds/flash/leds-mt6360.c +++ b/drivers/leds/flash/leds-mt6360.c @@ -784,7 +784,6 @@ static void mt6360_v4l2_flash_release(struct mt6360_priv *priv) static int mt6360_led_probe(struct platform_device *pdev) { struct mt6360_priv *priv; - struct fwnode_handle *child; size_t count; int i = 0, ret; @@ -811,7 +810,7 @@ static int mt6360_led_probe(struct platform_device *pdev) return -ENODEV; } - device_for_each_child_node(&pdev->dev, child) { + device_for_each_child_node_scoped(&pdev->dev, child) { struct mt6360_led *led = priv->leds + i; struct led_init_data init_data = { .fwnode = child, }; u32 reg, led_color; From patchwork Thu Sep 26 23:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813731 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8577CEBF61 for ; Thu, 26 Sep 2024 23:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SRhQyVKcgRlVjIYoZT+41pIKZJrgjINAhed1beNUQXI=; b=k8tw3/qyV07If+vPuM6YeP4o2D Lkh2EtzwWyxuOz1F81lbP3WuC6h03lQ0ltd2uVnsL/hqPcjte8+d+KmYjtPUO7OCY0c6gq0cVqyGH Ge7z+7sVnNMmjAJ2TbA/t37PRkGOUcStPuRs0CWXErNs0nf+9zzgYy8XhnNqQS4/NceddGKI5yrJ1 zyRZ9XExwggUMDetlQYtfnMJrGWszOiOLAc8BtgAU//AfnwrdfrrC36ZUhGrABxSeaMgRX1iPCRrh mDQMcWMBpqIPanZrpnulEonnIWboSbo0ENrNm0ZQWg9Nu2kv/i/D8f9nktTtMgRGpuJdxMIscdmQn LSuY4r6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxr0-00000009Zxk-3kPZ; Thu, 26 Sep 2024 23:24:58 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnX-00000009YsD-3pCD; Thu, 26 Sep 2024 23:21:25 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c42f406e29so1905548a12.2; Thu, 26 Sep 2024 16:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392882; x=1727997682; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SRhQyVKcgRlVjIYoZT+41pIKZJrgjINAhed1beNUQXI=; b=EDLf70HBrXNElX2K3DSXwqPkY7Ol9vq+UYY1U6XDOInYVAVSyt0OSchzNF8H2xDTUb R8I/l/JPv/oS3XK9xMMdr8jLc5EZKbqoAsJ4W3KB2e1Q6k6K/dh8T2fBaFAzVOfehrs6 H4yI5uWTXPy68xq0SE7qWqaBie+g/5iupOk7ZS4wiult0l4l0DqnafGJEXX8D8f47+eV ooFYkGZqVQ+tdWanAtGnpJPT51wjalGVnN3Cn6QTLaEdq946LIE6eBWRHyrhlOGvF88X k1jwsr/x89xk9yvl4HCwNODelFWRTyYqTzHGFOM5d7XSCVoolU6AEh4fWMC0NFvOtsNu 9NDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392882; x=1727997682; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SRhQyVKcgRlVjIYoZT+41pIKZJrgjINAhed1beNUQXI=; b=mIAbb8PBYi0QS+ItITBQyv2ubBDc/oBFsPy/kcvmcgnSatYiU6xi87WXIPX+Nn8z24 slJjI+gDlTXfFRob0d/SxgqxxxzdW2morMh1A4JWTveNd+z7tlV1z0YLO+XvSjsBLdjK LL8FHA1TzWAV1II3L79rhBtyCXWW7qhvokAUpaQrLKtCfRMMXpLI1/aLu1tsa8a9VVZb BczvJ5kBE2uFOmioiWP3YIdtquxfveuldHiue+JojrigO969KJrtIGrET8uv2Hyg4gcI 0Kt9eQB0fYKaFvVeEB/k5HqHDNGWgOnvg+HD1iz9ECauehk0DBQ6SXKL9BXrr1Lilk/i eC9w== X-Forwarded-Encrypted: i=1; AJvYcCU+L0l2PoE3Y4MC0TCJIvf3Eo49xf88p4Idh0Kg3ppVm975f/jRFzU/e9J+RCvx+qMBkg5KAJUnnvrNW/B4uVWJ@lists.infradead.org, AJvYcCW3vAikN1SY/ewcimPzVYyC6g8WiE52NCUAZzUPLMF8OXsYhRGmt+u9AtTagpAq7Qk3X+bFpgvB8OjiTfu+8gI=@lists.infradead.org X-Gm-Message-State: AOJu0YzQsUr/SvylunnphwjC2/3ERdVQi+2oFzFzJ/x89Cc80hbUgJw4 JUqRqRUP8MsQEAMLcl7z/HRvXq6/N2HcUL5w7f+9x3DfgpBzjTCxe+Gs7fBF X-Google-Smtp-Source: AGHT+IGd2PJRYpLODXkVXKvFBOHOE+/1R0umomGP/eN5VLC0TMztnCr42izK4H4rLnfkXKxJDXG3EA== X-Received: by 2002:a17:907:2d90:b0:a8d:510b:4f48 with SMTP id a640c23a62f3a-a93c491952fmr82476866b.22.1727392881724; Thu, 26 Sep 2024 16:21:21 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:21 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:53 +0200 Subject: [PATCH 02/18] leds: flash: mt6370: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-2-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1546; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=da+yiLrVSVhzxfXeLXUvwNG1cBTZv5IPC9inOzFUOgI=; b=+HkfaGOfTwfbLA3hl6LrR4cqzOrg7pu6sEXSeJ1n0Dv/N3Wgj5+SYNtD9fefjVYJnlMGIaRy1 uy9KHs3e49mDqhgLOoZkQSYwrgF26sZfTIiULhEDZkfR2xEXsDOl9l8 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162124_026875_753CC1CE X-CRM114-Status: GOOD ( 13.75 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/flash/leds-mt6370-flash.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/leds/flash/leds-mt6370-flash.c b/drivers/leds/flash/leds-mt6370-flash.c index 912d9d622320..dbdbe92309db 100644 --- a/drivers/leds/flash/leds-mt6370-flash.c +++ b/drivers/leds/flash/leds-mt6370-flash.c @@ -509,7 +509,6 @@ static int mt6370_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct mt6370_priv *priv; - struct fwnode_handle *child; size_t count; int i = 0, ret; @@ -529,22 +528,18 @@ static int mt6370_led_probe(struct platform_device *pdev) if (!priv->regmap) return dev_err_probe(dev, -ENODEV, "Failed to get parent regmap\n"); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct mt6370_led *led = priv->leds + i; led->priv = priv; ret = mt6370_init_flash_properties(dev, led, child); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } ret = mt6370_led_register(dev, led, child); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } i++; } From patchwork Thu Sep 26 23:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813732 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42FE0CEBF60 for ; Thu, 26 Sep 2024 23:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HNd4acINmmNerLNUmXoF50X4J1ylsjRdPZ4qMlEZiVs=; b=XU8X87Lbjl9gYqkAl10eW/5HRG ydK9z8/tpD57OsJqbP0tpmNuJ3BfkiRoD20VVxVYSpbWN5kWuzTv3n8/CApw6jOUw8DIdxZNL04+a BGXZpw8OXR+dXvcBKEvgdmFU9Xf72zgi90TImGWfas/TGXI8R0h611E1jOiIrMROP0Dn0spwM9O3D DiuIXV8QdpcmbexLB0STqXdDhbZLsCABy5Ee2SnFEK1VK7evXk0P30lRh/ZyavgxFx0HOT6A2M2Cw gbmWyxpEtBng5VpTm9yorbM/BWjBuyNs4QuNXT/UGSnZxMIKLQEeeWttvkgd7YxWNMWtGZruhbmaN rWPrzlPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxsB-00000009aGA-0R0d; Thu, 26 Sep 2024 23:26:11 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxna-00000009Yt5-2fIk; Thu, 26 Sep 2024 23:21:27 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a93b2070e0cso173533566b.3; Thu, 26 Sep 2024 16:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392884; x=1727997684; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HNd4acINmmNerLNUmXoF50X4J1ylsjRdPZ4qMlEZiVs=; b=cTbZAAvlMmCaqlB+qzuJJaf2qTzqsszmi5mAYfRrqNtmrDSxIQF6WNfMC+I1ys2bII owPTxpAYGSZIfHS5+LmC325K3qH3M72cJmWS5yZvaL3aRpAcCPHpyi0+rHUVelZGr+dG D7q9x4zPkYTApP75LvBCuNqaDmsfIywF96FhcJON3oEKcnE7R9CGXKPSsdzR7CAMHnVw EFX8wQ40DJK0R6dD1HQYjKnnYmx3A9+IxDu40FAjzowTgPkYYoumNX72iAUv0RnNeJF8 aECUOkLZWvD58uXNebeKRLazG2yNiORKJQ9vqd97elZpemHuGL6Hfb3KTyob+tLxNNvT 3QoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392884; x=1727997684; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HNd4acINmmNerLNUmXoF50X4J1ylsjRdPZ4qMlEZiVs=; b=dhow3LEg5gK3dtesSpcpzV8B6TodHpDTzVvcstk139y0B3DmMzJY27uVCV/EUWEELb B4HAIJVNST4aoy7uUcuheeGWpNcZa2NQFYJTc0n9e+DA4Fo+G7rPuxz0KzvO9R06NT8U CE4vld+4N4bU9VtCIzuYu/vR5lRZipK9mBmoLFswt3tvFb0ZEi66jbcikRTlgAyv4Q5U TNErabaL4mRFEWcMHQaJfwKuCwg8udkuzUDJ917NNhfRbVDmAepGsiBIApFwF8fqx860 xQRS7CsZRz2EwGB91xMIwAG9LI483S2m2h6a0pWvkO9HKiAIRlVatfmv7gdGNGsUKM/2 xnnA== X-Forwarded-Encrypted: i=1; AJvYcCVTi/o+N1lg0WI4QGGAjDCtgMTp9GiuKS2rf861DwkYVFPimLD53Oz9uEhY2dKQlMDPeEAp3Q9puDRhk2ANLNc=@lists.infradead.org, AJvYcCWqPMn+hUVI1F4oAOUaYJ3yMTqJRkNHXuYG/Lo8fn6Hnc1V/MEpdn5mqutIalxyfObAepFLjG9Amc76I+NwgHSF@lists.infradead.org X-Gm-Message-State: AOJu0YynJxZj+X7ZtfhWaRcBKQs3vLWxLLAUmavJSp+oMfFEdyTR2pWe VqsyV9S4HuZGibcLTXj8JuFScDOkjXz3vnfG+ktr+/PnEobssXtkxu8fz/f2 X-Google-Smtp-Source: AGHT+IEaJkjaI1Z6tqe57O4cY/kSpV7TlwQqKprn1eIz034AUHy+NubnWwLak/p5Xh3t4FDbODMYtg== X-Received: by 2002:a17:907:96a7:b0:a8a:3f78:7b7b with SMTP id a640c23a62f3a-a93c4916e6cmr73897666b.14.1727392884471; Thu, 26 Sep 2024 16:21:24 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:24 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:54 +0200 Subject: [PATCH 03/18] leds: flash: leds-qcom-flash: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-3-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1584; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=wZ6akrPJfNHUSfXIEENEHvfLrdMCasbCDwbd/LiltB0=; b=51y1SjR6ulBD3qqgS2qUF2cR+3GmbQoLP5twgUKAKBCLM1UNA7NMBuE8fYTAvAWvhCwVEKFCh S+CcP+wu+pwAJEAW1NzXp4grrO/7Uy2C/nu/OWMtTu//R6mCOAKLHae X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162126_709097_E10EABFD X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/flash/leds-qcom-flash.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c index 41ce034f700e..ab848c5acd2d 100644 --- a/drivers/leds/flash/leds-qcom-flash.c +++ b/drivers/leds/flash/leds-qcom-flash.c @@ -812,7 +812,6 @@ static int qcom_flash_led_probe(struct platform_device *pdev) { struct qcom_flash_data *flash_data; struct qcom_flash_led *led; - struct fwnode_handle *child; struct device *dev = &pdev->dev; struct regmap *regmap; struct reg_field *regs; @@ -896,7 +895,7 @@ static int qcom_flash_led_probe(struct platform_device *pdev) if (!flash_data->v4l2_flash) return -ENOMEM; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); if (!led) { rc = -ENOMEM; @@ -914,7 +913,6 @@ static int qcom_flash_led_probe(struct platform_device *pdev) return 0; release: - fwnode_handle_put(child); while (flash_data->v4l2_flash[flash_data->leds_count] && flash_data->leds_count) v4l2_flash_release(flash_data->v4l2_flash[flash_data->leds_count--]); return rc; From patchwork Thu Sep 26 23:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813733 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E23CCEBF60 for ; Thu, 26 Sep 2024 23:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=97MJYpYNh2OXN36yrgEntTFOxNkCwTKF272jX4EBFYg=; b=WGowiRZ/Fepv1U+OMed+DwoA9l wKBGuLY3L/uvzl5hrwkFQ87ogoacj/2xDx3XjH8e42mCEMhj+DPSXXFtc0rrOPSrNn2wx81OWSdGh D7k3dR52S8JRwvMuug6fsw4garulk3aJQWHFeyGPuspignvLILrV8OyOtRLmztnpGMjXqV1upyYJk SuA9+jmLcVlegUHmTrb1FfGlj7PludRTii4qvk1e7W9vvj8EnR3TZNks7TdPRCYaGwWboABodQaaq ZvoF0W8j0q9ghA4OSUOqWPet+3bN/9oblccTl78Vmf1cfETRNqVZWmExRPFWWD3eOY2aqQ8sYnSIK JbIGpD9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxtJ-00000009aPU-0sJA; Thu, 26 Sep 2024 23:27:21 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnc-00000009Yth-0YTt; Thu, 26 Sep 2024 23:21:30 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a83562f9be9so137010266b.0; Thu, 26 Sep 2024 16:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392886; x=1727997686; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=97MJYpYNh2OXN36yrgEntTFOxNkCwTKF272jX4EBFYg=; b=S3Q4UFQiVebFRWMEIJrX7xdkPIAGSxdyeG3QGlB3BTf7izdedkbWbuRI/HHmu5eGah ZFBd2n9T7KvELvMtRgPlEhzPt800CJvvrOEjoy2aDjQZSujM21wb7kJuNV4kjRSMnAYp 6/ZwmJv1Fvd27aiR83XmRxgqla0H8ix1MQ/Ril4s3rmcMOlY1S2UK+C+M7/bw2V+exiJ cyLSMBWxBFPfo5vc2Hqf3odDKHDT1oW2nYiRJgOqpEKGG6dOmMw9Y4TUcXKxWrSSK0Ny qgQqfl33Ie1SE8LsNYl1K6F4k0zERhe7yVPSBo3qEQ/Tza9Q3Sb1dWXAlywrZ8Iojf5i B1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392886; x=1727997686; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=97MJYpYNh2OXN36yrgEntTFOxNkCwTKF272jX4EBFYg=; b=UI5FADjrGaKrT3W99cdjjP4BkwNnhbENb24ZnA5pLtzIWO4B06R2YMseEUByPTXDZ5 oecIUqcxCbjwIjUazsHTt4di3iO4WdW9lBsF0njanVN/e8FjliGZ+CSJSj5pw15b0pZ2 V3H14Mfh2ermGb12oeuOx5O2SYdUdLALQfI35vp4gB7yetF9wnCDuMf2cOg2M/pGYsd7 kL+IAM7rOylp6YmksVSeT8VUvpy8bcErcHvCoS9ZQgd3SSxepjPsoBgEkBAnUXBmnCjH +Nkbafy0YuMrbPyB4p+jA/dnXmLW/q6Myoq5De6awz8jmJIUsCGhSbVoITVcVdbkvuqL Eo9A== X-Forwarded-Encrypted: i=1; AJvYcCUssvQ5kl9kfQSX1cELB1GA2SUpDnJC5V+dvyJjhYazUacauwfZtLgy7ZflQMgFO3SAKqL5bW52x/OjlukI1sXI@lists.infradead.org, AJvYcCVzgM4BuRRNvKXx5T4C1hah2ztr82Wnxvx82T9nMwPW70MushjL/wrJkuAyOfUo4dOy5nwmWbQtTfWa5NulHpU=@lists.infradead.org X-Gm-Message-State: AOJu0YzCPijEPT8xD8WgHpECXb4Ivp8hh/ZzxjPCgJ7vDRSVpmi/UVFh uG7t63z0MqU3A8r1ZUq68rJAyB4UXaAFNOcXz73zGUOQrywIv3LkrYeOUwL9 X-Google-Smtp-Source: AGHT+IGEbTyX4azDhptvTAbyqHSfEzTyPNNE/JgVuXwIVkiF6dJaxNfrq6Yp0EW4PANwfpfda2QaAA== X-Received: by 2002:a17:907:d14:b0:a8a:83e9:43e2 with SMTP id a640c23a62f3a-a93c48f926amr75943566b.12.1727392886119; Thu, 26 Sep 2024 16:21:26 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:25 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:55 +0200 Subject: [PATCH 04/18] leds: aw200xx: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-4-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1474; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=d0/jBZeOQ8xCvysG4yJkfCKJi0DJ8XXoa660caQmywM=; b=tR0vcqDoOSP5Z2owKMnAB9bhX8x7lqHl3M+byu6E1aArGwC6Yf4PxLgUabwsOkMjFx/oaq0zI VzAnF+19OBbC8V0VBuGNYGHfa/Q/kR9spuC+zWidBB4bco6IBrAZbCS X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162128_291696_AF5DC138 X-CRM114-Status: GOOD ( 13.33 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/leds-aw200xx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/leds/leds-aw200xx.c b/drivers/leds/leds-aw200xx.c index f9d9844e0273..08cca128458c 100644 --- a/drivers/leds/leds-aw200xx.c +++ b/drivers/leds/leds-aw200xx.c @@ -409,7 +409,6 @@ static int aw200xx_probe_get_display_rows(struct device *dev, static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip) { - struct fwnode_handle *child; u32 current_min, current_max, min_uA; int ret; int i; @@ -424,7 +423,7 @@ static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip) min_uA = UINT_MAX; i = 0; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_init_data init_data = {}; struct aw200xx_led *led; u32 source, imax; @@ -468,10 +467,8 @@ static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip) ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); - if (ret) { - fwnode_handle_put(child); + if (ret) break; - } i++; } From patchwork Thu Sep 26 23:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813737 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71DA2CEBF60 for ; Thu, 26 Sep 2024 23:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RKtvZEPDH+fIZPKBCRGZ7MZSFbm8PGwqKLmwiboGd/E=; b=rwbi9nvptHGsJg8D9Uka1kvdNV 6zvIpmcrP8QFhXdEcwBPnL6Rz1MgZ7dv6dtRGWTaQ+41VaHfn4gNNa1tfmE9YN2xoJtiePEfjAu/y qWTVVnIDxanstqm5qWPqjRD13heUmNIfFwjFlAQZ0fWAsj8Wn20LMxQIgltLKGjFbFrmiRVEVQbq3 DzSL1dJzz1qAYbHPddahefhp4EQcQK4/hCqDOH7qJkuAIdmdaz0pPkc6M2O0VHSKVQcSf7XnG3uXl mSBrt3gS6Z7sqH/isG53/eSTg2B4XavffAXIC/djzaYG3z2+1hKqWrc71xEDpXfx6o9Jp706bdEKJ iU4mB4wQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxva-00000009aeA-1xFh; Thu, 26 Sep 2024 23:29:42 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnf-00000009Yvj-3CUD; Thu, 26 Sep 2024 23:21:33 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c71f1396e4so1766473a12.0; Thu, 26 Sep 2024 16:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392890; x=1727997690; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RKtvZEPDH+fIZPKBCRGZ7MZSFbm8PGwqKLmwiboGd/E=; b=Si0mEyGXSYqo2UeT/D1Nr5qLQHaDwAP67Uca4Zbwgi33WCixwiwvSOXotCLmToBnG4 hVq+nYiLiqLnXmV0KOUmkmI0EBKP1saDjwM6kDe3WfNl9UUI69o/tW0glLU9nK0ESyB9 uLKdVyCvGChMDtMQDQVOiRrNtDecqMV1xnAJlX82Q/I5PRn1gpFp9wQo0yjKuDAkC33k MvGPFvLQYsYGXmEUTmL+R+hl06gQ3UJNiDKKBp28D0NnviPDsEM4c6YXaBy49nYZsXm+ cKDUg1Z5xH10rDQFRdsz+JBpCr1B7jmAnoDf8ms7wHiRw5gz8YjZ2zk0QXQVpeNe9VYu PRVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392890; x=1727997690; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RKtvZEPDH+fIZPKBCRGZ7MZSFbm8PGwqKLmwiboGd/E=; b=Io+XgAu2fbPufmLqkyVgUiZgYupy75HcH5xtLyF3FKlz1c41HHtsy2BgJCdDOXre+H M0QVDPjFok6KeEkyvAWYxiKLm56TVhoyzYT7jDXhR/YDoN31obkysXXkh3Q+8crQb/up zZM4H2E6PYrX8uNnJg0y8YZFp5wzXx8LV85CRkgHdZkAJdc76RWnWYCM0alBahC1DBAl RmrNFs7T4fzCA9abVru2QgdkA6elb9dhDaAV+nlwQBU348hpiO4emXM/ov3jGJyuWqrQ sbY45j5pmaoZZhySrwse9PI1ebTiVvst2C6uo8RwIcXylzFSKFUs8wVz1hcoKboUF3hI PmJQ== X-Forwarded-Encrypted: i=1; AJvYcCWR434Rd4YXktcSjIGlr71r3AHRRAqEkykuR35u8pz0NEbv0R/3qd6jJhlhmONbmDfMoCSsugaXg/fbTx5KsAE=@lists.infradead.org, AJvYcCXPoD96rc21jqktV2xn37vTUNFaaY+MaedRSrHycbzP2Euh0MxjMja2m78okVi02yWVDegErRZHl4wdnYkUrR22@lists.infradead.org X-Gm-Message-State: AOJu0Ywb5GDKB4KU7475iwjPD5mF2uTixFJnH8W/50J37hpSzrJL4odf iCGcJANx9JhdiqMt20gf2ODlvsT3N8brlaqf1Qqzd0YIUWGuWBF39s+ehp97 X-Google-Smtp-Source: AGHT+IHjxclqmwCts53ey2Mkw8lOf7cm6f6r/L5Uli3GTjR48O81vxvj6U2y1w0YBmydxDpTTVPPDQ== X-Received: by 2002:a17:907:6ea4:b0:a8d:555f:eed1 with SMTP id a640c23a62f3a-a93c4946d94mr84366166b.31.1727392889478; Thu, 26 Sep 2024 16:21:29 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:28 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:56 +0200 Subject: [PATCH 05/18] leds: cr0014114: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-5-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1242; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=ReP7Qr/J0AJ2qUDKb/L8HtY4TnwQiLgJ9A1DOQKpN7I=; b=jAh+BzDwMT0vn09JLTdN0MvzxhKKOiSKKW8O/GHNIet44fgm7ZR14Rvbw3/y5IEMMN9dMTqL7 Q05KmODqeDkDJyq7FeIhBaMWdt9zpVsDxf2x/EqmSbBsNmsdTzpoi0R X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162131_856959_CE0DE65A X-CRM114-Status: GOOD ( 12.52 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/leds-cr0014114.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/leds/leds-cr0014114.c b/drivers/leds/leds-cr0014114.c index c9914fc51f20..7e51c374edd4 100644 --- a/drivers/leds/leds-cr0014114.c +++ b/drivers/leds/leds-cr0014114.c @@ -181,11 +181,10 @@ static int cr0014114_probe_dt(struct cr0014114 *priv) { size_t i = 0; struct cr0014114_led *led; - struct fwnode_handle *child; struct led_init_data init_data = {}; int ret; - device_for_each_child_node(priv->dev, child) { + device_for_each_child_node_scoped(priv->dev, child) { led = &priv->leds[i]; led->priv = priv; @@ -201,7 +200,6 @@ static int cr0014114_probe_dt(struct cr0014114 *priv) if (ret) { dev_err(priv->dev, "failed to register LED device, err %d", ret); - fwnode_handle_put(child); return ret; } From patchwork Thu Sep 26 23:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813738 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77A1BCEBF60 for ; Thu, 26 Sep 2024 23:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SJpECgac0QWqDyY0V1N/RenFz/N/de4tQaF+Hl64Xww=; b=2rtmMUxlmJf2XNuv9roiKbSrVB 3KozTVH96xtO5R9XmAbMURm3UQPYbwIkYuQ7urMyDFF5yllvP2vutS+HmU2sA6CArh4P8PS5uwrjk xBfqvc0quTFCWduVNWQrwAlZCa6+8YVAY4cKeWE1Sk2Y94caXNzL5X98GxD5AfYW1FLYnmzH7kn6j Im4FewKzTfykFb7KZ2mz7FPaTZtkpKcB3yMXG3AYlDfpCOwCpD3O7pWvqh5VU0objT506Z6M5C2wM elhds9jHaqVMtzVb+l4O8ckFBRJeMQ/qTAIGZMnztCGJ1oxOl1AOtoeA+PGivJhi+IVChZ2wVzlF7 8Pki/oiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxwj-00000009anP-1wdq; Thu, 26 Sep 2024 23:30:53 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnh-00000009Yx2-2RRE; Thu, 26 Sep 2024 23:21:35 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a86e9db75b9so235046866b.1; Thu, 26 Sep 2024 16:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392891; x=1727997691; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SJpECgac0QWqDyY0V1N/RenFz/N/de4tQaF+Hl64Xww=; b=ktmcMetnYjdmlL3fnRWXwAMExh8exKqKuSLuJIxTwAYjBEWlUjUrlKW171K3pkguP/ BZRVVPlkmcZjItVw+fO3KlFiL877gWw2fccMyZBSjkJxeBUtLNEay3r2ZWhy7mv4KXoB iR+2/ILFeOvehct/4o6tyU6zm8cu1PQosJsYRB2zW1h9CUeCrVuY6uwZqKywiV+Ot73E KU/8Z40FNdtdKfi67k7t0/fk50aVQnIG06ezv7guGL24HdgxpbYKxtLP+JeabZlfhuA+ VaSH1H9JVqVHeAyDzvFl/KS+feJlPMz841+2BrQ9ZMmjqGjDuYaNJEnDIrPAjcgyOm+K tipg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392891; x=1727997691; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SJpECgac0QWqDyY0V1N/RenFz/N/de4tQaF+Hl64Xww=; b=fH35FhnbmFM295Il8lCywpIpRjW/pAO3ccZ2C75A//6eY5tjB+4PnQY4AorryWXGWL RQNam3lCLUbPHu502tE3XypcKqSEqJGo32BAwJECO6YyzXGqgfyoT+Wf9J1YY8TaRI5b aYvFaVTrQr24Wn+Pk7NK2b2XdDiDY1265GgQg8rq3sGYdJI4cXfAZist65vOLy5gYGS6 aZrzy4vG/maL7376pPiOfLvodOWcmorUt06N79JDZKXUauNwyLT7uydIU+Q6v/6a+ksp duIpaUdU9mbr9+NHQppRyGtdoH55NRjDMVmO2/V0rRHSdJVKCmpZFmxJUc+2KWE9fFWg nY4w== X-Forwarded-Encrypted: i=1; AJvYcCUVmk2MAIqkmmlXb3gWm2u/Ake8LHAS1i49cKvKddDyBF2yNASyg2JsDmEaAzJu/Cx11Zhp8G52vzPP5Hih9d0=@lists.infradead.org, AJvYcCUcX6puxe3Khn13X9zdH9Ru410hO2rdCAEjtEbpE51ms8+RU3TZZG713/vkWcwwJbbm8IFQdAy0LVr7C3Ry/gWX@lists.infradead.org X-Gm-Message-State: AOJu0Yx8ZfAUhzthYMduYFFA15/Mdbc6uSJZbI9THgA6RhiA7BSzDvSy iS88tN0S+27fdsa4Vqqz9zOExBQFY29SmrhYgGUMwtvXxxIOTGREHPbCSpQA X-Google-Smtp-Source: AGHT+IGSWoR1fCEWrIDtr8bTLXKGUTs29eDV3zKtmwo1hMD14zDFeQuF3IPtFA71mpm1QVUnbVuMZA== X-Received: by 2002:a17:907:2681:b0:a7a:ab8a:38f with SMTP id a640c23a62f3a-a93c4a67dcamr84483466b.41.1727392891222; Thu, 26 Sep 2024 16:21:31 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:30 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:57 +0200 Subject: [PATCH 06/18] leds: el15203000: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-6-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1939; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=V8haQmgnRaMTwlG5K1E7vGaVHwPa1IZaQXMfy8Pe7ck=; b=sTqeCbZp2AB1Bc5Bt7/iASwDkXreNOXxX6b+ivRKl7l5AcLYxvapJeVNieVkPiZPuXREO5n0U 8lb5CaGQyzlD8lCR4pv1xcQkTYZrQwZmlV1zDdjGoSHCfLUUuJ9Nwts X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162133_682116_1DEE431F X-CRM114-Status: GOOD ( 12.96 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'err_child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-el15203000.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/leds/leds-el15203000.c b/drivers/leds/leds-el15203000.c index d40194a3029f..e26d1654bd0d 100644 --- a/drivers/leds/leds-el15203000.c +++ b/drivers/leds/leds-el15203000.c @@ -237,22 +237,20 @@ static int el15203000_pattern_clear(struct led_classdev *ldev) static int el15203000_probe_dt(struct el15203000 *priv) { struct el15203000_led *led = priv->leds; - struct fwnode_handle *child; int ret; - device_for_each_child_node(priv->dev, child) { + device_for_each_child_node_scoped(priv->dev, child) { struct led_init_data init_data = {}; ret = fwnode_property_read_u32(child, "reg", &led->reg); if (ret) { dev_err(priv->dev, "LED without ID number"); - goto err_child_out; + return ret; } if (led->reg > U8_MAX) { dev_err(priv->dev, "LED value %d is invalid", led->reg); - ret = -EINVAL; - goto err_child_out; + return -EINVAL; } led->priv = priv; @@ -274,17 +272,13 @@ static int el15203000_probe_dt(struct el15203000 *priv) dev_err(priv->dev, "failed to register LED device %s, err %d", led->ldev.name, ret); - goto err_child_out; + return ret; } led++; } return 0; - -err_child_out: - fwnode_handle_put(child); - return ret; } static int el15203000_probe(struct spi_device *spi) From patchwork Thu Sep 26 23:20:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813739 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F308CEBF60 for ; Thu, 26 Sep 2024 23:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=njNW1TfRFsU+HRABWUBqLsQLOj2MxWgzdzaH2G/Qjz8=; b=13yDjVfRbKFA0dOW3dSaIRKf7n ROC973hi+lCic3om59R9UzQjnd5QCJI7+Zsd4rMSTiIalUVjcknUy0PUDYh7eCqdz1f1Ij89Q+R+6 otvKuCqsvO510KTzG0FEM8tjYMmPpi7RNA1blN4odKc1uu3CWX/+JSNg+f7GGNrCXgiyGe4gGK6hc glG+ElUz09GG14uazJtyvE3La/JWGIf69B1JwMZMWcChfaDqHOkCzz03iNruLu6FhOn1b3HgHqKdU +cJIj3EGPO878n/ZI3LCPFbDI7kzohjf8Sz+E0nphT5l8A0aaHDgIqN9b+Fb9YpPte4XdCiGzQ6Ai 73CSSLwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxxs-00000009ay9-1X5T; Thu, 26 Sep 2024 23:32:04 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnj-00000009YyA-2MGz; Thu, 26 Sep 2024 23:21:36 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42cbb08a1a5so14244495e9.3; Thu, 26 Sep 2024 16:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392893; x=1727997693; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=njNW1TfRFsU+HRABWUBqLsQLOj2MxWgzdzaH2G/Qjz8=; b=cQxRWG7itid0wvs5xRvKx2goDlzHo6LwteT0CEYiiLbpkmtQz9NwM+ylflrrhg2oZe nnw89qA4sBHc4tBWQpwboKkc27yFNxRHkRMUzLAWfq7kwmpvnHqkh96L06OGQhE6uK9o ojZUwIME6AiRHQp1K2vChycSq4DOxjNn2IgYQIzLXW3aYVfqAAQ4ZUoX247mYl61KAKD BsNl23oAgKTIBn7d43scAaET+sfYdYMFDWKnsvsLFNbtoldapAo4vPkS1sIlcvNPLvRz y/brlL3nd35+ZBMhog/LkkmVX2M1aNJRTG01hTSbG1wSL/A05ba4H14wk8gu1uK+Na5c pa8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392893; x=1727997693; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=njNW1TfRFsU+HRABWUBqLsQLOj2MxWgzdzaH2G/Qjz8=; b=hI5Gy8oiY4gZYGZ38AF+CrwHz8b8nKF7pj41X29dXnV5VRX93yUiucwAsOX1d8Cnme SYMZhDexIX5Chh1iII5gEGEPsx31gJHIQY7KqSnu0xYEYA4r0M1LoiYC48FQJ3LbR+Sa 8TA2JB/8dgGbgbj7Q3GOSHF0QM6LvB+PsPgTY/Bc7ASNq4+Z3K7Pchu679p9FX1v+me5 wMgfa93MDWDDfkQsjRSZ+e5r35vm3MFeW1LCzpIAHVOY9Tx8CB3CSgPiPQcdfhc/W077 6L8qCU5o7qDUOlVsi0Ew93+KOYsiZEGJZEloIZ+EUSLqBT0lIqdZXJwk56hLlJ1t0j0r 59vQ== X-Forwarded-Encrypted: i=1; AJvYcCUr2CjfwcvZzot6na0wFFW8jEBAq8nVtJF1VeN0Quy61Oi9mgxz3Jx2ySGuaKdD4rthvX9yRygSsp5bFIdbnvxs@lists.infradead.org, AJvYcCXMNtOjQGJjydc05ntNzH6E4gTxePZOS4GqWH+k8dvykmmhherTOSbtEnxXx0zcBclOJlxrpexriGkWloPWW9A=@lists.infradead.org X-Gm-Message-State: AOJu0YyenPwFBWKSEyhqHF+ZpOZBeOXp3qtBSx4Wt6zt4GKquKu53SWX 16/OoSzG85qs9kcbSoWXn4hogMQeJGtGWgamxKH5UPV0VtLoRnRkCAm0/xUX X-Google-Smtp-Source: AGHT+IFoitU4rHzuAlGaN0CepshD8zukebslAy4qEv5jClIy8HmE5FNZn/uF/6GAUB+QSUSFAl2R6w== X-Received: by 2002:adf:f4c8:0:b0:374:b97b:c69 with SMTP id ffacd0b85a97d-37cd5b1b9damr807113f8f.48.1727392892968; Thu, 26 Sep 2024 16:21:32 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:32 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:58 +0200 Subject: [PATCH 07/18] leds: gpio: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-7-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1859; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=YvOQrDMAC/x5xAIds/zbIhc77SSn9FZnaj7kTpsmuOI=; b=F2/BmA3k318R3nNJ4o+UdX5dm9/ZS5qzvXg9eIRN46g7PjN1BIAHbn7DjaItKHdhF2qnEkj6C BtRfhRRoXksBEEmVczX8toVRs3aBAvQxOXiWB/l5LPYF47XYVrkWYG1 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162135_640284_993F3A52 X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/leds-gpio.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 4d1612d557c8..7d4488191241 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -148,7 +148,6 @@ struct gpio_leds_priv { static struct gpio_leds_priv *gpio_leds_create(struct device *dev) { - struct fwnode_handle *child; struct gpio_leds_priv *priv; int count, used, ret; @@ -162,7 +161,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) priv->num_leds = count; used = 0; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct gpio_led_data *led_dat = &priv->leds[used]; struct gpio_led led = {}; @@ -176,7 +175,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) if (IS_ERR(led.gpiod)) { dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n", child); - fwnode_handle_put(child); return ERR_CAST(led.gpiod); } @@ -192,10 +190,9 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev) led.panic_indicator = 1; ret = create_gpio_led(&led, led_dat, dev, child, NULL); - if (ret < 0) { - fwnode_handle_put(child); + if (ret < 0) return ERR_PTR(ret); - } + /* Set gpiod label to match the corresponding LED name. */ gpiod_set_consumer_name(led_dat->gpiod, led_dat->cdev.dev->kobj.name); From patchwork Thu Sep 26 23:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813740 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7242BCEBF60 for ; Thu, 26 Sep 2024 23:33:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9z03eGnj6iGqYzDELmW5r9JfCTcrG6sf4eOCgWvySkE=; b=AR+x8EQC515C8e19rbqe5PO5zF 2ldQ6s70OPqXQ39yWOeASSn9T3eWFtxnBsX9gbqJJMHJDCxiPWLTgE1FGEbedo6g2i1QuUGBo6YEW WN0kC2TBj6NglG5u3XmlZgkU0FD/C0PBhahI7w5qXma4WI5kSeToL4nFS9MfKb3VbcEL1ARi4RX4q 6PFQND6Ey2WUYQZIIU+wHEQCuKydRh5TY6BEUFp1aSd9NdECRXHa2cdsubqIVnB0Oukk+6xZ0jLXo MrzMmTsQo+CnGHrWAfEL3a/CxKQReXSneoBDOt47FRXOy5kOT3zTFH8gkA7Pg2JXS09LopjmWCvxr 3TiM0VVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stxz0-00000009b4h-26SY; Thu, 26 Sep 2024 23:33:14 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnl-00000009YzU-1W8K; Thu, 26 Sep 2024 23:21:39 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a910860e4dcso215223666b.3; Thu, 26 Sep 2024 16:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392895; x=1727997695; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9z03eGnj6iGqYzDELmW5r9JfCTcrG6sf4eOCgWvySkE=; b=Ghfrk/dFPtYh8Qq9iKCGw+lRdsmtgydRKvIq8KPzHwuRJtfb+zvydNjK/qV7TwRKIZ 6yr2pUQY1fzftMsqApKuZfHvcPaNKvV1CfWjuClfBuPKoLREPzFEf1xmHa4tVYZXe42C RsU6icKZzXxL5PFCJYvqSgqKTwCjLnDSsBMxQZMGS3Gb12KwKmcu+3g5WusUJLV1wmgH TouLPgfR9oAFxMZoNNjTtjV+C9xGQZOIln6RrKUkMS5qbmZqCbQCVNkEI6dTcvCUMwuY vY0ulabMZCIzeUfrFiW1uu11qtdwy6hhlbWAcemWuHeIywvG6+lgKpXq7M90H7tG1KFF vsBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392895; x=1727997695; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9z03eGnj6iGqYzDELmW5r9JfCTcrG6sf4eOCgWvySkE=; b=AwZvL2MjxFVsu7fb2aItC9NKG5L+xW9yYloRUr10dTlJZivRVDzK+P1kpid3rd2pOw qXPl/11z0nu8jN/+fAkzuyQ+D0g25E0QM/abHOAAV3014XoEa6SKIZCE96iRzSuOaXVt va/7tAPX+8g9O5ceUw35BntRhXSluRECRaT0lVMZ5HoKwiyPOR5cB5J9k7iYjjZ+eu6i kEZAU5JSBUKVZWttBklNzJ63W2pAuDs0+6EepJLhebgrYWOGwLRXmjlPkjwYpxHqxtOL iQRrhf5mtfFTGaH2graDxS9DPl0JfD0SaYdAfOhrKVjUz1ocGIUVelMOefmbtRFGWDa3 YMSA== X-Forwarded-Encrypted: i=1; AJvYcCUjptQ/UYNAz+iwEXj4AJYkCQHEuFIWCnfkXQAGWyyWzlvZHz9GEK2tgx5nTzObf3EbgyEjOYpLfbZAZ/w2b+8=@lists.infradead.org, AJvYcCVH2TbZb1ezXiarTTDr8W2d8KGm4vmnPvrE+JjbhhJVrGydZY8P2/7D/sg31rZwWFmnZiXfD1VFmRe7zdu/uyc0@lists.infradead.org X-Gm-Message-State: AOJu0YxhdO5t3hICEhDC8Q2SjVSKYBElSsc26ifuKC3f4Kx/qpfoMM1/ srVzihdtgf2/qJrOxuRxkfrUDmACQ8KCSgKpF+Z+vBuuX5wa94vlPIC7G6Ul X-Google-Smtp-Source: AGHT+IHzRwIU6UAzlavm/QZ6zyKdlkN5H8May0eKhpEiWtxIy3j8Q0eikPpKvoRwQ2Ar8Be+Bn0Hew== X-Received: by 2002:a17:906:4787:b0:a8b:154b:7643 with SMTP id a640c23a62f3a-a93c492a5dcmr98770966b.28.1727392894740; Thu, 26 Sep 2024 16:21:34 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:34 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:20:59 +0200 Subject: [PATCH 08/18] leds: lm3532: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-8-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=2745; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=v0iYfIBPWrhBeMk5GmLZkiz62OQVqii6tL7xBG0nuYo=; b=vv0qMx18gJDO2AXmo395Dj+OG11mPwp0TR26/SNLfM9jrHi1Va8TeNdbSx8stlq/n+ILIf4c3 gYOYGMQVm0qArDwfN4d+6vbuDJ3QihySKHfjHS8w1myjgZBJRpxCUpZ X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162137_445342_ADCB7C3C X-CRM114-Status: GOOD ( 14.37 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-lm3532.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c index 54b5650877f7..24dc8ad27bb3 100644 --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -551,7 +551,6 @@ static void gpio_set_low_action(void *data) static int lm3532_parse_node(struct lm3532_data *priv) { - struct fwnode_handle *child = NULL; struct lm3532_led *led; int control_bank; u32 ramp_time; @@ -587,7 +586,7 @@ static int lm3532_parse_node(struct lm3532_data *priv) else priv->runtime_ramp_down = lm3532_get_ramp_index(ramp_time); - device_for_each_child_node(priv->dev, child) { + device_for_each_child_node_scoped(priv->dev, child) { struct led_init_data idata = { .fwnode = child, .default_label = ":", @@ -599,7 +598,7 @@ static int lm3532_parse_node(struct lm3532_data *priv) ret = fwnode_property_read_u32(child, "reg", &control_bank); if (ret) { dev_err(&priv->client->dev, "reg property missing\n"); - goto child_out; + return ret; } if (control_bank > LM3532_CONTROL_C) { @@ -613,7 +612,7 @@ static int lm3532_parse_node(struct lm3532_data *priv) &led->mode); if (ret) { dev_err(&priv->client->dev, "ti,led-mode property missing\n"); - goto child_out; + return ret; } if (fwnode_property_present(child, "led-max-microamp") && @@ -647,7 +646,7 @@ static int lm3532_parse_node(struct lm3532_data *priv) led->num_leds); if (ret) { dev_err(&priv->client->dev, "led-sources property missing\n"); - goto child_out; + return ret; } led->priv = priv; @@ -657,23 +656,20 @@ static int lm3532_parse_node(struct lm3532_data *priv) if (ret) { dev_err(&priv->client->dev, "led register err: %d\n", ret); - goto child_out; + return ret; } ret = lm3532_init_registers(led); if (ret) { dev_err(&priv->client->dev, "register init err: %d\n", ret); - goto child_out; + return ret; } i++; } - return 0; -child_out: - fwnode_handle_put(child); - return ret; + return 0; } static int lm3532_probe(struct i2c_client *client) From patchwork Thu Sep 26 23:21:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813741 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E938CEBF60 for ; Thu, 26 Sep 2024 23:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SQNsFzUPUUPsb4bHTQ95hMBvvP4G234MZae0hcpLMbY=; b=cEXtF6keOI16S6KnRgGEFdq6LV ZIOpMc8D9kSXygRrhgVqbytAxZZv2CZuSX6/Ncg2HB1zHDELYqiWv9v51bFRGcLPy6AZolQnmLgT3 agTC37Ao08fKPr0MoPQdaV9F1l1dkQXLW0tzx++W/6w1BIrQ7XocHVz11W5hhewzSlZBgERBqgRFx up4p8jJzVHh0vL86gEfyWEs98Egia7NN+xQhD5lLW85ocGVNC+6Lr4ufDiV8cDbrrmd+nDSUDiO8+ 028XNTfc+fHNikz30deTP6xb6XMCxWfBD+xpaDMFmpfq7fE+AAQPsUzeyaLP64JOYKWBXvlAqBRiA r5mdzqXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty0A-00000009bEj-1fr3; Thu, 26 Sep 2024 23:34:26 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnm-00000009Z06-1YcB; Thu, 26 Sep 2024 23:21:40 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a8d60e23b33so205020866b.0; Thu, 26 Sep 2024 16:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392896; x=1727997696; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SQNsFzUPUUPsb4bHTQ95hMBvvP4G234MZae0hcpLMbY=; b=k7NXlvgxmpn7jF+xPR7cjO5uOIyCIG3qAYY+8QCjI+aQKAjp5RaOxgWDTLtJf05acK V92klloBU8o2EyJ/YyT6vgjWr1iD1r+ieqm/G8Bxp4QRfUHEprLqSFBzlarPHbRJeIb4 pEB5uxxsMVNyzZD87nLVn4DllwVqz8/K+dwfslhaPYLqkRWc90Tj4drvGrox7hV4WL1r O5EOi8RiVppY0kzYxV2yq+3WX1D+lYdkcEZXmGeRKgPcTDRSi9oiG/RJFGey/N812r5F WYXC3lTLbpHpIj+GMQHnZtecv2cR4COu7ej9ue9bJgt6PcaGUyBRGKMfEKMaDwfNeUTr YufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392896; x=1727997696; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SQNsFzUPUUPsb4bHTQ95hMBvvP4G234MZae0hcpLMbY=; b=iLPHVgXoA2+M9lmW5TFXC/D+IZzR429IdE4iw6tuqzBFf1D/W7A7zdj5/hJk/SJ5ON mBmj9D6dg938G55BBOBYJpGZp2pBlvBV4F0hG7ERF7+EVt26iFPIf3KPXBW5QgUKtV1q Lv+iTdmCVk/4IOECgjg72LWaUnxvoMVcfepPx2AP1qMydCV5aVq4we1IC6uBhKW64rSY Mk0AaJMGRTg5fEXcNuKePiKyKLRFD+ev/aPzU1fU2bAkqx8rJzSDvwk92j94d/GHtyY7 XPfKQYs+e5nxBg+iso3Dtbnx01vAEWSvPddDZD5qzAj+EbhW1lWXgC2pQxHmGW4C6B+J yQFA== X-Forwarded-Encrypted: i=1; AJvYcCUSKpOcSxIawsEjFi+jyvjUu+8KEh2LOpYeQVsKQ2XoFsRgrCn81L0MMQ7us4XkxESP+zKCYX8nGBVEw6x/XG4=@lists.infradead.org, AJvYcCXaBX6FOi3kmbY3dAn3Be9qd1iloUiloFDXn6934K9tujt8jGPkLLlRvtjGzRtoFchX7w9haK7Ogz90QQNQc6dt@lists.infradead.org X-Gm-Message-State: AOJu0YzZd2XYq12BsMuOhWlnlqwhJbLJOvKGBWYJCdgD6J0XAmXYnMMg z3++DnV/y33LdUAAxlybDJemdiYuxaFUUijy1E1KR1NbPMRI2i2DVAc2C5Gl X-Google-Smtp-Source: AGHT+IEyOGNZ71T4Vzvgj3bKvi7dihBSn/dSInDBzZVsM1XUQPQ44OJgPDcuSpfwKzM4zpJDbvxA3w== X-Received: by 2002:a17:906:794c:b0:a8c:d6a3:d03a with SMTP id a640c23a62f3a-a93c491f3b2mr103908966b.21.1727392896321; Thu, 26 Sep 2024 16:21:36 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:35 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:00 +0200 Subject: [PATCH 09/18] leds: lm3697: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-9-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=2273; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=fs0ieuWlVTuCmcLPVCaC9tRU1u41+9gEsw3Vo/oP6MU=; b=W7PpV2kxni+RR0wy6YwJI0c2sUNCxXu+i08YXpIMr6XkyMRvsaXGdZ2iuGj13YAu0Wxs7NeRP b7bgPKb5Zo6AJcco0ow/T7yOT/DNC6kxjWbdvRLSxzKncZ93rGydqGU X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162138_449632_5C893AB5 X-CRM114-Status: GOOD ( 14.06 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-lm3697.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/leds/leds-lm3697.c b/drivers/leds/leds-lm3697.c index 99de2a331727..7ad232780a31 100644 --- a/drivers/leds/leds-lm3697.c +++ b/drivers/leds/leds-lm3697.c @@ -202,7 +202,6 @@ static int lm3697_init(struct lm3697 *priv) static int lm3697_probe_dt(struct lm3697 *priv) { - struct fwnode_handle *child = NULL; struct device *dev = priv->dev; struct lm3697_led *led; int ret = -EINVAL; @@ -220,19 +219,18 @@ static int lm3697_probe_dt(struct lm3697 *priv) if (IS_ERR(priv->regulator)) priv->regulator = NULL; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_init_data init_data = {}; ret = fwnode_property_read_u32(child, "reg", &control_bank); if (ret) { dev_err(dev, "reg property missing\n"); - goto child_out; + return ret; } if (control_bank > LM3697_CONTROL_B) { dev_err(dev, "reg property is invalid\n"); - ret = -EINVAL; - goto child_out; + return -EINVAL; } led = &priv->leds[i]; @@ -262,7 +260,7 @@ static int lm3697_probe_dt(struct lm3697 *priv) led->num_leds); if (ret) { dev_err(dev, "led-sources property missing\n"); - goto child_out; + return ret; } for (j = 0; j < led->num_leds; j++) @@ -286,17 +284,13 @@ static int lm3697_probe_dt(struct lm3697 *priv) &init_data); if (ret) { dev_err(dev, "led register err: %d\n", ret); - goto child_out; + return ret; } i++; } - return ret; - -child_out: - fwnode_handle_put(child); - return ret; + return 0; } static int lm3697_probe(struct i2c_client *client) From patchwork Thu Sep 26 23:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813747 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6974FCEBF60 for ; Thu, 26 Sep 2024 23:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SbKG8yQzAXSNKnNqMlC3vDG+SObBOdoBsMSFHrHh/gQ=; b=CIQiY7EUoW+UDAZnDc+f0XyanI 7tJTx3TcDtFA+a9l82cd7h9QFYvbRbt39ypCyb4D5umgMA6Hk9XsFGm7ZlKpUxQRZZjE7IVG4TzNt 8y8auciEWBy89DFohct+CARM9nc9kmVQbxmHsk3dhWrUgtsTZ/RqOkM31ITCqT1QY5+BFfGa+c+4h 65XL7NWYvsXIT2skvXi/LM03XokFgtlP5ClOAWABgBUFY49JU8ZDUALBOx110hkOnBe4Rw9d85OIa gWxLaUVWZMieoU/vPUCMwfO9jEf4SkrAE/wRUYQeVLphIXK9srNN8n+pq5Nqx9QRYhzQLfJOaUOwl Fz1xMsmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty1H-00000009bLX-1gcF; Thu, 26 Sep 2024 23:35:35 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnp-00000009Z11-0MrA; Thu, 26 Sep 2024 23:21:42 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5365b71a6bdso1985059e87.2; Thu, 26 Sep 2024 16:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392898; x=1727997698; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SbKG8yQzAXSNKnNqMlC3vDG+SObBOdoBsMSFHrHh/gQ=; b=hg4YlA6YY+OAYErucdSDk0ziAGULYdtWJeMEoazmslDv8JtY4ywM6k1Tff+15FUKD3 6FzW61mE7zv9p0zRoizDaRi6kxtm8o97ZSCK5EbAPBXvw7BMAZS4snjzBlVtfA27UKjs Q13offwV8se/zT+qOXtXntNnevpjxyIPwpjo3xdQgUAplS5gSfAzI46wTm+ZZxF0oQeN iXFYf4U81oLKzCmHxZvh3m8avw17CvjdfSQ7QBy0obg8KU4VcXb/kIKbJgfvkACv/pH3 oUEsQnCW5PwyMQhb6NVL8nRF5TNO8OuwBe2FeYEyaB3l6Yu98LkhSzllLS3edRvU9yZm rxrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392898; x=1727997698; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SbKG8yQzAXSNKnNqMlC3vDG+SObBOdoBsMSFHrHh/gQ=; b=eKHduMDadpnx/ojDSMyvqXjYWXLR0by7L24Fq2jASEQc1vCDTHHUXn3E7fQ9zdDpda jmRgMYXt590cKSJAngQjhZUAHs3vyzMs8MB+OrmUiO5ZdVO9M6YAMzf4t97RpNWTdbgH LmRMlO3tADe4NY29IFQ8VVX0noU8SYpAYSaV3ZUpAAaPN/3cBj0SCtqQ+gPp3bw4gBT/ 2RCjpkmY3WyQ/ojoV0Ka3OpO0KvEg+1cByW31zmOJOMzsGXCFkAW43BEpdpAIJkQQg2h 3tAAD830nP+BJDIGW8LL6g6SEpp2NucGvQWWWZgb5c57wDlB+tp1MJezSE9qi4p7jjfQ wX0A== X-Forwarded-Encrypted: i=1; AJvYcCW1bqOzrVGD6Rrg1WgoIEZNTn1zz9T7COhDEln2s2HtN9nPanX2R2TshtFC0ki1T5236DnUtmqhcTMI8E2O2kBa@lists.infradead.org, AJvYcCWwDc/IpFZdlEDXDVtHyh69PiTkq1h362pTwyFy9Je9FK9ytsExElr3+8z+oM8bXYPBMlsrGLLNudbEacZCdUY=@lists.infradead.org X-Gm-Message-State: AOJu0Yxgd/KHMraUiPS/p6etsfBXLRRf8dw8boFoPdUHifYZd8vYWaGJ w9ymLxEK7TMFoqEvisug4xK9KZ3SbjuIv8Fvd8DtJWUHMxmhdCHG7O7Cg2Ze X-Google-Smtp-Source: AGHT+IHargOBULwRmlTYho66CY6TIIKNF6jhPFgs1jxdfin7EzZ3x+Ihx+4IF9Pdg3mdG2UXbYfTUQ== X-Received: by 2002:a05:6512:3b0e:b0:533:4477:28a2 with SMTP id 2adb3069b0e04-5389fc3bd4cmr983572e87.16.1727392898039; Thu, 26 Sep 2024 16:21:38 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:37 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:01 +0200 Subject: [PATCH 10/18] leds: lp50xx: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-10-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=2725; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=wVCMNpNXMBYRf/3Qo+CvGWvj1uX3gLZ/0II5tIZcKP4=; b=gvqzp5RpDFRs+Bq7QHctcXoi4uXIDmfAqWPfacNwek7XmLGTnkrq8CcrnDg8YhcpKi7G9Dh5l Mj0YUm6RICjA0yWhlPqzXPpjj3PJpAdJDq6e44FbnnPGX71dsvI63Wq X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162141_166235_85539774 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-lp50xx.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c index 175d4b06659b..32ca45aec76c 100644 --- a/drivers/leds/leds-lp50xx.c +++ b/drivers/leds/leds-lp50xx.c @@ -434,7 +434,6 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv, static int lp50xx_probe_dt(struct lp50xx *priv) { - struct fwnode_handle *child = NULL; struct fwnode_handle *led_node = NULL; struct led_init_data init_data = {}; struct led_classdev *led_cdev; @@ -454,17 +453,17 @@ static int lp50xx_probe_dt(struct lp50xx *priv) if (IS_ERR(priv->regulator)) priv->regulator = NULL; - device_for_each_child_node(priv->dev, child) { + device_for_each_child_node_scoped(priv->dev, child) { led = &priv->leds[i]; ret = fwnode_property_count_u32(child, "reg"); if (ret < 0) { dev_err(priv->dev, "reg property is invalid\n"); - goto child_out; + return ret; } ret = lp50xx_probe_leds(child, priv, led, ret); if (ret) - goto child_out; + return ret; init_data.fwnode = child; num_colors = 0; @@ -475,10 +474,8 @@ static int lp50xx_probe_dt(struct lp50xx *priv) */ mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE, sizeof(*mc_led_info), GFP_KERNEL); - if (!mc_led_info) { - ret = -ENOMEM; - goto child_out; - } + if (!mc_led_info) + return -ENOMEM; fwnode_for_each_child_node(child, led_node) { ret = fwnode_property_read_u32(led_node, "color", @@ -486,7 +483,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv) if (ret) { fwnode_handle_put(led_node); dev_err(priv->dev, "Cannot read color\n"); - goto child_out; + return ret; } mc_led_info[num_colors].color_index = color_id; @@ -504,16 +501,12 @@ static int lp50xx_probe_dt(struct lp50xx *priv) &init_data); if (ret) { dev_err(priv->dev, "led register err: %d\n", ret); - goto child_out; + return ret; } i++; } return 0; - -child_out: - fwnode_handle_put(child); - return ret; } static int lp50xx_probe(struct i2c_client *client) From patchwork Thu Sep 26 23:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813748 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9DA04CEBF61 for ; Thu, 26 Sep 2024 23:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QsOsZwrJIVejL5A3KYmk/iH+gmiGbQUrbC+6txQSDz8=; b=C1MeJ5FYws+t0LQHM5Xn/axpB8 aBH/b8v6IEcxP8timDRI5eYnSihJhgZQLx0H9GWrRRCiCnqXlDVWHZKpfY5Pq0EvtzMg178z264G4 9vNmpbxHK3PilIPezYQWATgke4M34Z7CE+9r0SkmfP+2Vvb8oTWReWSOvOzHyNd+dv8at/RtRMRxU HX1HzbwgBo2S4U86tX3kj9sGY+1zevuku7vUKInMzG8RJVoyiVUB4pTP/wFpcf/qu2qc20aKnbbT/ 9ULe3pFmFHOJGNDeaPqZGKJ3TKEnXQyJ05cCRpr+wNRQpOkiaM9FqEU6zL/BRYlecCq06A8nzZkri kYxaoFyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty2Q-00000009bVC-2bIV; Thu, 26 Sep 2024 23:36:46 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnq-00000009Z1P-0akP; Thu, 26 Sep 2024 23:21:43 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-374c3400367so1338904f8f.2; Thu, 26 Sep 2024 16:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392900; x=1727997700; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QsOsZwrJIVejL5A3KYmk/iH+gmiGbQUrbC+6txQSDz8=; b=PxjW1ScgVjBNmiRWdc5sbWVtKrxWSJO+pLubr5LFAa5WoE8uZNZxbFieDamDH5a4N1 SiU7diKek8GATXRKa2XPjtzzHoeQpT4uZ8KaqOazUfGK77C2V4WMuEpj6Qs2/+kTpZzq bsiEX0tsMBjmo4FNfrOUDEAq8WGbgMe/VTZT7ZKgGhdG2/qKwBSFqsLU8WqstgqiMS4H 1p8r2+BKTZuuoOGLPoozaQ5LHxG4KRleyQL6yIdcjr0za7BsXe6qkG7FU+GtZPYgFBTp kYN8o+kYPdiCwOu78NyvGbWlqjbY4uTQHyHt8EkRFaCgnY3elSs5uKG++xhsAXv+6WmJ dPIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392900; x=1727997700; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QsOsZwrJIVejL5A3KYmk/iH+gmiGbQUrbC+6txQSDz8=; b=MU/uOiAw+3pUTSbwAjFFcTi1N00YW4SGwXvc9280a8gYbkiqR2O50Lr50k6Ws+Cs4j jHSWCGlRxd4hZSSYROZH8krtwk1w6vzDZQs3P3wyuN6twdRjF5iy/WOnLkA7MDyGbeqH 2BAhcTxc20KimNccgkarsKSXp3tRdmO+l/bj9apYiXhf4EzetOSzQaI4Gk+aOEmc25gw SQaFfHP3UvUgrrn36cRZwbkVXeLjlTNEoysdq/uASa4shJIz3IjKL2Kd/bU/KnTUZdhQ TfqCIzZhjg/C/5qUeAT/C4RIYlVyCvyWl/JOf09f16ODrqfRjOSDeVkzftwTOuY2WgYj HqBg== X-Forwarded-Encrypted: i=1; AJvYcCVT/XWJXvxeaH9iUDBn27Yjs8eT4qkjhequavzdhfysqSNLP9ITYqoOj6Nox7UuzjUiX7kcoApw5GhlWt+YGL0F@lists.infradead.org, AJvYcCWItbiD3PWFOsVJFFWl9z6xSr7MLWHeJ++iUgy6J2QPeybX4wZXob9IQ2pAtz1sGa7Yv44s8WJI3kYVm12uHqs=@lists.infradead.org X-Gm-Message-State: AOJu0YzzFjsmayvbqdw9zyJZJB2rvINRleh2oJOc7qL/eo+A423Xs1Nd wg+rtw6iQ3HvujhzAYNVmsazMCsbSev6tbUSvz7uZ+nFtKv8kCZye8PynQku X-Google-Smtp-Source: AGHT+IFUS8qz9IpKL5ZcAZ8OyFyLvVNgici/BBziOfQFbnEaYTDdxY4F9CAtftsOOYRvJ/CoOPKo9w== X-Received: by 2002:a5d:574b:0:b0:37c:cf1a:b2a8 with SMTP id ffacd0b85a97d-37cd59def87mr961455f8f.0.1727392899862; Thu, 26 Sep 2024 16:21:39 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:39 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:02 +0200 Subject: [PATCH 11/18] leds: max77650: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-11-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=2297; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=GGAv58INZAAcONt61Bpt35Ntgip4w7Gu6UUVWWUtppE=; b=8bF3DQ/2DWcbOXH4dFor2UErTpk8gkcWEtJam43Nw0mF8/Zn9foJ+D7oYX405KrNhZyrd0vzr F5Z7Ns6Yd7HCiI8Ke73l2dScfUxJ1IBnD7u7ujtB4pnx6fEvO1lSltl X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162142_216548_E902BA78 X-CRM114-Status: GOOD ( 14.91 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'err_node_out', as an immediate return is possible. Signed-off-by: Javier Carrasco Acked-by: Bartosz Golaszewski --- drivers/leds/leds-max77650.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/leds/leds-max77650.c b/drivers/leds/leds-max77650.c index 1eeac56b0014..f8c47078a3bb 100644 --- a/drivers/leds/leds-max77650.c +++ b/drivers/leds/leds-max77650.c @@ -62,7 +62,6 @@ static int max77650_led_brightness_set(struct led_classdev *cdev, static int max77650_led_probe(struct platform_device *pdev) { - struct fwnode_handle *child; struct max77650_led *leds, *led; struct device *dev; struct regmap *map; @@ -84,14 +83,12 @@ static int max77650_led_probe(struct platform_device *pdev) if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS) return -ENODEV; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_init_data init_data = {}; rv = fwnode_property_read_u32(child, "reg", ®); - if (rv || reg >= MAX77650_LED_NUM_LEDS) { - rv = -EINVAL; - goto err_node_put; - } + if (rv || reg >= MAX77650_LED_NUM_LEDS) + return -EINVAL; led = &leds[reg]; led->map = map; @@ -108,23 +105,20 @@ static int max77650_led_probe(struct platform_device *pdev) rv = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); if (rv) - goto err_node_put; + return rv; rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT); if (rv) - goto err_node_put; + return rv; rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT); if (rv) - goto err_node_put; + return rv; } return regmap_write(map, MAX77650_REG_CNFG_LED_TOP, MAX77650_LED_TOP_DEFAULT); -err_node_put: - fwnode_handle_put(child); - return rv; } static const struct of_device_id max77650_led_of_match[] = { From patchwork Thu Sep 26 23:21:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813749 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 646D9CEBF60 for ; Thu, 26 Sep 2024 23:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=m7h6S8dVKu0rivFQ344WPkvtRjYXL2xD9tqPuM/hQA0=; b=eHm86RWbXjGAKvXxKS1RqIadvl zFGF7RNkrAzbtO3+wk+AUwEQvIznBwcOr3lNigTEFCYCPJQEC6ccY91cPIJcWsZflwQh+tL8BZT3J QVnJme5GyJbymC9vTbxzy0VL5mLTrM4D/gyLfXRxTv97EJmOOQ/PcCk6p3TbIrubu/U3pyty0Wirs aYxke6UVPg8S03IDmEkXVN6nUD3kGjHbxEWVyJlTD0eQh8q+YckzOpS+9JSfLQFeg//WdVPO8Q9gD ldlB/zan/RC4kiv8vI5zXzN9ANitLB+bLx2qkEEApcbsY9dY3gW+E1nuTvJ7/wrYKTEqhcqS0XHdE z6/RvgZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty3d-00000009bqZ-1Vv5; Thu, 26 Sep 2024 23:38:01 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnt-00000009Z2d-0W57; Thu, 26 Sep 2024 23:21:46 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a86e9db75b9so235064666b.1; Thu, 26 Sep 2024 16:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392903; x=1727997703; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=m7h6S8dVKu0rivFQ344WPkvtRjYXL2xD9tqPuM/hQA0=; b=fzEYUtEYafeXp1K1Wxnud6vDdbuPhLu//Rokmhhc4g6dUQ7KW5WAaBOHH+T3/du5uY o/vlVxR9GXcnJO0yZ+Ph46lC0eyn8YrlIU6rZG8xcmqMe3vavYjFwV8npHqwkqLKlDKM ClTgyBnpRmlYLxXMJXoLHTyjYegFaCXfqTiV8kKOL7+44WTzy31av8XrkVCCcDF3ju9o uOi6PpPOKzhfSzoSB84AN1JZJuliWwu1SmR8oAw5Eu0YEDtJRJxXOja5W25swHp/1ZFw je+YLMwt9ML8ZFHQ1xz2NK/TxYBeTshg/rkLGx/tiFPY8JUVlxCsGM6eO+eko1s2inzZ lPYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392903; x=1727997703; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m7h6S8dVKu0rivFQ344WPkvtRjYXL2xD9tqPuM/hQA0=; b=c37qmEe9QMRzhUDXMvMrZ8yeanZacIYGX64leRzd5r9bolq0rY2m9xMOxQaH3k6lPa hWQsdhBiqDcgC8yUTy3WuBhCBFzfcI8glJF2GrqTcIG3jG2ynkxl7xYvXYhh6h/Ojju4 M+eF8OCXio5iC4kmPjccDyTZUDzFryoK02/DYgwNWGtJCmuAF/jOg/x+ZNZbzYr63XBJ etWLZZU10djkVOLdBJHVvLrYt7PtTVaanbYBkc/TRLxYGkzwJJgfpNU/Tf/1GqnCIdWA L/eDvCszf1hD3YlZK8c6M8C9x2QMWl7iM7C3BGZfqS4L5MEBN4zBdaGvosJU1P/wSZLW bcuQ== X-Forwarded-Encrypted: i=1; AJvYcCUAWBn1N5N1VR553N/i3VzcGB4OWOqeVQvsPChYjsoLmmTS2tMeIc6ICBIv41oTl/G1BinaKNkob4eU5qniSWY=@lists.infradead.org, AJvYcCWkNZbUDWWX705iuufKMNuXdQoASqfzmqRb++v1Ujy5A3WK/Csvm6WK6JyNBfi5gBsBixM7MddrHDzhmbjeLqmh@lists.infradead.org X-Gm-Message-State: AOJu0Yw6l17Wsds3W/rR2RjRWr/bKoIdWYBFftx7RRV+FE8oYmzfiCyJ 0Z3dAeo7K28+IBAzmT0wVlRcger9a22LoOZJj1wD6vSEygNAsYVpyA7Czc+Y X-Google-Smtp-Source: AGHT+IGvoYtTRlxo+ZCSr+7IZ7oL03DwfddA8kVTy/0vVLsrqZIZv4yAr3ANwPUYnXfyhoxnViIYyQ== X-Received: by 2002:a17:907:3fa2:b0:a8d:29b7:ecfd with SMTP id a640c23a62f3a-a93c4aab828mr100357366b.54.1727392902592; Thu, 26 Sep 2024 16:21:42 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:41 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:03 +0200 Subject: [PATCH 12/18] leds: ns2: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-12-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1248; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Jz/4B/tgbBWqjdHctAGZYjiz0MxFy7WzJiMpp8ER/SE=; b=qKqtyfzAGtYGnjb8UqcfA9/S/SX/eIKdm4rVtvNbSdblTDBXwzHMlUAHLJLiyKXWonL5oGDQU 78Jcr4LvBg5AaqQMyyw/4oVbokWmBpUiGyTqttgSpH73fYZpZIVLpnW X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162145_230156_611551A3 X-CRM114-Status: GOOD ( 14.12 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error path. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/leds-ns2.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index f3010c472bbd..4c6f04a5bd87 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -238,7 +238,6 @@ static int ns2_led_register(struct device *dev, struct fwnode_handle *node, static int ns2_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct fwnode_handle *child; struct ns2_led *leds; int count; int ret; @@ -251,12 +250,10 @@ static int ns2_led_probe(struct platform_device *pdev) if (!leds) return -ENOMEM; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { ret = ns2_led_register(dev, child, leds++); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } } return 0; From patchwork Thu Sep 26 23:21:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813750 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FBE2CEBF61 for ; Thu, 26 Sep 2024 23:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TyRYSLB4FUMG7ZQozSGEenWyDF3XZ2iz0mCpEEN+5z4=; b=3YZyIoY0Uhc0CdNuxN11dLKtGG b7/ojWgSEPImGhuS+9bVuZ3WiphtSLlUiBJUzszW0C6xGYWNPG0vK2ZAWkyQeQKDoeHmwXMEWjL0u 2+vu31LWBO636fS+N2i+fzRe6x/tm5BBPBxOOtbSdd7ke40FsEPgpx/sNWcMT2MxoC4BfHdMRcGL3 MTqr2Dl8rVBhyrjMpC7l+dKuAHma7THXYCQC0oplz/Ga70R9wprE11H0mQnyvp0rsI0ox3LKGTy+B VheDVuf8N97PPyTmV/Q+5VgtRzgae4hIBSlBJW2Y8DTe6Z1jyy/R+p/kTDcHw1ByCSTc1XPzJVqbL OtvrzkUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty4n-00000009cAE-0peZ; Thu, 26 Sep 2024 23:39:13 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxnw-00000009Z4b-2b9U; Thu, 26 Sep 2024 23:21:50 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso4774528a12.0; Thu, 26 Sep 2024 16:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392906; x=1727997706; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TyRYSLB4FUMG7ZQozSGEenWyDF3XZ2iz0mCpEEN+5z4=; b=hZEKYDhFjC7yXwskyJdyRDCc/AMDu55GKvlTfzj+ugvw4PQzB3P44lDkhJlyDbk8I1 w1IwRUqwMtQ0FqUfDR47jdoDmT1pfo3V36/wQtuyZNbeAKXcKTL+ZpfBi3w/EA1hkWBN y1RONobm2U5C7Kry+THuO1TLJ0Kl0U/TPIiUaAfjp4PmrSCJYxusgOjoqwdXDOaUZ2dW LmyDpPODIeKX7kZR92us059YDueqFcBgZkJeod6dpqYqeicD0P3FTxVyvAJ628Lw2Ob9 F7paA8GFNW4ncIy8D0HlJBKJPcdjd9ja2x66F+j0u41iEDsix3IwFoEbGepVpqcH/y/K 5YkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392906; x=1727997706; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TyRYSLB4FUMG7ZQozSGEenWyDF3XZ2iz0mCpEEN+5z4=; b=DJdxjyjBBKFMwVkA1Unu3JJMfZjXpEEkhp1ZCcClgUK35jTyBuRGZfYs//28nRLQcS iCEU9oraNHRA2ooDcfT41pDU6DPUULG1jUYmCnLt6xK/G0fVmHtqY6MQNvdsbsduDdI9 HMpJe5fbUkLquhc5UPl8rOjTsgJfF3HMHi4EmGBF8mB+rqVVMMrDmN+7SzzqhurrZGJL PRhUauNH5JnHN0S2YreHhctgfgd8wl10Xe8Qv2g48XVETafhkHrRadYNcB+7PX0MtLSQ RAjUltM017EqJDu0zs/95klZBOeGrGmwDfZ7zd2QA31bG4YKyJStmCq/yU39rsCafiHe 1WNA== X-Forwarded-Encrypted: i=1; AJvYcCUFME3JINsTQsFfChIl0+L+i1g4LbWywkVHMuRad8Y/rpjFYFkzbJhVamQRvSrIi8HMzO1nTmKIfzDRzGM/5oc=@lists.infradead.org, AJvYcCVWvwG+5clNMA3kqj7vM++6SCEBnaZGuZ6lHPZmqvCGCmq4lMYfNN6ERNJsaTL1eurEKOoo8MBHtYSCk9xl/wan@lists.infradead.org X-Gm-Message-State: AOJu0Yyp38q2+2WLx2FlSEPwx+p+Co+dyYthr3NuRmaKgGslS77idfCl thPsMeno+tHbW85CqEffwzmyhpAC2pRBMwwiF8JJowNadLSLpkj7F7OyyNjh X-Google-Smtp-Source: AGHT+IF2h6rfpoYNPcv3IJUyf/0VxJB+Tzg7enQ3X9qTLHoriZAfUF5SXe05FRA9//n3nOpoi2FKjQ== X-Received: by 2002:a17:907:36cd:b0:a7a:acae:340b with SMTP id a640c23a62f3a-a93c32119afmr152457166b.31.1727392906224; Thu, 26 Sep 2024 16:21:46 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:44 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:04 +0200 Subject: [PATCH 13/18] leds: pca963x: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-13-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1968; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Pv0inpasEwKB4z2yQMzZWyX6wkHoCypZJXtRjmgK+mU=; b=4OyN2lOQijDJ7XTOSToVZf5Jm5nLKGku+MN88b0WkN8LPNF8MQ75n8vIksJCldHP70NcDZrab N/kVJn2HWk2DcMaBUelGlqT9fiv7ll/wbB/w8wUBdi5v4GKnZbdtw3R X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162148_697422_E895649B X-CRM114-Status: GOOD ( 14.29 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'err', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-pca963x.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c index b53905da3592..050e93b04884 100644 --- a/drivers/leds/leds-pca963x.c +++ b/drivers/leds/leds-pca963x.c @@ -306,7 +306,6 @@ static int pca963x_register_leds(struct i2c_client *client, struct pca963x_chipdef *chipdef = chip->chipdef; struct pca963x_led *led = chip->leds; struct device *dev = &client->dev; - struct fwnode_handle *child; bool hw_blink; s32 mode2; u32 reg; @@ -338,7 +337,7 @@ static int pca963x_register_leds(struct i2c_client *client, if (ret < 0) return ret; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_init_data init_data = {}; char default_label[32]; @@ -346,8 +345,7 @@ static int pca963x_register_leds(struct i2c_client *client, if (ret || reg >= chipdef->n_leds) { dev_err(dev, "Invalid 'reg' property for node %pfw\n", child); - ret = -EINVAL; - goto err; + return -EINVAL; } led->led_num = reg; @@ -369,16 +367,13 @@ static int pca963x_register_leds(struct i2c_client *client, if (ret) { dev_err(dev, "Failed to register LED for node %pfw\n", child); - goto err; + return ret; } ++led; } return 0; -err: - fwnode_handle_put(child); - return ret; } static int pca963x_suspend(struct device *dev) From patchwork Thu Sep 26 23:21:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813765 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36FB8CEBF61 for ; Thu, 26 Sep 2024 23:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hHGLYSMhagE5fSOewtprIrN3fA4YzjKM29kt0KG+UpM=; b=ohVtjKR/NfxJvNTQ9p5ROEVOV3 zNmpU3yB6f2HvruaN8qTmVlkmvF6o7qg4Af05CJmPGPSzNBJYUkw2dtzqg0gKcMIm1WB4vgQDXQqw bK5IMa1wi19IDJlxRZHsvBCL8ikMYoxiDPGyoG9hJiSSDKQ/Fhj+P6CuiVaqEqvT4kDIoGe5MgyA8 3Uqe8XEkIZAsPNA2lW+x7DgJRHJPmozybXz35TWKLciWsZGUa+ytGDMKoDgqNnWkd690+H47guJ23 9KNvOwpeim/TU28RNIjvoTDfcQTROCkAYPVoyOqW/MvYn4mpTWZE1+c9QqqvhrmXPYbPTk2siOivU Vkp+QeCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty61-00000009cZK-0Kiy; Thu, 26 Sep 2024 23:40:29 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxny-00000009Z5R-2h4q; Thu, 26 Sep 2024 23:21:51 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5356aa9a0afso2430702e87.2; Thu, 26 Sep 2024 16:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392908; x=1727997708; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hHGLYSMhagE5fSOewtprIrN3fA4YzjKM29kt0KG+UpM=; b=nPWU6mDFJr/znNxSpxt6AXwI6AH/8HUgj2nBTcBk32PLW2WpC641RxNN7t62fPKjPM xX7llylUoQ/pegngCXVbwidEWXkaQbxej7Bf9d/VwEROKnV8XQjRa5e/wRVvKiE+GUho 7fyN8idu/XRz1cy5GJtlotU0SGJ0TcotHXI0BX9LNgB3E/kCwpltaX1qXw/onXgZ5409 Xm40UGRMVGPVjy9vFnmjxBqjU8BwSnQjy+ULWe3hwQpYtyBzF3s/cmD5/8FE2dknCQxm /zTLgCSfkFSLGRRdQelNNi3UMOi9zwAghqXT4HhRbIr5W/FW5sbdCJ6iAhzBlRNSsSGJ V/6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392908; x=1727997708; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hHGLYSMhagE5fSOewtprIrN3fA4YzjKM29kt0KG+UpM=; b=Wnlk1QC7WnV4pVmGYRPSPv5AGf3fwrggT1hspjCgBrZlwlRMweKvIAOoAfDxfqOr0g It1t3LGde1ZO8/IBcJ9kBqvEmO8uplXp1aVVC97lmxAXZY5xQrGrpACJ8UnD7lcrjnYW vg1tu17SY+ybNn8bwnbDBqQXJosDW9XsKw6VhCFz9zKIYq5rQtvW4lP7STHI+iwvWbmK B+3Ib+cE+ZKg82oX6FzPwyN0No9rD6zazC6JABLSfizfWd0xk0zSUnq7Fb02FzV8LWX0 W95pGJH9KmdrtJhPI/jFVVriri69c35APvvOYBUvtnnNcWOIQkQ0HRJsV3bcm3LNCJp6 TiRQ== X-Forwarded-Encrypted: i=1; AJvYcCVOqytM1HcxT6CX5+gpYkEH6tBB3JCDJv3bp8BO0KNT2isv9Gd+n5RTUr12bB3d+S3Hh0YClNmOtXYNVn7DL9U=@lists.infradead.org, AJvYcCWs4nsGyGxAzmhecR6/DcSBJAlstep0fcMlp3JpVMSVxCTwyNNrL7Wx/fNw4lfzfNqO4B0CDpXHljfQPPRIw3Ut@lists.infradead.org X-Gm-Message-State: AOJu0YxMkusHQf183oYWssU0znP05UIDcDX3lYtdThaxbYX7tCzh0jg4 JhU94UFKkc9g606em++Jw6cRa+S4nbfVp0FRQoCnbnL5gWwJpNKp3P85sV3P X-Google-Smtp-Source: AGHT+IHlD2G2E7GSRoMpuBNsI0X5mi6Ua8JvRQEFmnFC/8WxUbT+wMtBf0onF8DjiKH20jT0Ia2fqA== X-Received: by 2002:a05:6512:3d8d:b0:52c:9877:71b7 with SMTP id 2adb3069b0e04-5389fca4475mr1025221e87.59.1727392908032; Thu, 26 Sep 2024 16:21:48 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:47 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:05 +0200 Subject: [PATCH 14/18] leds: pwm: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-14-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1845; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=h1wO2Y5y3snunIjQvp9wEO38mWmGcGSDzqEh5GMe7fI=; b=J1kuyS1rctHLvv769c4EZm6T2XBPkiw9ibZoWkMdEGXw3txrJVIYnZXZTRhRj50ABFFbr7IzF VoKASt4M5y0BuAGDuF4YB9A9l9nGY60szrd+yDBg2/dQb2i/6z43d4J X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162150_718474_515D19D6 X-CRM114-Status: GOOD ( 14.75 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'err_child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco --- drivers/leds/leds-pwm.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index e1b414b40353..7961dca0db2f 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -140,21 +140,18 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv) { - struct fwnode_handle *fwnode; struct led_pwm led; int ret; - device_for_each_child_node(dev, fwnode) { + device_for_each_child_node_scoped(dev, fwnode) { memset(&led, 0, sizeof(led)); ret = fwnode_property_read_string(fwnode, "label", &led.name); if (ret && is_of_node(fwnode)) led.name = to_of_node(fwnode)->name; - if (!led.name) { - ret = -EINVAL; - goto err_child_out; - } + if (!led.name) + return -EINVAL; led.active_low = fwnode_property_read_bool(fwnode, "active-low"); @@ -165,14 +162,10 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv) ret = led_pwm_add(dev, priv, &led, fwnode); if (ret) - goto err_child_out; + return ret; } return 0; - -err_child_out: - fwnode_handle_put(fwnode); - return ret; } static int led_pwm_probe(struct platform_device *pdev) From patchwork Thu Sep 26 23:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813766 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3767CEBF60 for ; Thu, 26 Sep 2024 23:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KxTvYBMAH6K76CxmrsMQCXDoyFzNi14dQqKe3hz4/gE=; b=BhJeCzOM8S/4yU9XbOL3yVeUz6 aumDlaTIaPyevNcCapBUBk7zRjNI8YOIUzbIv0ukyjSb3EGmRUKmgcPIKzSuzdK598wLM4J2c26hX 9W1VILwF3q5vsn2qu/u4COCCXiimyXeW69tV/vxZaHj5hqhBnhWhS4xgPyMzs2YBbKzT9IGgiIhh+ xTQT63w7Q9oVVbSe3KCg+4HIlV5BqEfCmA1R4x89kf3w8MPZBMmp2Sq7pTZdHGBqGsARa75JIwopn LgDCOkzO6Ik9SOSfd+zPtzHwOvGSMhLoDguKriqD8a1p0dOV1x71vzHyDADZ+DzpqkVUtiiIsqccR Y9EsMHpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty7A-00000009coj-42kz; Thu, 26 Sep 2024 23:41:40 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxo0-00000009Z64-0HuC; Thu, 26 Sep 2024 23:21:53 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a8d56155f51so176268166b.2; Thu, 26 Sep 2024 16:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392910; x=1727997710; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KxTvYBMAH6K76CxmrsMQCXDoyFzNi14dQqKe3hz4/gE=; b=gf/SNH2krvPHq6djD56DqZtlUD5e1tCvHE2lPUuC3CSG7iOssbz+sB1xlcQAGtBCX8 uh2uXk25C54z6PA6U+G9jQ74WVUYJrmU3eiJun1EycHJUksZCdABJNcDXyfhBwy0rYpc jYxOUfXpayuB/WSeCcJkT5/vdzpPz/P76AK5MYmHJBhTmODD/CKnuEYOZg3Zj8prmqe+ 10Kt9E6V/dAO42J33IZsBng7iCUrILUAW4cfebStft23v5J++Vslpju/lXVTv6VQbVpi n7MoV/o0CznminrRdIj+2uhDLWa0h5lBE6m4ZzMMSta66MUxtBICJeEetnRGqSHGhOcQ rIcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392910; x=1727997710; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KxTvYBMAH6K76CxmrsMQCXDoyFzNi14dQqKe3hz4/gE=; b=bDDfvyIl4376nUErq9uP35NgmBCP+sI217jHaz/ziOPTZ+qGwhGaq11SeFf8beW3Sh C6bD5C/FCCeo3Ev5SU+P1Zzi3mNSKOBQmk7Fe2nuOZK1rsrknNPwzsutbxw965a+QjUZ KXMB/japSagNNTHVBkcgETIgOS8vcRmIyiFDbTEM0KhaU8x8+3I6xU9GAGCe60vbu0Zh yqrY0p+8TnNvklbzjFJbGAf+0oyXKh1N1QZmwCfwsv9i4jLCGgQj5tGj0DnsUg1pLYn2 sUQNxJ5byFKQ1A2UJnVgg61GV49sfReBME1UwO30RjHRudDmbiQ+Ds904FvBACoNdBbQ O8Tg== X-Forwarded-Encrypted: i=1; AJvYcCVKbtL4qze/WeJTuP8CnIxuQ5scE+S+PYvYfHcbS+okjRKzmngwlB/7ldNoS64mIXIU8ZUwSxfsT76rpqiIKLF2@lists.infradead.org, AJvYcCWf6qBTCG1F7a2rdUxZarkSAkrjsX4IKjxLUiY+WCDTwouU/1ykp3+K5Nv/5I/kXaXm5KErd1TzsYqD52998Rk=@lists.infradead.org X-Gm-Message-State: AOJu0Ywbv403QWyuHK+S37n6LQv64KNK/YrKvAFBkNsbtq8xyH4KHWJw /NoD7SRpMeLa3FKYaidCb8LzrKh9NJ4cpTCgIFK4xAoo/1rcWaJb6zbkQtrc X-Google-Smtp-Source: AGHT+IGRFpVHqTjLsEHhuX5kjF6xyPuBHJW+zrrF725EKx1jN/+wFjAEQNE/hCfydi8zaA50x0RLFw== X-Received: by 2002:a17:907:7e85:b0:a77:f2c5:84b3 with SMTP id a640c23a62f3a-a93c491f380mr76021266b.22.1727392910067; Thu, 26 Sep 2024 16:21:50 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:49 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:06 +0200 Subject: [PATCH 15/18] leds: sun50i-a100: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-15-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=3318; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Fm7F+4MLH582iBnJnE4p4FnmOoiX1OKki6L98DcIN8s=; b=f73Nl+8leOeKTCe124dSLiK3ZYOKg3Q7P72HDYcJ6IZ07AvEQUvjA731Hl8QEMGU3egu+VFHI +vPMS/2qRmIBoqp6rhj8XlbLqzyW7QoOokmZylHrnKLr2RNAmi848fy X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162152_159464_9A3AE494 X-CRM114-Status: GOOD ( 16.93 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). The error handling after 'err_put_child' has been moved to the only goto that jumps to it (second device_for_each_child_node()), and the call to fwnode_handle_put() has been removed accordingly. Signed-off-by: Javier Carrasco --- drivers/leds/leds-sun50i-a100.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c index 4c468d487486..03f1b6424692 100644 --- a/drivers/leds/leds-sun50i-a100.c +++ b/drivers/leds/leds-sun50i-a100.c @@ -392,7 +392,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) struct sun50i_a100_ledc_led *led; struct device *dev = &pdev->dev; struct sun50i_a100_ledc *priv; - struct fwnode_handle *child; struct resource *mem; u32 max_addr = 0; u32 num_leds = 0; @@ -402,21 +401,17 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) * The maximum LED address must be known in sun50i_a100_ledc_resume() before * class device registration, so parse and validate the subnodes up front. */ - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { u32 addr, color; ret = fwnode_property_read_u32(child, "reg", &addr); - if (ret || addr >= LEDC_MAX_LEDS) { - fwnode_handle_put(child); + if (ret || addr >= LEDC_MAX_LEDS) return dev_err_probe(dev, -EINVAL, "'reg' must be between 0 and %d\n", LEDC_MAX_LEDS - 1); - } ret = fwnode_property_read_u32(child, "color", &color); - if (ret || color != LED_COLOR_ID_RGB) { - fwnode_handle_put(child); + if (ret || color != LED_COLOR_ID_RGB) return dev_err_probe(dev, -EINVAL, "'color' must be LED_COLOR_ID_RGB\n"); - } max_addr = max(max_addr, addr); num_leds++; @@ -502,7 +497,7 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) return ret; led = priv->leds; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_classdev *cdev; /* The node was already validated above. */ @@ -527,7 +522,11 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) ret = led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data); if (ret) { dev_err_probe(dev, ret, "Failed to register multicolor LED %u", led->addr); - goto err_put_child; + while (led-- > priv->leds) + led_classdev_multicolor_unregister(&led->mc_cdev); + sun50i_a100_ledc_suspend(&pdev->dev); + + return ret; } led++; @@ -536,14 +535,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev) dev_info(dev, "Registered %u LEDs\n", num_leds); return 0; - -err_put_child: - fwnode_handle_put(child); - while (led-- > priv->leds) - led_classdev_multicolor_unregister(&led->mc_cdev); - sun50i_a100_ledc_suspend(&pdev->dev); - - return ret; } static void sun50i_a100_ledc_remove(struct platform_device *pdev) From patchwork Thu Sep 26 23:21:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813767 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB501CEBF61 for ; Thu, 26 Sep 2024 23:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NM+8ic/Px3mQTsuCcs62/53dsl/B3jVBAf4+IMQjl4A=; b=MqxNES60ZQI9Z97nKcLs7IuWD5 7OGQ0JRSkwqmu0P6C7M2wlTDWo8aYN++sy2uToXFOl2tsjqROi7q2f7tL75v6oxUVdxGdLYxNVm6o /u3I8N4VKUXT0GzbnWMPaIIRnxPPecsQnH/AWMu1On38SpwCv6/R6IRjbe8DVzzy7Q9UdxsGMfOGi vuidP+TfioyCHuk1Lj9thmI6faNMJrT4OODxGxP+LOGQWAj5sV35FwTsmpz6VI8uFVoG3Xcn7YGb0 JXHtZqrYBz20hPfaa5UOwBOzG44cnuRCaCoCEy1mzAiXjVoM58ttgOxDNgJN6QSh3J9qawUafk/tD 3pFASI/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty8I-00000009cyX-3TuM; Thu, 26 Sep 2024 23:42:50 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxo3-00000009Z6m-121Y; Thu, 26 Sep 2024 23:21:56 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5c5c3a1f474so1584782a12.0; Thu, 26 Sep 2024 16:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392913; x=1727997713; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NM+8ic/Px3mQTsuCcs62/53dsl/B3jVBAf4+IMQjl4A=; b=ejSzFDOMLLXVhan//VTgqXkGGxZ03kYIhH1zNxPbqe6xX120ntGGGjRcUZt6MhiqeG D3vZg/aqaFs3W4w8GB7af2fFj+LuM7utnXV/gADcT9OOeREBg/cqQDNqxJGupRNhHVnY HNnKCajSk4JQfqrepOQ3ZvjCoqebMwHh9bXlM0cA5z4dGDSDGKn3Q5MPmEzDziIBT/1F /SVwlvS0zgfgKRPy2psYloQ5mNT45O1prZBgPrLTMUk9ivUrfM4ysvUdZnJvXEABIZY1 2/3SA5otAodDlYMlDhBOcmrtOCsn/pTB6U97jIc1QpZHVaELSkBtUROr0eoS+S0gkC0W fQJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392913; x=1727997713; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NM+8ic/Px3mQTsuCcs62/53dsl/B3jVBAf4+IMQjl4A=; b=nqIt7XBDcTARgU8v2y4HHQ9ENP4A/JftADVeeuXtxCxxqXcRoCNse21opdpRNdG1yu MP46yxjd4xuhjHHqnS2L6T48zlSymCk8M7J0+RmrK5mSbLT1yNfiXstkWNT5Yw47k2Cy iw7xzPmguFLQhOhVvGpWlwrfUymmbMBu+wFM/VS7EYpS3dYhw7LZkUF9BOaQGOSwA6MR xJiea20lHZj7q+XhpcKAFdTsdndVW0JO/hDylqFO2wicas8y9V9hj25qylzIJExxnfks hbkEevOCIY0qvAE3sqLkfRWdcj2GnxqM+eJGo+p+VN+6/ZN90dez3MyuaMIFF4VN+3+t sGyw== X-Forwarded-Encrypted: i=1; AJvYcCVIWtJzhGMZ30w6qvGPRSO/gCc8IKJz2+mYJLIVsL0mXp1zpt7fHsK/EjpbLmIw6sJZIac2DpQKVYMvuzIQL+FS@lists.infradead.org, AJvYcCVORfyEspMQjkbIV0uXoqsl3wOm9h7KfFiGspwlcG21npco4eNV4SNtXfLOYQi7w6ntYNiYkZ8piG6aTxVBqA8=@lists.infradead.org X-Gm-Message-State: AOJu0YzJIY1MjDpQf3leYXrZt/KqvPZOAXmTYf6GVC6UZ5gtXmtzyFDv mDFSBGX0ap4lb6oFwpUjTS89nLyJ1YbUbY0pYANFPXXbRky3oPMl+MqZIT2B X-Google-Smtp-Source: AGHT+IEjGS5H1uM127zHsUDENMHQP4peBo2B0LKYmvOBCuq2OU03bEqMYA+oUjVvyxH/GoEWditQPw== X-Received: by 2002:a17:907:1c0f:b0:a86:aee7:9736 with SMTP id a640c23a62f3a-a93c4ac9334mr83767066b.46.1727392912970; Thu, 26 Sep 2024 16:21:52 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:51 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:07 +0200 Subject: [PATCH 16/18] leds: tca6507: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-16-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1443; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=uZ6AU+qHxNHc+7ZSbOLvFpKS951bl9x9VeT+GuFOE+o=; b=NGlWdNHQgGpOwQAC3L9GY90Rn3MtzUIW2LrL0gjOsK+kWA98v8Pom7eibl6iKW9m1g68g/UJo C3/17jLgkcHBEyM4LlOU2NTx5/2Qx+Dapk5n5sfsJBSp2CMoP1wmmcy X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162155_321516_21958044 X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error path. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/leds-tca6507.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index 4f22f4224946..acbd8169723c 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c @@ -658,7 +658,6 @@ static struct tca6507_platform_data * tca6507_led_dt_init(struct device *dev) { struct tca6507_platform_data *pdata; - struct fwnode_handle *child; struct led_info *tca_leds; int count; @@ -671,7 +670,7 @@ tca6507_led_dt_init(struct device *dev) if (!tca_leds) return ERR_PTR(-ENOMEM); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct led_info led; u32 reg; int ret; @@ -688,10 +687,8 @@ tca6507_led_dt_init(struct device *dev) led.flags |= TCA6507_MAKE_GPIO; ret = fwnode_property_read_u32(child, "reg", ®); - if (ret || reg >= NUM_LEDS) { - fwnode_handle_put(child); + if (ret || reg >= NUM_LEDS) return ERR_PTR(ret ? : -EINVAL); - } tca_leds[reg] = led; } From patchwork Thu Sep 26 23:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813768 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24D64CEBF60 for ; Thu, 26 Sep 2024 23:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WkHqvkI/1/i2Yqceu5g2GJiVANgvtprMciXZ8BQ+brY=; b=O+IKJohUcuS34YNLVicziALv+l olJW50w4on2BTC6WRcpHInZ0KlYmdIQIE5mLMOk3tbnKYnvWBi099/Ck9/8DzY9RF2q/bhs839CvW Lptn2O8PkY18F9tPnaow6sKmAdQzePU2Kg+7+vDp4CBdaCG1oRorXSZhPyUJuzRkFiFPu5JcR5hJU E8O09uwjfZvXpIw4z1nlMFrZGP6BGRS1pIM50yAPOHPDFfsI9wnIyBiuLTBTwkc3G/TdhPHMjmA3J EgJsY5W0MncNHyLbEc/ZogHmSHXUkYmjl7+8z8oasyem/mtE+X+6/qPgi/GsJcgrC6/IGJT5V+YcB Hd/mk6IA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sty9R-00000009d6j-0tby; Thu, 26 Sep 2024 23:44:01 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxo5-00000009Z7S-2dpD; Thu, 26 Sep 2024 23:21:59 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a8d0d82e76aso214563466b.3; Thu, 26 Sep 2024 16:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392916; x=1727997716; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WkHqvkI/1/i2Yqceu5g2GJiVANgvtprMciXZ8BQ+brY=; b=bTL9N6Bock9ASFVAaLZ98jG+QZYQ0CHUDd4Cj1lnB8fLDe1XBZvmpFMTDTr5WDVLbG 413CLIqrwbb9IGka/4Ck5VWQ9r34FSk4rZ9xs+PlUep1KUIKgL4NA14gXRmV2B+GXK0y Mm+3xUmzv+I2Sks7+wcTUr+2uaebvTSj+LsiiP9nDX47DN4LfTH+NhMcp/UNbGOsbzb2 PFZCcxooGkzpM35AkkyAQXdSQHYCBjKkUFwaeQan8FR++5R3JsaltVnXEL+6qaqvufFa LfBcdUBo9jYHMDKf1n0Rm5eo2guMC10wOJYogbFcGUMul1qS2tWRCyKXhd+Cpu8omuLW qfxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392916; x=1727997716; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WkHqvkI/1/i2Yqceu5g2GJiVANgvtprMciXZ8BQ+brY=; b=q4yppVGd3+v1gI5vlzIKmAsnNriozPgpbKgzCo+mEEL2r6LKwaAdYHngwIHORz1gWJ zyXkRl50aoqqNUj7mk9PMhW/nHSrofIY905Z3ZVTiSCG26mZ5UeBEJ/A74w/S1/P43SJ qk3q1s+iHVO93z2qc6WHGLjBbCx/DhvMJcW73XcoCizhm8KcY+jybAdShQVyrGthFMrm vaWNNObOygdYjTYP4w8OrFEMTLyX/LCRm9RF1o5BaPkB3jTH7Nitd+IrNAez1tpGZsC+ qV4JqgShSQTpUFFy/YeEAp7GvH+5gbv3cyMkoZ0y5KvwpA5gXWPrq3kbFRbFfR52Rbzb Hd+g== X-Forwarded-Encrypted: i=1; AJvYcCUSUuTL3hjCd92RyjhcTnon1IYg5sdKFuEpSg1zmzS/BgD0oq0ZTbl4HH2SzZx0xd/9BG60HMdLKvvZZ5gCJN4=@lists.infradead.org, AJvYcCVrS7hnyneWW7iiueyQSFsDYNoi9thOjhGqYK9w0iesxojPjP6ULg5NaRQf3G3ayRkodsujMW7mmxDqUbSC8PLs@lists.infradead.org X-Gm-Message-State: AOJu0Yz0Wr8Qkx6FZPAixmr72UtOs0pOlfFX6DHK2SmUybACIkm9gSYj RhMQxmwcHdqmUqFjkn76WhjYJCxrH1m03arVhYRLW6LzYaRFzYsYRVQXPAby X-Google-Smtp-Source: AGHT+IHu7GUf4pEGuh3ajW4RTtn5QFJeznBoUNPfpuLLhiJAhuYOKyTqQymBYsqixg5g1+2YdfLoVw== X-Received: by 2002:a17:907:7b91:b0:a86:c825:7678 with SMTP id a640c23a62f3a-a93c4a98df0mr96575666b.64.1727392915679; Thu, 26 Sep 2024 16:21:55 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:54 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:08 +0200 Subject: [PATCH 17/18] leds: rgb: ktd202x: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-17-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=1313; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Upol74WYOlhW6c4peUbPQECrXBC2IELBkPGR+0SYZwE=; b=f5ds5pKXTIF+B1jMaYwlb8PPJAHi7VfKk6RXlM18dKn8C3IQVGT8JccELHUU4Z+ooOWcfqKQS 27cVaVRUn+uAh7+rCzd53VFlBKfzGLxtf5g5DJWnaFLJwjdJFD+8kOV X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162157_740935_97ADEC2A X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error path. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco --- drivers/leds/rgb/leds-ktd202x.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c index d5c442163c46..04e62faa3a00 100644 --- a/drivers/leds/rgb/leds-ktd202x.c +++ b/drivers/leds/rgb/leds-ktd202x.c @@ -495,7 +495,6 @@ static int ktd202x_add_led(struct ktd202x *chip, struct fwnode_handle *fwnode, u static int ktd202x_probe_fw(struct ktd202x *chip) { - struct fwnode_handle *child; struct device *dev = chip->dev; int count; int i = 0; @@ -509,13 +508,12 @@ static int ktd202x_probe_fw(struct ktd202x *chip) /* Allow the device to execute the complete reset */ usleep_range(200, 300); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { int ret = ktd202x_add_led(chip, child, i); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } + i++; } From patchwork Thu Sep 26 23:21:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13813779 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 426E6CEBF60 for ; Thu, 26 Sep 2024 23:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gsf1H9vGvMDgxqrrd3JfvSIa5200NszB5Zt97OWrjd0=; b=asRqO2f7Ko9j+DZMN82uZwfiy7 dsEVC5yFg7mJCTSnuD/o9bqqtQK3vCJdMSwoY22Ab5d2ZFfpnXmCo3OSHeHenJsRDRv3Cdn0Lknel 50D3zzmoCIGBj5nnTx8cSDENI7ufMXgb6RwdRMeoQjFi2P3WJUdsudeKdq8T0mdbXi7svfW41uiBo V7rTwey+J+LK9Rzqa/DhClRI4pZNyMBbS2dKW7ewQy0R12PKrvYL1rG/tsruIklDZI/omB8uf7jvg 5r7B7cHoGOSpTGeROOIazH+Ixc5OjVl5WaQ/k8ULvtS8ZfyrnDgo0VBuBVD308YbmYDJu61Hj11D5 L3EzcV+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1styAa-00000009dE9-0d1I; Thu, 26 Sep 2024 23:45:12 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stxo8-00000009Z8L-0NXB; Thu, 26 Sep 2024 23:22:02 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a8d56155f51so176274366b.2; Thu, 26 Sep 2024 16:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727392917; x=1727997717; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gsf1H9vGvMDgxqrrd3JfvSIa5200NszB5Zt97OWrjd0=; b=CPXuCbWsn2nEo2ZjsFtcUhUMBkJZAG5pP5xYEgnB/DVlyRsglOyFCp6HjRGelV2ab7 unELuE2eyPQ9Jgc9LEHE2e/IrMkt493kNoWESysJg4gRfYfrKKH4fe3EjtbJ/7+9T5mP Q9BpX5sRRNyjF7xELtDpPfEal3EmXXxZ6+WN1kUztQdLfSWHX92OI/2tDVWAKUIRoQmH WpSd0OzJ7Isa2eIPbHM+K42TIC0rAYNPgtGDnmgmyd85OR8Npwr8JJ8bZAG2K6X3DsDW yQtc2Rm10zmMdEWkBbi9qtWbY6Q4sf8qHlLGeUku/twOVmkX6xa/sky+Q5Pf+ViM34qW P/Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727392917; x=1727997717; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gsf1H9vGvMDgxqrrd3JfvSIa5200NszB5Zt97OWrjd0=; b=AVX8HspeyPHu6x5ObJ5UEE7FDGDCcAwltlcZ88N5YuxJOSqSdPuprQYwT5wGGQeuuA 7RcvSabJiUdrnSKMpctceGLFBqFF695kSLuZgFgPsQmBsZbt7tcRtTDuIbJdjlVYaIY/ 0cGFVJrNfaCaGIL0iYePRABwWTCmW+D4OJLSSqGM81qMEjpmdg3Rq29X/XXytcsw39wI lC/ZxBGImHLz67Pmrm04GbsAyan9xmK9J51oaLVSPIvKHnmtJsm+Z+nTcmvS33M/gzK7 YWIc9qkGf2HobQ7q/vgtSWwt5iSvqvi2UdsXYi+K4ST6KsQXciQeLI5Wcy+XzjrDJWmG nnzg== X-Forwarded-Encrypted: i=1; AJvYcCUPHW3pfeCQ4DXXz1A10G/m66ifV2n3Vw4LDnV6deKOO3efAfFn9FWp8BDFZU8lngsiyr7KxT7kUtxzT0GhUwS5@lists.infradead.org, AJvYcCWnf2I5ozWR7APzrw5r/tdRH51HkByFRs/VFpO9ytDWwiEOWTozKHpRFu3/2BwdrmwOGWUmzRvrvkt66sl6aeE=@lists.infradead.org X-Gm-Message-State: AOJu0YxvOg08aT3kxZGkNbJS8nmq4Jxc47MoE+2vb9b02RRF+IrN3B4a /jN1j63Z1MGNr7J+p9ldapJCqK6YMa5uAF7N/dxgzbKKTrrtppYp5nj6DAEU X-Google-Smtp-Source: AGHT+IFFYGWgxNe3W6HVZ9vKaXN55rWL1eirSET5THcsDSbxqgt+Ehox2JsTuD01KAWPP5hH/gwWVw== X-Received: by 2002:a17:907:320d:b0:a8d:128a:cc23 with SMTP id a640c23a62f3a-a93c4c2d809mr96338766b.59.1727392917484; Thu, 26 Sep 2024 16:21:57 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-3989-b03c-7705-998b.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:3989:b03c:7705:998b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27773c0sm50368166b.1.2024.09.26.16.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 16:21:57 -0700 (PDT) From: Javier Carrasco Date: Fri, 27 Sep 2024 01:21:09 +0200 Subject: [PATCH 18/18] leds: rgb: mt6370: switch to device_for_each_child_node_scoped() MIME-Version: 1.0 Message-Id: <20240927-leds_device_for_each_child_node_scoped-v1-18-95c0614b38c8@gmail.com> References: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com> To: Pavel Machek , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Gene Chen , Jacek Anaszewski , Bartosz Golaszewski , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1727392874; l=3209; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=PSVqt2hzPQNutXFJ1ySerbu1QMLwioqVyiO4z6jxrQ8=; b=CwV0EpzUvZAO2Xr3Lvw35f2AWkJgxILgyeJ44eQr3MbK8h5/RqojjHPTG/zr0owvVEhgiQYxU 1I/cZWn0KknD6O57SSfoyl0TPR+QYf61STH2RPg5oIKED+kOJG42L2i X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_162200_176163_C62F2DE2 X-CRM114-Status: GOOD ( 18.44 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Switch to device_for_each_child_node_scoped() to simplify the code by removing the need for calls to fwnode_handle_put() in the error paths. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). After switching to the scoped variant, there is no longer need for a jump to 'fwnode_release', as an immediate return is possible. Given that the loop is called in the probe function, and it already uses dev_err_probe(), the common "dev_err() + return" has been updated as well. Signed-off-by: Javier Carrasco --- drivers/leds/rgb/leds-mt6370-rgb.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/drivers/leds/rgb/leds-mt6370-rgb.c b/drivers/leds/rgb/leds-mt6370-rgb.c index 359ef00498b4..fe76e8e27f9c 100644 --- a/drivers/leds/rgb/leds-mt6370-rgb.c +++ b/drivers/leds/rgb/leds-mt6370-rgb.c @@ -905,7 +905,6 @@ static int mt6370_leds_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct mt6370_priv *priv; - struct fwnode_handle *child; size_t count; unsigned int i = 0; int ret; @@ -936,37 +935,27 @@ static int mt6370_leds_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "Failed to allocate regmap field\n"); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct mt6370_led *led = priv->leds + i++; struct led_init_data init_data = { .fwnode = child }; u32 reg, color; ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - dev_err(dev, "Failed to parse reg property\n"); - goto fwnode_release; - } + if (ret) + dev_err_probe(dev, ret, "Failed to parse reg property\n"); - if (reg >= MT6370_MAX_LEDS) { - ret = -EINVAL; - dev_err(dev, "Error reg property number\n"); - goto fwnode_release; - } + if (reg >= MT6370_MAX_LEDS) + return dev_err_probe(dev, -EINVAL, "Error reg property number\n"); ret = fwnode_property_read_u32(child, "color", &color); - if (ret) { - dev_err(dev, "Failed to parse color property\n"); - goto fwnode_release; - } + if (ret) + return dev_err_probe(dev, ret, "Failed to parse color property\n"); if (color == LED_COLOR_ID_RGB || color == LED_COLOR_ID_MULTI) reg = MT6370_VIRTUAL_MULTICOLOR; - if (priv->leds_active & BIT(reg)) { - ret = -EINVAL; - dev_err(dev, "Duplicate reg property\n"); - goto fwnode_release; - } + if (priv->leds_active & BIT(reg)) + return dev_err_probe(dev, -EINVAL, "Duplicate reg property\n"); priv->leds_active |= BIT(reg); @@ -975,18 +964,14 @@ static int mt6370_leds_probe(struct platform_device *pdev) ret = mt6370_init_led_properties(dev, led, &init_data); if (ret) - goto fwnode_release; + return ret; ret = mt6370_led_register(dev, led, &init_data); if (ret) - goto fwnode_release; + return ret; } return 0; - -fwnode_release: - fwnode_handle_put(child); - return ret; } static const struct of_device_id mt6370_rgbled_device_table[] = {