From patchwork Thu May 23 15:47:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13671987 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 8274012B89; Thu, 23 May 2024 15:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479256; cv=none; b=QFcMt09v0aS9IiJgX+Lrs62RPiQPdeHLBoYhkJpAJBcG5b6DQ31ZMYGTHZWig9HzRnPPKCE/XfWz3JswfWq7ASu63HGz0QlKhO/GYSXouwdO9qcqKxRiNS3NyRR92+z1l3x88jBbSyRx33LgI0xjI3uyH5XJQiE3Lq0J/ohWZKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479256; c=relaxed/simple; bh=9hWCfjhhVw3iKm2K8ZqqBvjv4a6eCuEbOteQFItL/So=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R3MiuON/NR11eKjT4DEQxizPKkKdhAr2W8w+B5YPIEemwlWQPJqt2mdBejxNAMwFIDRvWCaoTOyPliK2TNCTE+7p/DaAKMGe1A5zkEIj6kEE3+y6XbzsApiCbWXT4AOUPw6PAEbispuN9C5zcT6PuVDxycEZBtLLGyRJuktIJng= 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=cuVmT/KV; arc=none smtp.client-ip=209.85.208.171 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="cuVmT/KV" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2e538a264e0so108862031fa.1; Thu, 23 May 2024 08:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716479252; x=1717084052; 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=l9FQyjhPHmXpcdMO6VzbCHP+i07w7eEawaXliufyJqc=; b=cuVmT/KV2WeCiMH6xcRrAlmCO5RrkFkUtiK6sTQWtJL1ESx1VXVqyJdKW1SIP042IN +Py+4BstuNmsOZlgQnAHUKlZkQOnpQN+3bhpA+QxhgAGfs1UuZMBE9nBqIVSiL9exTEv ELYO5mS9mE6w5xuArYKnG80bIVndQhEpUXcBfl7syfqbvM1hMT6CElg7VDbhtIZ5lQhi aa8Q7uiRQORf9SzAwSz1OZcT35puaU9pu1KKeark5RxJ/PsEVug8cAzMM6vOAE18qqJs ZCWTleCXWKLiVbu1zjufUsk/wt07/TekhTmXuHaCwgrQ2Bv5ltl+3Z9pQhvNnNvXAamW Y09w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716479252; x=1717084052; 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=l9FQyjhPHmXpcdMO6VzbCHP+i07w7eEawaXliufyJqc=; b=Jqmvlx/eq0+EqBSHW8m1YA6Px8G7N5+ZmjFJaqelMXNon2hp3cC+i7q0KrXY6VOM1Z YCalN6mAOLUH8JBzLzm5qGkEMeEbADEKfB1YVROrcnPnMEsmCID40F8ugPAKtYFxvP17 4f7ZnMXHcnNoOREcBH9VbzzlA6LUpmboZDDjsIiOIJJ60IVrxd5Uj6P+IBFe2Um9PWSP rTrVnbIK0S51no2CWQhfs2n6w+jxcJzDRVTWEDAAbCmycs6SOiA9Cwtqh8eLacoBnAov yTq14S9jhVTPUKYR8MtXa9Kv8+3KqGaUZAWvDwGxCyNBZW1JhZdH7RHet8pW0ip2XJL1 iGCw== X-Forwarded-Encrypted: i=1; AJvYcCW/eNMcsgdsNZM40WyWYIykS6T5au9xhqg9cDs/Xt4SBJfeDvmtGRznrEudHI+dvVigCqT+kEvjnhDKgp4nqVy5sTJ3U5jcZ8fmEIUEKIFBYfFBvsbS6KvFAVsSZfmwyKcTP3CnZk1wQ/dxMFgO2qkFsFoFazStCGBl+FXN1Jtpn6c= X-Gm-Message-State: AOJu0Yxmvndc/atbq1prwPO9kmOVsfteIBved6aGM1ibjO+mrpGQsZWX jq8zZW8VpTMMHzmnVrLvk2oRe0zHBiYzSg04gQPOqgdqTLf/WcR9QOOwSlRnxL4= X-Google-Smtp-Source: AGHT+IHOPon9/wAOsXX5ACXesmOWEvoSUCdGumsqH6LYPpDZhTFoVRQ0woENgeiNb4K33Fij75kDcg== X-Received: by 2002:a2e:96c3:0:b0:2e9:555f:54e with SMTP id 38308e7fff4ca-2e9555f08bdmr16396651fa.18.1716479252157; Thu, 23 May 2024 08:47:32 -0700 (PDT) Received: from [127.0.1.1] (84-115-212-250.cable.dynamic.surfer.at. [84.115.212.250]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f5a576sm28569725e9.22.2024.05.23.08.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:47:31 -0700 (PDT) From: Javier Carrasco Date: Thu, 23 May 2024 17:47:14 +0200 Subject: [PATCH v2 1/3] hwmon: (ltc2992) Fix memory leak in ltc2992_parse_dt() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240523-fwnode_for_each_available_child_node_scoped-v2-1-701f3a03f2fb@gmail.com> References: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@gmail.com> In-Reply-To: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@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 , stable@vger.kernel.org X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1716479248; l=1134; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=9hWCfjhhVw3iKm2K8ZqqBvjv4a6eCuEbOteQFItL/So=; b=cUt3FVuACsgdaeqMx1ewYFxQ1Ie/fOsFuDfGfBu4aZmqq7BgBJhE2eksmLuECMRRrmBO9Cbkw ef60GlkHglgATzTHOWTG5DXQSnJI0IerCpJFdKAKFpw6J307tB7kbTw X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= A new error path was added to the fwnode_for_each_available_node() loop in ltc2992_parse_dt(), which leads to an early return that requires a call to fwnode_handle_put() to avoid a memory leak in that case. Add the missing fwnode_handle_put() in the error path from a zero value shunt resistor. Cc: stable@vger.kernel.org Fixes: 10b029020487 ("hwmon: (ltc2992) Avoid division by zero") Signed-off-by: Javier Carrasco --- drivers/hwmon/ltc2992.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index 229aed15d5ca..d4a93223cd3b 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -876,9 +876,11 @@ static int ltc2992_parse_dt(struct ltc2992_state *st) ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val); if (!ret) { - if (!val) + if (!val) { + fwnode_handle_put(child); return dev_err_probe(&st->client->dev, -EINVAL, "shunt resistor value cannot be zero\n"); + } st->r_sense_uohm[addr] = val; } } From patchwork Thu May 23 15:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13671988 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 51317171A5; Thu, 23 May 2024 15:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479257; cv=none; b=GfBnvdJarzNZOqYF2cInTgOYHVGwDcy7MMYTmWrp1M3DGr0BrLr+poX9WP4oKDDLhAYt/gcF3lf01NClhjp8Y5g9I3fyvgk4e7moP5Yigr9n4D0grKyzbhqWjlLoasyPBIuaz0SlYkTrfdGaNwLfiWd2olSGD24kA1NcX6rK4cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479257; c=relaxed/simple; bh=mgKxk4kqyOKEtZOpwFvK75hdFyTZlYf7QqUN84i837Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZHUGxwjPgjfxt6rJ+6lkrAKibiu0yrFGl+Go/ZZXCze5VUpu0PCHZjAif4ai+saVxlc0oNF39NbifiUkEFdXkAspTGWw+nUg5X+lBXXPmS+f2BdUGqit691A9rHuwkAUDjGqRA4n4A9CG7cAPv6ciG8UR1WgcU/g/JL8CI6pa4I= 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=hk0akTly; arc=none smtp.client-ip=209.85.221.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="hk0akTly" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-354f69934feso670077f8f.0; Thu, 23 May 2024 08:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716479254; x=1717084054; 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=ni+RqltCXaCNZL9b8F9XE81/Sw38rziGN7U8OpBwI5k=; b=hk0akTly3q6jR1Lsot6+DIEM4mufldbnnqx4AyNBPee0hBaK1pgpc1Dj0rkN1V6Krz km+dZHF8okcunrhiEqNsW0PINNAAwih7y0xzx76H3AZ9/qcxAsMQUUArsrezyBpGGRFZ FLN6u9VfoAXCmFM4tJBNaXqI60NYG4nMvQBEMe+n5Fb0etyPqy5cWozzO9hESQe2vAp2 Ljv7pnq/zQb+R98xHQtZAhfzPSaiwinwIoA5NWbNZ5QERIt1TuOl5lhG6sNAyACfZMqs 4NtkaAChViF+tHJa4g7Vl2ypsDj+Gqk3UvlxidHIXetLRoCtVjLgImY4acz7XIr6MB1E ReFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716479254; x=1717084054; 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=ni+RqltCXaCNZL9b8F9XE81/Sw38rziGN7U8OpBwI5k=; b=Nemusx2l6LgU27rgGFJXVrZqsGVImTjGOhaAxXKMJsoV2PlFejOTGN4kWtMCZGw79y uWCSfjWO+YzCDg3oRB/MgbPp0HPMg0m2V4FabUQssdlyPH5vwOlwIecv8oFikkahFg3M ZsXnF5mFQLSubIYtzi9q7o/LhKwIEvHn0ctiSo2sbqb+hR44bOVLZQp0AjDewt3CvWrg KSJsq5e2MCMRvtVOTn8i56noEUgkUebG64YtdW4dOKge9Ixbqpri343ZqiaJ8395Ufn4 xzaJAacjSircC/xt9Nb5MGB9qnnIkbfTbfdKEqwaTbTrG1WMydoTrXLEzSvrTKKZaCpU puNw== X-Forwarded-Encrypted: i=1; AJvYcCVy9zCLwW3cyfTntn54qi7+lYb4Rt0kWzAhPPNOBxcfSm16RmQ0whF8W7Zls+l4qphD3zV2m90TLFeQGy1PSkoiu5yVfM7j/kYDfckRr6nX1Yq4injESQWdnz0G3xFXK8VyeeVoB3aESx4= X-Gm-Message-State: AOJu0YyPDjpR37hmU0qrcsNb0dJAGbX+0SmH+/WImOg+FtODryjL//GN X41v5wOcBRlCOFyEUhNyDqq4VvxbP9My+cAo3A99K+XKIqGUSWF8P6myBVmlkhk= X-Google-Smtp-Source: AGHT+IEwdwLQgejvo83vwsUa0ZCY0Of9z20Fn1QFyxSqI+jRPjwvqYvdzzAxg8fiUD/VeoWcasAvzw== X-Received: by 2002:a5d:6351:0:b0:351:d9a1:4f1 with SMTP id ffacd0b85a97d-354f75a3d6amr2158769f8f.32.1716479253982; Thu, 23 May 2024 08:47:33 -0700 (PDT) Received: from [127.0.1.1] (84-115-212-250.cable.dynamic.surfer.at. [84.115.212.250]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f5a576sm28569725e9.22.2024.05.23.08.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:47:33 -0700 (PDT) From: Javier Carrasco Date: Thu, 23 May 2024 17:47:15 +0200 Subject: [PATCH v2 2/3] device property: introduce fwnode_for_each_available_child_node_scoped() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240523-fwnode_for_each_available_child_node_scoped-v2-2-701f3a03f2fb@gmail.com> References: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@gmail.com> In-Reply-To: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@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=1716479248; l=1414; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=mgKxk4kqyOKEtZOpwFvK75hdFyTZlYf7QqUN84i837Q=; b=cWDs4kp+IgTdKqY6DfDtSL7FHqR3iOb2KbTMby/6acFeycZrT4oYGqPhHUdw9dpl9CGxOetju XyFHz93zxa0BOGPfwNzOPf/S862rlPjTobwnUxIwQ7+UbPNF+Z+3G/u 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. Reviewed-by: Andy Shevchenko Reviewed-by: Sakari Ailus Signed-off-by: Javier Carrasco --- 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 Thu May 23 15:47:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13671989 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 6AA3C18029; Thu, 23 May 2024 15:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479259; cv=none; b=L/5CBwuKoT8BgPTYWvempwECM1PLGrpYowWZnrFK6LTk8/bPP3YpWfpeebN5OQMHZFuuMchMw6U2Xm3CJIU5GIq1+b9ZqqDvMGJbIZdzZrd9Gd7NFuqCGD/2mUzoyvKaFEgkjOfQoNSVAsF8S67tHjENt9oabcKOAP/ADbZGaHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716479259; c=relaxed/simple; bh=W29c7LQHWSwTs1cLDmC6925ws2Ed59HyAJ65h7ys/4I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r7twJvCZr3MeqbrZb3dD5/kfezukbmNROxlpXz93TTCbVFcWZditwtJBVzf4G90grpxFItuT/BAF9rI+c9bUQtqnplIHeeTubrdLNjD/113qszwXhNu8TtKAVqMYyzil2GjBoz9GBAzsiEfve5cBaj3e+FvbFgo5ND4tmjVo84Q= 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=CiTw7/Sa; arc=none smtp.client-ip=209.85.128.41 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="CiTw7/Sa" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-420180b58c3so57754355e9.2; Thu, 23 May 2024 08:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716479255; x=1717084055; 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=mgjORZ1nG8GVZ5mqOBWiHYanFt0bhnov5yW5k3xGY4s=; b=CiTw7/SaNLJoa6mqdAKBKZQj0ZdZxcNEmG3MTZup4o8b1PVzbtALUM9sbk7b7MkzpI 4T9dXfswjG4BKM5XeMs/TDFZN5BI7XKsRhBb8dna/zrOyTedurRp4vFDXPgCBcOwm4m7 sVs2/J52xTVqgLDTH3yB6uEOsNjrmvot6Vf7MqH8m1Sraqp8GbCcIzWCHFa9hfXsV6Yj cMeZ4wkDacIlJ/zLGFMOALKDTYgPxPy8lx3QnRzAS/55kQNXXe2Q/LRQxYbzoQ0Q9GQD GEVSTcIX8QNaxDvqPATBo1SFYw+yiiMldoVpYhIwgV6AqWVJcn+qs0TL0uUTE1xQjl9n UXcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716479255; x=1717084055; 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=mgjORZ1nG8GVZ5mqOBWiHYanFt0bhnov5yW5k3xGY4s=; b=wsu7sEvbwxxHRe2/YAMaSkdAXB38bfT0FDr4JFl1XbUfwk3LW9L/eGj0QNjlwjuHly 6PABaQijh99/h9dJWZby2wecLaAWxF+Io6UMhS0wtbiFLpgVERLumch7zI5yY2RXtlqf M2lRtDgqnY/ipGnNODRotRS5RJ+cT4JnjbSEyNaqqnn+zdKXv4vZeBh5aXzRqv7zi8/C zcZbLP770aAENbBOLovTTrXSj22jb5EqodPI2zqhRzewAJWVHTTq1fa521v7NeKn/2dd 3E47EoyEvOhvl8ZrbdRPGUn1MtR4/eblpUToOLqla+DvDAEidt8g9am1mGdGIiBK6BDD +WoQ== X-Forwarded-Encrypted: i=1; AJvYcCXfLA00+rfLoYshPdmMPQgqO1VAXOF94q1mc6Sts67QNPqJ1nR3z+TMudwXnnu+KvuytKsn500cj9qSjCc8snk58qR0o2/34qxiDr9rRf2BZNEqXBXs5zQ9WH3JPYbohUeU6nej5WrP/Js= X-Gm-Message-State: AOJu0Yx0htenNUOVA11RxvevYURV/raK9XSyFE/1k6Mi3x5iLBJBFZIT JQYJjg+ES2xg3GMwj702ipV6SHa9v4bbO9Y1ptAgRmu/8UQPup7ruo+HRkO9Py0= X-Google-Smtp-Source: AGHT+IH81lEU3NMBlt+vvzk9v3kvz88ZQXtT4eKWWxh5WTsZnioymb6B9Tw+CfR6ch5ExosS2yllBQ== X-Received: by 2002:a05:600c:5802:b0:418:3eb7:e8c6 with SMTP id 5b1f17b1804b1-420fd2de525mr42805915e9.5.1716479255556; Thu, 23 May 2024 08:47:35 -0700 (PDT) Received: from [127.0.1.1] (84-115-212-250.cable.dynamic.surfer.at. [84.115.212.250]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f5a576sm28569725e9.22.2024.05.23.08.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:47:35 -0700 (PDT) From: Javier Carrasco Date: Thu, 23 May 2024 17:47:16 +0200 Subject: [PATCH v2 3/3] hwmon: (ltc2992) Use fwnode_for_each_available_child_node_scoped() Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240523-fwnode_for_each_available_child_node_scoped-v2-3-701f3a03f2fb@gmail.com> References: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@gmail.com> In-Reply-To: <20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@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=1716479248; l=1914; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=W29c7LQHWSwTs1cLDmC6925ws2Ed59HyAJ65h7ys/4I=; b=hJsNk1qK9bFp/YtyRLaBHH0CpBC3eyYwxgTIyc4EGzGTSOLsTh0zFRQvHVKbK6UTawaCYX+Og fw7w7hR9WohDlf33RLnmPUHoRnfzSKZOMX23rnLStdiTmIuAXpCWpyp X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The scoped version of the fwnode_for_each_available_child_node() macro automates object recfount decrement, avoiding possible memory leaks in new error paths inside the loop like it happened when commit '10b029020487 ("hwmon: (ltc2992) Avoid division by zero")' was added. The new macro removes the need to manually call fwnode_handle_put() in the existing error paths and in any future addition. It also removes the need for the current child node declaration as well, as it is internally declared. Reviewed-by: Andy Shevchenko Signed-off-by: Javier Carrasco --- drivers/hwmon/ltc2992.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/hwmon/ltc2992.c b/drivers/hwmon/ltc2992.c index d4a93223cd3b..3feee400ecf8 100644 --- a/drivers/hwmon/ltc2992.c +++ b/drivers/hwmon/ltc2992.c @@ -855,32 +855,25 @@ 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) { - 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; } }