From patchwork Sun Jul 21 15:19: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: 13738024 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9C861667F6; Sun, 21 Jul 2024 15:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575166; cv=none; b=LJr/gcCca3j3TEDcaTiT0gQmrQVxG/maH3aLf9uby779d8Ah7C5SwMm+WvXg5PX3bIFjzBQncasw3/g9uz8EdR0kkIalxu58mCr1N+C7HpvQoZ4SWALUSw7Ly5zmTZLTQu5WKCjl29KrMmBXmEPQgnPP/BjgdSqGYyxvSwBdL+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575166; c=relaxed/simple; bh=NQLwlzM1GB5s/6zaH5GM8OvbL7Is75uW2H1eYJozVs0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e+OtDLpn+SJoThJu1/AhGL5W2ow0O9Dx/dfmrrteDfMJhCIDWlqy785i8xygWY3mIvyuT0aXfd+mS2v0nQX5SXUa8xNc2b5wTHpuiRFXApVZnCRFdkorHQwUSXkmZf1XHTBjQ9pW9vzltvKac2cOYX48GvZO++ZLUjurMFDlYyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Iu+lGlhW; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Iu+lGlhW" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a79f9a72a99so809111466b.0; Sun, 21 Jul 2024 08:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575163; x=1722179963; darn=vger.kernel.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=y/Pf1euXJ7YiFp6MxoAI1+nAX1xEOLbJWGLNA7qyCg8=; b=Iu+lGlhWlQh3WyNSx4DpzObWI9eOTdPdDVq7EV6ol42WYV0t2GuwTUu3fs7Hqmyd6V BM+Zjz9IAIzQz26buAye7CzrdDyRv/mfMMkAulbzozro017nIf4fh2l36lK6MrQ24hf4 TJ6mRflQGg3QEwzJdsYzZM5z4AT2LINGdKfQkUf81BEx+Ijul+bTD4V++QwycKrYIBqY fU+W7RU7ohzSG5ph5Cz5m6PjRoy1+Mn1HPyxFDnzVPo8fSgyCO9eNbwsxQVL8kKQAkIe oeXnDI2In3srsWKo7Sx56qg8TUUwiXJTu5AgYI1XG2l0+vl+Pz74bb6zRHIIUwS1Ya47 ErqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575163; x=1722179963; 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=y/Pf1euXJ7YiFp6MxoAI1+nAX1xEOLbJWGLNA7qyCg8=; b=XkkBvnf+McK+5Lpl7JlstmgyGYoazdUNQbucSxqtHg6uWi98BWrDBmfyXxdv+2moRf SpE8Bm2lsvz1wexW00arhDGTx3zo8ZDvdeSIWAjcDi0hrCWy+hXUQO9JyLuzQE9H3Oa6 fFKRZJqHLlPVS8DnaG+i+VZS17wCI7FrYBDueD0f5dZhtE7BPcps2bw5AI/EiNFO7mN+ 8u5Dk4EyMtKtkHkR1GkrPGLZ7TPcTRSHSr4vZP3cJDdxLGuiyN5BEm5+sJVbDVkLdPoA +qBV+ZvgFQRoZvTACBn/3SQg00uWqQdajkxciObNNYJs8W2o6CcoDtsULLizyXtWwq3e JP7A== X-Forwarded-Encrypted: i=1; AJvYcCUtJ1g6wRKC9nLHM6OSITZWKmdHo1BL5O5zk2U3z2PcJYp/6C0SpY9UEEjQwuplMMCFwktUJ5GiBExTM9TStysw7wmtSBCmxRIzGRQjwllgNljebxnPo+dkN+dyuMtqUGyGarOaV2ra/SxUGuEICAWMCw1V8ii6uArjARUIMFiks0e7rQyxhOaT9s5tydZgQdVfjdu4ohOuHd7gdYor X-Gm-Message-State: AOJu0YxC+/MRcN39IRw5AktLHdRE6b6NJXkzZZFEkFthr7bU81OCWsZn xi9Fjs10RGChbByLWJkpEbtNed3XOS9rO0HbZ6zq8VCGI9h5rm5c X-Google-Smtp-Source: AGHT+IF5poCMFJoB1QBA50RVZf8sIrkQwalXR8cSF3JoqUpvJkktDE0ENejC0z1/gU5kvlPaLR/fFQ== X-Received: by 2002:a17:907:9727:b0:a77:ecf0:84e5 with SMTP id a640c23a62f3a-a7a41b0534bmr475210266b.14.1721575162600; Sun, 21 Jul 2024 08:19:22 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:22 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:01 +0200 Subject: [PATCH v2 1/6] device property: document device_for_each_child_node macro Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-1-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=2059; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=NQLwlzM1GB5s/6zaH5GM8OvbL7Is75uW2H1eYJozVs0=; b=mau8GXUvako8cDiI6eQz1SkIMsNpRk/Se8mFBQSXfOKpnevqV8V4yJSJGwSEmp1A2Nh+MJlPh AhzzO+KxkaZDgIzRKhYQ6mhyuXJBBffATc20B9c3jcXSb2EeZELZR6O X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= There have been some misconceptions about this macro, which iterates over available child nodes from different backends. As that is not obvious by its name, some users have opted for the `fwnode_for_each_available_child_node()` macro instead. That requires an unnecessary, explicit access to the fwnode member of the device structure. Passing the device to `device_for_each_child_node()` is shorter, reflects more clearly the nature of the child nodes, and renders the same result. In general, `fwnode_for_each_available_child_node()` should be used whenever the parent node of the children to iterate over is a firmware node, and not the device itself. Document the `device_for_each_child node(dev, child)` macro to clarify its functionality. Suggested-by: Jonathan Cameron Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- include/linux/property.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 61fc20e5f81f..da8f1208de38 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -171,6 +171,16 @@ struct fwnode_handle *fwnode_get_next_available_child_node( struct fwnode_handle *device_get_next_child_node(const struct device *dev, struct fwnode_handle *child); +/** + * device_for_each_child_node - iterate over available child nodes of a device + * @dev: Pointer to the struct device + * @child: Pointer to an available child node in each loop iteration + * + * Unavailable nodes are skipped i.e. this macro is implicitly _available_. + * The reference to the child node must be dropped on early exits. + * See fwnode_handle_put(). + * For a scoped version of this macro, use device_for_each_child_node_scoped(). + */ #define device_for_each_child_node(dev, child) \ for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) From patchwork Sun Jul 21 15:19: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: 13738025 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9557D168491; Sun, 21 Jul 2024 15:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575169; cv=none; b=QoWC4w3VCbSVkXhp7MjqPaQZWU+FnU1wUnzklezr1C6eynBWcp1cX4P7uYkcm9ettLWQ0yjzJCoFnvVCrsvXSdAtiihInuYD3Z57Qn+dAycIrTUV0zJ5+Uf2XKW92jTuaADQNsXX5NQkRwJspsF1++MmbQLC/dHQnV6eDsZdNK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575169; c=relaxed/simple; bh=qmJK3LZuSa0Q8co0FeH63oXHSEAWVIOtnWvvKF0X9Vg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XWviVc+WIDMpGlhGuZPwDklHT2zIJKFmvv0p2On+5O9WYT0rD/V3OzTjfrbNgKs73uN2vDyXcGswacsTbLu6DWAuy6HSrZ0HhBZDVoN27y4DWP7k/ROCUqC9f2MtLaPZz+5+7ZuPtusSOZIDvSgw7C0ol3FAyG20kLUu3lElNS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fjMf0l/Y; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fjMf0l/Y" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-52f04150796so103272e87.3; Sun, 21 Jul 2024 08:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575165; x=1722179965; darn=vger.kernel.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=nLo1DCjLzPkM82LXiwcToVtcKJJFQ6JlMuEebWdypGk=; b=fjMf0l/YzUeo1qiDn+60d1gZ+3U5B5F9XCb+Bkc0XlB1B2O2jGPoqXSg2V2zAlnmV2 H0qlHMgakPkRQrk3RXFGHx0gEDo3b2soum1AQKfea1WuA44HVRrKdGI1K9SLZMKKp4Tt MGXnZdfpTglGT8aJCT++U6g9PO1x2HbDHbMbAnl9qGHSSSjtakQNsOAuimLq9H0IzYa5 Gm3Uet11JnUn+nAeqJrkX54dOMJwxkvjfvYwUXGrc7zeik/B/HFmQZUnDfd4AFcDYCPn appRVHbYTpwBJA1TWwZ4ntoUu9+1WA52f9uFUEzdcWsfnKbMuRG+i1uWGJHjR2u/CT5g BiqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575165; x=1722179965; 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=nLo1DCjLzPkM82LXiwcToVtcKJJFQ6JlMuEebWdypGk=; b=Kx8LIHXXouhwzW9rrAsSu1n3Ajl/6Jk2zXXFDm6r7Nd74Hzw1Yxc6T30AePnGCbcA7 /BmJFTvQGQlZiZEk5lEIu/Fy/CgBGavs/+OxjA3BwN8tXRuC54NsRvsQAm5+K55yOQMF Pk8keIVySvNck0UiFVBYj7Ygejz55ATVrZXVyYTXc9KpoZ2U/i6ZogX3J7sazXS8hhEa mXjImztwHbUAUjZGuXhjjLNuiMaspU9St2STFPQkN0I3yX943qyNwcB9Cq833x6y98xE cgZk9WWkRreX2eyQ+3vT0TffMykhRLsTtBIapWT8FfBtoKHptG4Lodere4oIw2uucT0Z mhPQ== X-Forwarded-Encrypted: i=1; AJvYcCVb3VxGsXM6bK28pE+HbsNVInwipt/HrA7LHctf/uM2/SgdjCDBVANFGXfd2x3mMWKui7P19ASdBNG/bm8XnVYjcGFSTkGd7qnpchwZ+w+gz3YpmnyWsBbqUhWctn/RH+HDJRlH6mNF4lh3r9YIJ0nv7kXwWcAESByBs9f0KlsaLhHmrPhzWZDhDfPKJnyLFnFk3PiiDBIz3zxGydqr X-Gm-Message-State: AOJu0YxYW7PRy1PY2BgP/U+51+VHXItsvms9R4qNTfEIhSGVB05CXx4l 6ZNZ/QIubVNMLblMTsJBMEDSu9sIc45zIqZ68mv1jieUIm3X1PPfkKZqD6w+ X-Google-Smtp-Source: AGHT+IFky+8Xq3MfILxGzTgpCFEIBmcdXggGjBm2n6+4RWT8GKM2DUZln/cW2pbRLRatbPCgoyfd/A== X-Received: by 2002:a05:6512:2820:b0:52e:9c69:b25b with SMTP id 2adb3069b0e04-52efb748b3amr2667915e87.28.1721575164455; Sun, 21 Jul 2024 08:19:24 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:24 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:02 +0200 Subject: [PATCH v2 2/6] hwmon: (ltc2992) use device_for_each_child_node_scoped() to access child nodes Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-2-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=1962; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=qmJK3LZuSa0Q8co0FeH63oXHSEAWVIOtnWvvKF0X9Vg=; b=EOAWx1KMuMlIc+Yg6IQBT3vDliOEmMWvAD5kHoGeSHqA67yup3gB9zEr4K50S2w+sr91FEDzB iZmNWBEOAamC2D2/OlNOofezTrsbmVUUTtCQ0WlI8JqdBTFhoVtVZrs X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. In this case, the child nodes are not required outside the loop, and the scoped version of the macro can be used to remove the repetitive `goto put` pattern. Use `device_for_each_child_node_scoped_scoped()` to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/hwmon/ltc2992.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index d4a93223cd3b..541fa09dc6e7 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -854,33 +854,24 @@ static const struct regmap_config ltc2992_regmap_config = { static int ltc2992_parse_dt(struct ltc2992_state *st) { - struct fwnode_handle *fwnode; - struct fwnode_handle *child; u32 addr; u32 val; int ret; - fwnode = dev_fwnode(&st->client->dev); - - fwnode_for_each_available_child_node(fwnode, child) { + device_for_each_child_node_scoped(&st->client->dev, child) { ret = fwnode_property_read_u32(child, "reg", &addr); - if (ret < 0) { - fwnode_handle_put(child); + if (ret < 0) return ret; - } - if (addr > 1) { - fwnode_handle_put(child); + if (addr > 1) return -EINVAL; - } ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val); if (!ret) { - if (!val) { - fwnode_handle_put(child); + if (!val) return dev_err_probe(&st->client->dev, -EINVAL, "shunt resistor value cannot be zero\n"); - } + st->r_sense_uohm[addr] = val; } } From patchwork Sun Jul 21 15:19: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: 13738026 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7F09168C26; Sun, 21 Jul 2024 15:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575169; cv=none; b=q+/X1fftAQK+xOSpjE0PZBUDtIQAK7Sy7olHAflEcj4Ff09d2OyCYDPPjUXw581qgaw9lmtlKaezHbqIOuSQueP7SpFu7mttvhO0ik6NDujI7sVXJlftztEEHVod1L+YeWYtO87+GKEYvQVJXIfC9SPMrRX830ARlKYF9lU8hv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575169; c=relaxed/simple; bh=zfKvVl56Ee/YHYsPw//vbpTx3vfqLNtRUd8E8z686Yk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=blKuWa73li85jvUp7Phezp2tXQaNG88TPoUtQhiew+AtfANDN5OOcw8+e9sF22hQcWjow458cenglU7S3hRqjhV1W7nqmE9tU25AT68bvBeAxBwUfIYN1LEosZ+ACQzQyuGktfFVURY4THOxIVgTVq5yZWCkQow4uTQUnOFxTUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PC2YCcRz; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PC2YCcRz" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a79a7d1a0dbso338526366b.2; Sun, 21 Jul 2024 08:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575166; x=1722179966; darn=vger.kernel.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=34LO3D9/a+9GkhCYyyEdto/l7dIIOtnNwsjkTzmylGo=; b=PC2YCcRz8BR6GekTVCiCPZyuy0qMoZ77SWhm3BYT0dgidVUJJUybDGNarn6nnaxHSl W3lupiiISme53mf21YW8XVet7qES/NeKTqciCVReCTaGkoTdN1Dn/oLUb+Yl2AD0eUlU XEQwlErvM+OIZI48bCTP6pYqF+zB4lUKoafvsmTPLaTmpoVbCFzdcXFvHDAG2jduMxS7 ZRKxGbh6A2QPFf3/AeLfLp4V41EnlSQgDaRxxdOdFjcpz2wtJL9645ulJL3lV8F24FK6 El6A6ZdOHWo+yYDLPfBAK+ka/kXE6b9Qx3q7oCWDTJn0TN6EuMZVAw7UJ59GOryycWp8 D2UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575166; x=1722179966; 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=34LO3D9/a+9GkhCYyyEdto/l7dIIOtnNwsjkTzmylGo=; b=dP0piCfqa3+YMasKKygBY4gCwgxvv/+KPJJS4zjIIPvP8cXVdKMFuhVmiKJefanssC PBU63NWfjYMxUMBJhbadwISybQEptgw4ZnpbvB20F9Y//8PRS3jfq9OPF6hR3AzUWWMS DJyw80Iozz/o9b5u+2tPnhGtnsUKa7qJHWPy/cq28cIFViybSKxG8pJW6MW/rMHOrCag bX1bkBcIUadxpR+AWJbu0HP/U4eJxQ2ia9wgDAPpZGyG7SuKC6FWZ9QXmIBiO9JquzCi iBOkOgwUjs0QOq1sEjpoqFDUj57ayFe1evkNYVBBi5oTLSU8I5Y1Mn/+jZzjYlOzfwyt FlFA== X-Forwarded-Encrypted: i=1; AJvYcCWzNELsSN70qRHniTcjNdLMO+ByE3wuTySMYyn6BBMdZUdizM1aRK9oj2G6orOOjn8qr1NGEjkumhFuc05qlhuxn0dgz3xgChuQwD0C3u6V7Ug2oi5CVRdYJ2r7Psg4NTiKjoapWiiP7gbiIxJBFZj4tkm8ITFAWU441z1lRTOHAeRQDFNnn6nS/j0HOfL1GAX5vthbnnvxuLhnaKCF X-Gm-Message-State: AOJu0Yw1ykOhfSR7oCCZMOQ39jhGkOJUCjcARqH4pU8qF+eBYu37+SIX y7/1Z6TtB7gbCmg6cta1ap8imG9ZLdzj8+Z5ZLyd/g/kfTZqR+l3 X-Google-Smtp-Source: AGHT+IE2m8FTqLcaB0ayAtsAcxDklDrh0Jeo9GelAe8928pHZaIlEmSx4Gb+ZFErkTLXrmOEbver9Q== X-Received: by 2002:a17:907:7d86:b0:a77:bfca:da54 with SMTP id a640c23a62f3a-a7a4bfa7767mr288110166b.29.1721575166197; Sun, 21 Jul 2024 08:19:26 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:25 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:03 +0200 Subject: [PATCH v2 3/6] leds: bd2606mvv: fix device child node usage in bd2606mvv_probe() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-3-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=3278; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=zfKvVl56Ee/YHYsPw//vbpTx3vfqLNtRUd8E8z686Yk=; b=ZOs+XB1NOY29jgnwIKho0VKLh2Hw7hfs9FxrizpKpodfRzt1jD2qEBOPUZ/OgG6WdVgMs7pyg 0s3G95aCiF8A1ViieFgNQ20Rsb1P2WxwE8ftDUkaao75AfAxCNb2kSV X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The current implementation accesses the `child` fwnode handle outside of fwnode_for_each_available_child_node() without incrementing its refcount. Add the missing call to `fwnode_handle_get(child)`. The cleanup process where `child` is accessed is not right either because a single call to `fwnode_handle_put()` is carried out in case of an error, ignoring unasigned nodes at the point when the error happens. Keep `child` inside of the first loop, and use the helper pointer that receives references via `fwnode_handle_get()` to handle the child nodes within the second loop. Moreover, the iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. By restricting `child` to live within that loop, the scoped version of it can be used to simplify the error handling. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. Use `device_for_each_child_node_scoped()` to indicate device's direct child nodes. Fixes: 8325642d2757 ("leds: bd2606mvv: Driver for the Rohm 6 Channel i2c LED driver") Signed-off-by: Javier Carrasco --- drivers/leds/leds-bd2606mvv.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/leds/leds-bd2606mvv.c b/drivers/leds/leds-bd2606mvv.c index 3fda712d2f80..c1181a35d0f7 100644 --- a/drivers/leds/leds-bd2606mvv.c +++ b/drivers/leds/leds-bd2606mvv.c @@ -69,16 +69,14 @@ static const struct regmap_config bd2606mvv_regmap = { static int bd2606mvv_probe(struct i2c_client *client) { - struct fwnode_handle *np, *child; struct device *dev = &client->dev; struct bd2606mvv_priv *priv; struct fwnode_handle *led_fwnodes[BD2606_MAX_LEDS] = { 0 }; int active_pairs[BD2606_MAX_LEDS / 2] = { 0 }; int err, reg; - int i; + int i, j; - np = dev_fwnode(dev); - if (!np) + if (!dev_fwnode(dev)) return -ENODEV; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -94,20 +92,18 @@ static int bd2606mvv_probe(struct i2c_client *client) i2c_set_clientdata(client, priv); - fwnode_for_each_available_child_node(np, child) { + device_for_each_child_node_scoped(dev, child) { struct bd2606mvv_led *led; err = fwnode_property_read_u32(child, "reg", ®); - if (err) { - fwnode_handle_put(child); + if (err) return err; - } - if (reg < 0 || reg >= BD2606_MAX_LEDS || led_fwnodes[reg]) { - fwnode_handle_put(child); + + if (reg < 0 || reg >= BD2606_MAX_LEDS || led_fwnodes[reg]) return -EINVAL; - } + led = &priv->leds[reg]; - led_fwnodes[reg] = child; + led_fwnodes[reg] = fwnode_handle_get(child); active_pairs[reg / 2]++; led->priv = priv; led->led_no = reg; @@ -130,7 +126,8 @@ static int bd2606mvv_probe(struct i2c_client *client) &priv->leds[i].ldev, &init_data); if (err < 0) { - fwnode_handle_put(child); + for (j = i; j < BD2606_MAX_LEDS; j++) + fwnode_handle_put(led_fwnodes[j]); return dev_err_probe(dev, err, "couldn't register LED %s\n", priv->leds[i].ldev.name); From patchwork Sun Jul 21 15:19: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: 13738027 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D518816A954; Sun, 21 Jul 2024 15:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575171; cv=none; b=eorkg4oGjUNGHjgtDBlv4zryMz2IbG4pzsGgcU0A7IRmWqoIyQlFNmjl8S9oHx5Jf55ZEr2KleMtL7SfMZLFT3ddS/ZIO0jAYR8n8PiAfCAxdo2x9muOZeSRLXfzF9hh8hFn1aSyleLFPhfJGGHgjS5HlzvqacG+PkKoKUKG5BE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575171; c=relaxed/simple; bh=j/RHG5S2KBp37HXXynDqIlrHp6BrAXodPNBCnQweexc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qEe349N9iNwnK+pXDrIT1Ve6R5oIICDl1G4GtHFUqQZjH+sZt9SAgDSw3jpNGOvlvRVHYghxUcnJxvshz0SVqizi+/8CnddpGiGqBUDZZ/CdR+XmIyT3wwTjT/GKDdcBdeu9/XlZJg4wRuPrTMvOmzDdvn+E9Y9i6F3/hKcO9Pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ev+EFb8w; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ev+EFb8w" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a77e392f59fso358171966b.1; Sun, 21 Jul 2024 08:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575168; x=1722179968; darn=vger.kernel.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=J8k5b/mbk8JidSQkDkpUc1By8/0Pl5zLywNFvxqirlc=; b=Ev+EFb8w85qD39zxBUprT/j3fK7IY5B/NoKw3RxBoE+b0xPRWW4ndAmTx1EhZpC3nW V6OhoN1gYdf1yYpv2y4k9lPJz3yF1bClq7WJdMV3wyzaRxRf1E8CWg0a8TusGtlk4VBA pMAWOrZ/58iDCKXcKygawnvNSdKGSQzgNl6ooS3G6X28Ubfd1vemN1rXIuMorfpzheNF kheiNb3xTLCCQRONBbDsvE3jZ7fSM0Eb6iFB7oGDzn8U8QNf2Brc65NVQslHgveMyRY8 Al/aCcoKVx7JN2syxmrF5+cMFdOKKvgzEgN6FCEcioZUP8CrXPt6tSQEtcCekbZeoHqb plGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575168; x=1722179968; 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=J8k5b/mbk8JidSQkDkpUc1By8/0Pl5zLywNFvxqirlc=; b=TtA0GXPhmYMXKgPL+PSdEcu4+gsIPSuzjTkahCe6k8WawKuoWQHQ0UlnOmiZYmqgyM roHYOueQLQiUMU2bjtSCqNeia9rEoe7E29IptGquW1RwR2sjp1ftLcAlO8fVckZI4w6E pewzGszUkn6lymsZnCVLIA4WUFqBE92qOsKuya/VfWpiOYg5AbZb1PZ3LCao6zsc65FB UA6mlf0iaH9aQVnoeFrTREl21g4+GH78BsE+qMKhI6FrGuweCNZIBDRzNf+yQya6e/jr 1X8FvRGSERSl1TW8E6RAvVXK3QeVcBvWEf9zidNKYcf32z6L/fdoB6UQkqLVD2K1ywF2 NjHw== X-Forwarded-Encrypted: i=1; AJvYcCVb0JEpyOAYw4GkLvovrXYPzu/JSSw5AOFxskitxqauZRp86etXBcsoixvxqvT9D4YDcDqcDjMteM1rBUPCF+u5A3B+uOIluxI/yj3Gn4BNN6DRmkuhO9XwnU5JqUhk6tXWqlWfpnRYtIXxlydGZ4wsUKAh9Wun89FpgpN7FtYGeJrGiqyUg/z6CQZCZR3c9qj2lN7GKb0dcjtBZUld X-Gm-Message-State: AOJu0YzyqFims69oj0raCHm6eCSNKzA8lBm0fjtAtWX1BlPEg4wiXoeT e/D3GWwgoQ2imlb10TS29Q8aQoJ8+jYmJxAsgI1Oak/kVDdXJOPH X-Google-Smtp-Source: AGHT+IGp55aRgT5ci8RjSPk4Z8pjU7fk+RHTFyEes+YN7ooGbgnG832FPrZ8ml4i+8/DWxjznFAfyQ== X-Received: by 2002:a17:907:7d88:b0:a77:c080:11fc with SMTP id a640c23a62f3a-a7a4c0cfd91mr268413266b.36.1721575168037; Sun, 21 Jul 2024 08:19:28 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:27 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:04 +0200 Subject: [PATCH v2 4/6] leds: is31fl319x: use device_for_each_child_node_scoped() to access child nodes Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-4-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=3441; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=j/RHG5S2KBp37HXXynDqIlrHp6BrAXodPNBCnQweexc=; b=GnDe4jzcJoRelbHvrSCqaVtirX0l96JIpTFerOd5HX5Z5a4TOcwdirZvJSxljFBhbZpWn21hp wrMec4QL9fYA5kMGSUry7pLPrIQ9WFJnGkUznPUmuFEvd1LOCW1MQVD X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. In this case, the child nodes are not required outside the loop, and the scoped version of the macro can be used to remove the repetitive `goto put` pattern. Use `device_for_each_child_node_scoped_scoped()` to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/leds/leds-is31fl319x.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 5e1a4d39a107..27bfab3da479 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -392,7 +392,7 @@ static int is31fl319x_parse_child_fw(const struct device *dev, static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) { - struct fwnode_handle *fwnode = dev_fwnode(dev), *child; + struct fwnode_handle *fwnode = dev_fwnode(dev); int count; int ret; @@ -404,7 +404,7 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) is31->cdef = device_get_match_data(dev); count = 0; - fwnode_for_each_available_child_node(fwnode, child) + device_for_each_child_node_scoped(dev, child) count++; dev_dbg(dev, "probing with %d leds defined in DT\n", count); @@ -414,33 +414,25 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) "Number of leds defined must be between 1 and %u\n", is31->cdef->num_leds); - fwnode_for_each_available_child_node(fwnode, child) { + device_for_each_child_node_scoped(dev, child) { struct is31fl319x_led *led; u32 reg; ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); - goto put_child_node; - } + if (ret) + return dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); - if (reg < 1 || reg > is31->cdef->num_leds) { - ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); - goto put_child_node; - } + if (reg < 1 || reg > is31->cdef->num_leds) + return dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); led = &is31->leds[reg - 1]; - if (led->configured) { - ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); - goto put_child_node; - } + if (led->configured) + return dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); ret = is31fl319x_parse_child_fw(dev, child, led, is31); - if (ret) { - ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); - goto put_child_node; - } + if (ret) + return dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); led->configured = true; } @@ -454,10 +446,6 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) } return 0; - -put_child_node: - fwnode_handle_put(child); - return ret; } static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp) From patchwork Sun Jul 21 15:19: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: 13738028 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF5D916B3AD; Sun, 21 Jul 2024 15:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575173; cv=none; b=Ps7D7wd0dc1k3FzD3yJMo3a9HCxF9PiMwvhMx4d5Gvr5K2hkOZFGwwQsW0ZGYqkB8yzRYjjnF1tSptYoU15uLDIjm+K6lziMc1ZVARAcRsfYZC7QdKm7nyEBH2uK/qslyPIfocYWS1FoDSj73jsb3JqZfEhEZh67yMCohl0TPiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575173; c=relaxed/simple; bh=IZz056KNV/K5vy8xE0mpvGhKiXnzIveHDDS4W0kv+KA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WoXFdjRbDA1NEzVCJ/Nb2X1MNQ1Lckny9Jmb9PSh/cJ7J+axxn/twMWbW55ZiwYFifcwdy8kXsyIF1lNds+Q/3qp7VAaD6l3R5WWaw8ox7zcdbrbNA68yAcA20P1vGkquhhioqWHcJrrUNVXyIl6Ucl13CoyRuz6YWI0ITct7lA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PsDTo0Z+; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PsDTo0Z+" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a77baa87743so367070666b.3; Sun, 21 Jul 2024 08:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575170; x=1722179970; darn=vger.kernel.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=UCaeppO5TKYQKt2aHsXVMJ2MVvG+IrdjQ14PrXl1bh0=; b=PsDTo0Z+xpbzxgrVTn4r2Krq254svorwrSKsYndG2InltVmeOhZjofFhtBS3vKcyhG eHV7SUxF9YD3/M4unSScyCdDqoJ13orTPC2F24r23B0VcIwsb+rMSEMcdvaN/fsBNQEh SkeLTfK9XI4twqc8Z84xIm4DChlr5LeVZ4c192lDIWl2ZZ4UVM7N5UuVm8/DYtaULrd1 QGnXZUW+kjnsMpkSAJyEAeQ7ixuTgmVaBx/SZHev+IfWFuDQmo3EdfMqWaa585jBp7l0 2CjBlPUasav8l0yidKbQFGJK7hfw4bzt1JtAmFx3wgzrFmvz6eXT60D+qqqv0NuPRoFz lHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575170; x=1722179970; 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=UCaeppO5TKYQKt2aHsXVMJ2MVvG+IrdjQ14PrXl1bh0=; b=F83PcdDfSoTNaG+zIYn20nxfg7Z6Eji2mET31x9ODyGykpU1+PiaGfF8uygquIotSP Bq06zupdpYbsKALIKiIbrLvOP/ryAfuX+tDyO4UhT8de9OgIRqsduSxKjExGlAQOB5oP P+npAXseWSvfQiHqFD6n7Krfjmz4s+5NJ5dTG8UOl/SuNyJHc3IxCDAQd/qkOafgDLNX FKSHmATyTNov+Eao/bs4UQHtlKmKjnBQpCnxzEPf0xa0LD5O9qCfk1wmkAPPw5La7vYS Oa90CMwN65ry/W91fXYtMJzTnpx3Ik3pBPBaCHAVSNTl8T2zvpa9oZuwUYTJtiEpVNWh D6aw== X-Forwarded-Encrypted: i=1; AJvYcCUz6G9DasdzhFkoKcX3bw2Fhlf8CHCJS8uz7SRtYjecdivQ8pCVoYyAndly2TX3uaoBimua7oOPOwx9R1LKGGxFhg7IgJpXiazAL7ze8x8phU6tsxquJayHZfcIO67gGenhtKhEkbPtjym1IAUtUWlYMFUn2VmYSDJZ0x5vmVYkWqPLsqYN6apWF+a9ibEgpfMQuWLyNkY5N0F70YtQ X-Gm-Message-State: AOJu0YzS9SwuhD4EaiJGnVQ14LkO1ol30mzxT943LHa6b1MxgjnSDPb8 RG6C/6LzQbq1a/cV7kpC9YmBG+LUi4psEWe/vSUe4j7nMF464DaH X-Google-Smtp-Source: AGHT+IHxuJd7XSf6nb/ITawU9NSqfoOysNSpBdPER5Ug2vlASU0Mv26PZB28946+o5vf6kRkZ120kQ== X-Received: by 2002:a17:907:72c1:b0:a6f:b702:8a21 with SMTP id a640c23a62f3a-a7a4c4711d8mr313073866b.63.1721575169807; Sun, 21 Jul 2024 08:19:29 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:29 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:05 +0200 Subject: [PATCH v2 5/6] leds: pca995x: use device_for_each_child_node() to access device child nodes Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-5-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=2070; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=IZz056KNV/K5vy8xE0mpvGhKiXnzIveHDDS4W0kv+KA=; b=0Hk6DPbuVgat91nCbXV2Uc5dy+J5iKlJx6cRKAKwJr7juKeeou3yTnjpfStfyQu+WL6OixVhc lD4IQMFZXQSDDVSS2NouYI1/3ePm+ZSC6gokltOpL2DR856jpP9HQwO X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. Use `device_for_each_child_node()` to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/leds/leds-pca995x.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c index 78215dff1499..a5b32eaba724 100644 --- a/drivers/leds/leds-pca995x.c +++ b/drivers/leds/leds-pca995x.c @@ -102,7 +102,7 @@ static const struct regmap_config pca995x_regmap = { static int pca995x_probe(struct i2c_client *client) { struct fwnode_handle *led_fwnodes[PCA995X_MAX_OUTPUTS] = { 0 }; - struct fwnode_handle *np, *child; + struct fwnode_handle *child; struct device *dev = &client->dev; struct pca995x_chip *chip; struct pca995x_led *led; @@ -110,8 +110,7 @@ static int pca995x_probe(struct i2c_client *client) btype = (unsigned long)device_get_match_data(&client->dev); - np = dev_fwnode(dev); - if (!np) + if (!dev_fwnode(dev)) return -ENODEV; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); @@ -125,17 +124,13 @@ static int pca995x_probe(struct i2c_client *client) i2c_set_clientdata(client, chip); - fwnode_for_each_available_child_node(np, child) { + device_for_each_child_node(dev, child) { ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } - if (reg < 0 || reg >= PCA995X_MAX_OUTPUTS || led_fwnodes[reg]) { - fwnode_handle_put(child); + if (reg < 0 || reg >= PCA995X_MAX_OUTPUTS || led_fwnodes[reg]) return -EINVAL; - } led = &chip->leds[reg]; led_fwnodes[reg] = child; From patchwork Sun Jul 21 15:19: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: 13738029 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A020416C440; Sun, 21 Jul 2024 15:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575175; cv=none; b=CnLaCkVd4Dtgf3uXBp9z+L+bOcb4VVb/8rhegIwaZXcqDnOKQg6wkPUAXHRRxpjShKig0gI5zGC1uVtzvcnn30JJEqqf4G0EoNCcvWip6wseptyz+H4+MspNPz5MmTSx4r8k1IkcNpZJ+nTKvz4dm25ESaq8nBKe3MGVhvUBylY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721575175; c=relaxed/simple; bh=7OWJetluoWS/Nf5AUxollSLUqkLBtNYzuJKo21kzZoM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M/zUGRATrRewvZsMmLFouAhpxuVpwGM8eaNyh43cItGRFr10HLuGHDVVnSu+yl6+aFZmR2+1li6q55lnB+5PbFpFXPoHQeEST4O0QRDYx/q/Oe6woTHq0Q5pQSJs40Oo5MUUV+ag8oA/ATzbXa1SnXGNZ7jq2TMod52EpLnzL6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GO7JI9dD; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GO7JI9dD" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-59f9f59b827so2851008a12.1; Sun, 21 Jul 2024 08:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575172; x=1722179972; darn=vger.kernel.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=vWxQDkg0tjoveNQoAFF0zn3+Cul5K66566bw3Hq4SzU=; b=GO7JI9dDutHPHIPdTGjB5AdkL8QSL9z73dWvASktSLLjvYR8F80SYLYSXu4/q/tOqs N0w+mi8R6xnm2BqKgavgIiASf04RDNpKrmwllshTg8ldSLXF5KTDbeaDalx0/PwCR/hE vMT/fmsqloyLeSfbOc37IFYV129Mj/gE3aRLCYEC0Ggkh8eszlObJwXQCDCIEnXI8++7 PbOAUNodDwaBX0ZKZUiU6fn2JC6EtZAEcHA3wk1975pKucj9eL90OG73A22fOweFHq8N rDqp3UrWW8JzC62MYXI0wUB/mJp9y84yt7as9L2AAfcf/m6ONOSYLJgaHaTbclix8pmU BqCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575172; x=1722179972; 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=vWxQDkg0tjoveNQoAFF0zn3+Cul5K66566bw3Hq4SzU=; b=iki50d1tqffTpVvMjwVVNVcXv76DjI9HKgouZPnZlpNXgp60M6nqgC6L3Aw9LbN82U 1/vAa9KzI6tnQorDd9MQZxZKc3kNXA18e1qsXBO4Qdm5CsvXkH03+f2yaFTKTsiXw5ed VoPo5FfALrPWACE6Ppua1vG189mO1+cei0WPyJzKjdgmZtroXGGlkjQD4ZQeoACRzJyv ivIEoil9rJ+yp4WxCnyJNFQJUkuBNtmhG43XIVK6j7N3GqaOijr8XagBSqpksSFaQPsj jJItAWBXkhfmasK1noMpVZ0Bpt0asd4P8xgEgnnDWh6e7OMW7OD/J+p6jEMrfeQSxW7r lOGQ== X-Forwarded-Encrypted: i=1; AJvYcCVgmr5rqgSGz/TtL4+f1Epeo2ipMm4jUL1rOKAlQeWBwIxvcTUikwN3IrKoE6vSTaWHZkLTtK9bPBZbrNCg7a+hyy2XE11ISRWIdAK8o/YgJBGYF6NB7lIvLWsMJ/bj0/mWx8FzJwvCoMMXOcimnr0UY0gIE8nGott6X/r5qEdLiWfJyrR2LR/i639CVQGudz9mzQT0FoLhOpXD3YC9 X-Gm-Message-State: AOJu0YzahdMFJdjD+C8nF4D8Xl+7J4J8qCctqrW+IQ5BUVxjuRO4v6DZ DZBMllgk1s62GYEU7p54+hgR1Ec3iPqMp1WjO/T2aZ77uziRqxMc X-Google-Smtp-Source: AGHT+IEVeHfDmq5X+0n82+27QM8fwNYvFlhBRw++xiui7Q80c9Brz+8apBbPFsTFmQPHrqEaUNy4ng== X-Received: by 2002:a17:907:da1:b0:a77:d0a0:ea6d with SMTP id a640c23a62f3a-a7a4c011d3bmr308158566b.24.1721575171728; Sun, 21 Jul 2024 08:19:31 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-859e-243c-21d1-9ff6.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:859e:243c:21d1:9ff6]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c78603dsm302270366b.8.2024.07.21.08.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 08:19:31 -0700 (PDT) From: Javier Carrasco Date: Sun, 21 Jul 2024 17:19:06 +0200 Subject: [PATCH v2 6/6] net: mvpp2: use device_for_each_child_node() to access device child nodes Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240721-device_for_each_child_node-available-v2-6-f33748fd8b2d@gmail.com> References: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> In-Reply-To: <20240721-device_for_each_child_node-available-v2-0-f33748fd8b2d@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Jonathan Cameron , Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Pavel Machek , Lee Jones , Marcin Wojtas , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andreas Kemnade Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org, Javier Carrasco , Jonathan Cameron X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1721575158; l=3125; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=7OWJetluoWS/Nf5AUxollSLUqkLBtNYzuJKo21kzZoM=; b=iNMnJvDJavKxd/cTaIQ/wI2+FJ4kPjgO9E1eheuFfGi79xO65EgIuqoenEmedZS7dH91lzXQt cx1BbNkkjcQC1xfO4u/nxdT4RF3p6HMHZwvY1HQLTf43XhDgUcxjsIp X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. The child nodes within mvpp2_probe are not accessed outside the lopps, and the socped version of the macro can be used to automatically decrement the refcount on early exits. Use `device_for_each_child_node()` and its scoped variant to indicate device's direct child nodes. Reviewed-by: Jonathan Cameron Signed-off-by: Javier Carrasco --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 8c45ad983abc..f123072b1f87 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7417,8 +7417,6 @@ static int mvpp2_get_sram(struct platform_device *pdev, static int mvpp2_probe(struct platform_device *pdev) { - struct fwnode_handle *fwnode = pdev->dev.fwnode; - struct fwnode_handle *port_fwnode; struct mvpp2 *priv; struct resource *res; void __iomem *base; @@ -7591,7 +7589,7 @@ static int mvpp2_probe(struct platform_device *pdev) } /* Map DTS-active ports. Should be done before FIFO mvpp2_init */ - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { if (!fwnode_property_read_u32(port_fwnode, "port-id", &i)) priv->port_map |= BIT(i); } @@ -7614,7 +7612,7 @@ static int mvpp2_probe(struct platform_device *pdev) goto err_axi_clk; /* Initialize ports */ - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { err = mvpp2_port_probe(pdev, port_fwnode, priv); if (err < 0) goto err_port_probe; @@ -7653,10 +7651,8 @@ static int mvpp2_probe(struct platform_device *pdev) return 0; err_port_probe: - fwnode_handle_put(port_fwnode); - i = 0; - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node_scoped(&pdev->dev, port_fwnode) { if (priv->port_list[i]) mvpp2_port_remove(priv->port_list[i]); i++; @@ -7677,13 +7673,12 @@ static int mvpp2_probe(struct platform_device *pdev) static void mvpp2_remove(struct platform_device *pdev) { struct mvpp2 *priv = platform_get_drvdata(pdev); - struct fwnode_handle *fwnode = pdev->dev.fwnode; int i = 0, poolnum = MVPP2_BM_POOLS_NUM; struct fwnode_handle *port_fwnode; mvpp2_dbgfs_cleanup(priv); - fwnode_for_each_available_child_node(fwnode, port_fwnode) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) { mutex_destroy(&priv->port_list[i]->gather_stats_lock); mvpp2_port_remove(priv->port_list[i]);