From patchwork Wed May 22 09:18: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: 13670627 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 407AA2D047; Wed, 22 May 2024 09:18:17 +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=1716369498; cv=none; b=UycrAa0gg+NMFcJ0kWzk7hUSETIYmsgE7f6+cvJ6koVUXcbMAcdJ/wv5x0OuRTA1afRFChrFaszfIKWOP7m7V4wTz32Lc8Ou/TRimuE4MfrZrPySjykzosoFBIq5hLZkr7IgulJBFkG1FmpOtTGBpDt1r0XcM3ZyWkUXD0sR388= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369498; c=relaxed/simple; bh=clL0rBh8NOdBwMJgT36ockVwV2WORoYm3aKRiSyAeBM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cZW52JGVWH/fB7Vt8pyjlMAPS6FgyIHtrPLk0aqzrI7SJD1CmxcAfmZohY1pwGKVFq/VOjYoKKwP3ekvFO/k84A6B6RZpLtY3G4TTWTGqcDKrK7aNu4vgHPCooIh1+S1ItuUIze19BuqDXM9Dof5kpX2Q/BgK0PyKpq7ZW/X2as= 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=MB0KdTv1; 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="MB0KdTv1" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-572b37afd73so11104853a12.2; Wed, 22 May 2024 02:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716369495; x=1716974295; 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=E/SuC7+08n2vCECZ9UGktNuVdHeXOcscIV21TQ6r7Hs=; b=MB0KdTv1wR7kfJkG2xQ4bj9rNVyWFNs3ud/3RkQqP6+5BnutVNwcFFg5o0lJEJ3Fl/ PhuLX8RLuFU5OFjx19QajgcAS0/RxiTnzUHeD5uy6XMdIwyqS/DhOdytElAwHl79e6qK aSoIPrPeUxxRBmqBwYvz+T6iCxXbbwfx7A+fsnupwq4PotLCeVCIxFk2yX+sOf5VmU1r L/U0BkmXHNnoXWXUUbp6/378pNJtID2ZZAG/qOZHpmprcRlLh0fOnJ7GzpqDcErx7tts j072mVCheVDqtjRNgSZ6/WGsRIMwD/ewOovFYSTGNHuXZyiMO+9rRZHPP7wIXagD6lcH E+5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716369495; x=1716974295; 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=E/SuC7+08n2vCECZ9UGktNuVdHeXOcscIV21TQ6r7Hs=; b=PZtPimNIREhFGIHUhJya2B/97BOUG8R4oE3IwmEbE4eLmqn8RQqfbZ6jaFLsheSTi/ tjDsNV3Bjh0xtB3+7h193QP/rIS/AxFlO9ifN7RwrW7/3aLSEKLR3yBI963Ka2FjNiXe N0R3IZVm4Q5Wlob02a/+HY8uCAP4LvF0qQx2K6vKXFTicvD/7hwqjj2s4dpiHTyyd/my 4V6g7i+nl0ALG3igrfw3lVB1QGGDiDpueXtUPgCpRIBG8kLR5STXrVdYXvT5ai/oLXhD u+FR5fyvTQ5WTNmjrC6bF5nOWLYy4wb3CxpCmySEWMabAI6Vd/qqsPboasiSyyZBSnjx 8Lyg== X-Forwarded-Encrypted: i=1; AJvYcCWwQaTjRtkUURIdGTk2WQfNNjjpFXQbiD5C/3a/Hd6n8OWplwxpYj7kpvQjzW/lcR3kDtlripi9/iSO7DBBA/HSwvIPu7wtvyIwsgFwdoa1KEu3o04beXmyZIKCKu6Ji3wCfD/6xLg85Ck= X-Gm-Message-State: AOJu0YzHa49ZS/N5xIlEJdYjM45u8utZIC2wGwCc6TEmZIbDbC9rQkPu 1LCV2Im70NaUYSC3xegYclRVPuQIgqHnnEt36YbhhO/H8sQ8Rk2H X-Google-Smtp-Source: AGHT+IF/abuB+35BiACuJiMAWk3Vdx15AYYVtexypEh5EAJOOiGLT5XZcyn/DsstVdk3MZmt75OvYA== X-Received: by 2002:a17:906:b2d0:b0:a59:a977:a15b with SMTP id a640c23a62f3a-a6228170ae1mr80912766b.68.1716369495442; Wed, 22 May 2024 02:18:15 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5cec3d9b5csm836678066b.16.2024.05.22.02.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:18:15 -0700 (PDT) From: Javier Carrasco Date: Wed, 22 May 2024 11:18:07 +0200 Subject: [PATCH 1/2] device property: introduce fwnode_for_each_available_child_node_scoped() Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240522-fwnode_for_each_available_child_node_scoped-v1-1-1188b0da12dc@gmail.com> References: <20240522-fwnode_for_each_available_child_node_scoped-v1-0-1188b0da12dc@gmail.com> In-Reply-To: <20240522-fwnode_for_each_available_child_node_scoped-v1-0-1188b0da12dc@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Antoniu Miclaus , Jonathan Cameron Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1716369492; l=1290; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=clL0rBh8NOdBwMJgT36ockVwV2WORoYm3aKRiSyAeBM=; b=bsLn6S4t9QZoPppi3IVSBbC3zONy3ba3SOgXnySR7A+tL92YLMD5hb+eiqmX3SHgl17fcB6Tg gWm7iyGaX0iAKqNnrxExlVt8r8gYWd2doQRuv3C+A7K70zzx4UCFVoO X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Add a scoped version of fwnode_for_each_available_child_node() following the approach recently taken for other loops that handle child nodes like for_each_child_of_node_scoped() or device_for_each_child_node_scoped(), which are based on the __free() auto cleanup handler to remove the need for fwnode_handle_put() on early loop exits. Signed-off-by: Javier Carrasco Reviewed-by: Andy Shevchenko Reviewed-by: Sakari Ailus --- include/linux/property.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 61fc20e5f81f..bcc3dda5a9d8 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -168,6 +168,11 @@ struct fwnode_handle *fwnode_get_next_available_child_node( for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ child = fwnode_get_next_available_child_node(fwnode, child)) +#define fwnode_for_each_available_child_node_scoped(fwnode, child) \ + for (struct fwnode_handle *child __free(fwnode_handle) = \ + fwnode_get_next_available_child_node(fwnode, NULL); \ + child; child = fwnode_get_next_available_child_node(fwnode, child)) + struct fwnode_handle *device_get_next_child_node(const struct device *dev, struct fwnode_handle *child); From patchwork Wed May 22 09:18: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: 13670628 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 9437580BE5; Wed, 22 May 2024 09:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369500; cv=none; b=fnFD+R1uzJqSDP5D2APpeRNlFyKvZl0fBPwLU4mIuKg2pap7LnyTpN9mvK4dQrQOLolRIGKLeaVriS9Pi7FsRox8u6dkqpq6cZk21TiwVRjtPkyoNqjI+70G85fMDihz1Ij/3DwUM7Y0L3t8Q9Gu1eCgerZgtpBwSqe+lRDazUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716369500; c=relaxed/simple; bh=gJ0Rue8CIZyFI5vYaIOIDGhFikGz+fvLwhXk8VedQ4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m/nfGFmr64JpNaefN8I2L5bRw6rM9UkbfAV3/BpsZgUC0VBhzb3TJZfpR+UeGssUf4Uojrn9468SAuVrW6ZAO0mKETLwpSoevbGzHerIKYm2+9x2aReDepYcpDxD/hEi/qRqaZ6sz3FeHS7eupYzxVW+cqWjVQV8IJfLQYqYEds= 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=K5r6mYzE; arc=none smtp.client-ip=209.85.208.53 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="K5r6mYzE" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-56e56ee8d5cso11045731a12.2; Wed, 22 May 2024 02:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716369497; x=1716974297; 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=hS8QMYPX9HU5iZYVx3xj9uGjra02vQn4uMTO3p8AL04=; b=K5r6mYzEc+YSf4uuURpEE4QKV7ehLV3HEzMlKwl1Lh+oCSmsfrkvRTmk2uwqfRz8gw bP33phRu/IbNtqIcC+bRlWs9MSimYVhx4tGAUERTp0AMNyaDCgaBV1tBuQyOMxRpVvWl rcw0CzpxMcvrCxjl4tQN5aEqWS7Q5tRFO0RMPti07KOX2H+y5T3+4YvbznzXWyqYT3DT QY10HWMQFz4imaKIrai4QL3WjdeK7qD6QOyrRPGIpmWNGAV/7WhVytxcmqCCtOUJNuWZ VqS31oZUnnpKDsL21SvpLPeZixxFzxAnTB+pYfkbuH4rKRI7Jk9yCWWEq3E5hcaQO6hq acyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716369497; x=1716974297; 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=hS8QMYPX9HU5iZYVx3xj9uGjra02vQn4uMTO3p8AL04=; b=pVtYxARtGl5nQ9+Itb+onY6qU+ajgQautohlLQrQnsPV/kD3b+fXZh70hWB4tZrYTB g/BWW9g85/5SVfM5Pm/zBT6emf7KggDlldGdJIgvb04zBKjJjZNA76NnV77yhABiHvq1 1rcf0wWLfTLZO0/LFFPyo3QIMZ4F54VYcBVmi7yaqI9WJwBltvMtv8+MykzL9lp3A1fa lahc1BclxZ8qsJsdj4BbZMXq+0nZLXVWBq9JvPrd8ZucWNInxeyp9jQiHZY30mqGAAlf CWOmcVPmlg3ILA8HK63sJgaMUk8qM5/fE1NJl9Sr6Jns+7S64UOfFrEQe9dsPgRHiNL0 V/1Q== X-Forwarded-Encrypted: i=1; AJvYcCXi2jO230Ny7ROueWv4KI+ibdheTs+wtD6XQPptx8C4kRE5qUYhLt0WVOGsZQzVMdydGflhOskSmaaLe6g0CLSbapRS+G5JUzxfnzcLnH39kmtOyUJrQulhmYIdHAYc+ghNP/MGyNdgypI= X-Gm-Message-State: AOJu0YxaBXyQWfYfsatv14B+fwy0ULpyn3bzAVYmBV6CA8UnC7l/PjS8 8tVnYw4I5/Zvb66h3t9AlTXl45ro/44XwzQoc93eo84+yoC/3kDm X-Google-Smtp-Source: AGHT+IF/8OxWhDUzjhGymfGdtzuojEnUQciyaHavmrRUL77vmxFvNHu12QGy36TR9eglHTPzQgnaZQ== X-Received: by 2002:a17:906:f8d6:b0:a5a:2aed:ca2b with SMTP id a640c23a62f3a-a62280611ccmr92560166b.28.1716369496750; Wed, 22 May 2024 02:18:16 -0700 (PDT) Received: from [127.0.1.1] (91-118-163-37.static.upcbusiness.at. [91.118.163.37]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5cec3d9b5csm836678066b.16.2024.05.22.02.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:18:16 -0700 (PDT) From: Javier Carrasco Date: Wed, 22 May 2024 11:18:08 +0200 Subject: [PATCH 2/2] hwmon: (ltc2992) use fwnode_for_each_available_child_node_scoped() Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240522-fwnode_for_each_available_child_node_scoped-v1-2-1188b0da12dc@gmail.com> References: <20240522-fwnode_for_each_available_child_node_scoped-v1-0-1188b0da12dc@gmail.com> In-Reply-To: <20240522-fwnode_for_each_available_child_node_scoped-v1-0-1188b0da12dc@gmail.com> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Jean Delvare , Guenter Roeck , Antoniu Miclaus , Jonathan Cameron Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1716369492; l=1624; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=gJ0Rue8CIZyFI5vYaIOIDGhFikGz+fvLwhXk8VedQ4Y=; b=wQ3arPrlq5jG+PHOk8g6UYSech0Zs3LjLnOqv1Zq9azk4RcV6qXWM4uz27Ag7lYIm9qToKnPd MgBAG71LnogAwtuBRihcB19SRjRzZnPPxmCE8GJsjuG7k8cQxl6C5qD X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The error path from a zero value of the "shunt-resistor-micro-ohms" property does not decrement the refcount of the child node. Instead of adding the missing fwnode_handle_put(), a safer fix for future modifications is using the _scoped version of the macro, which removes the need for fwnode_handle_put() in all error paths. The macro defines the child node internally, which removes the need for the current child node declaration as well. Fixes: 10b029020487 ("hwmon: (ltc2992) Avoid division by zero") Signed-off-by: Javier Carrasco Reviewed-by: Andy Shevchenko --- drivers/hwmon/ltc2992.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index 229aed15d5ca..3feee400ecf8 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -855,24 +855,19 @@ 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) { + fwnode_for_each_available_child_node_scoped(fwnode, 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) {