From patchwork Sun Apr 28 17:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13646085 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26D0F9D9 for ; Sun, 28 Apr 2024 17:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714326036; cv=none; b=G57Y50VN3xNeuol3Z4mNriQ8SL5AmA0CHLSf3/Ql1HAIzhxn2BoLWjcSKVxO5s8Eh3p7YVvqRkQcd7/Vlu+RaNotkSWtKKq/0erT3XdhoYL33ydvkRYoQhbIJAanF4w7fyDZjb0uqsBfAMR818YBjasySPSN17gyIMlxaiTA1eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714326036; c=relaxed/simple; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHQ4R8TaY3uz1wLag3IqFJB/F/D9VzOYmFXvZBAV+BbOROomjsWZXVMYePo9Ntb6hh0hr+HZ4CRk7Opw7MbliwS7Ni8vxPkPl0p0l+/RyHCSNaQBViHBgtFoH82D9iiD3TGHjUkQVOjpnjn5J+756SuYbA5y4sUYg6+sB61o7P8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p07Y9pEB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p07Y9pEB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 544B1C116B1; Sun, 28 Apr 2024 17:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714326036; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p07Y9pEBiblOcWsRBSIt7Plc+vbZrV+ZWpFhIWVttFwjnsUX5UZ3Wg33wTrTpO8mx YAddpeHgUg3breGLd9OJw+FKyZYosFyWD4vLm8H8lgBgPCZgK4IYU1s5R4chRHLoS2 iT3Nx+E0eGP4AxdDCaIl1Q+rLMyQFrfERpZjHONIOJwPiBlf13eoeXMFuJI3DScq9S Z/+W6VtOtw8004UJYuxjk6ZrwH8GUJsvEcbi22OYJTGn7eyp2OojT9kDxIMEh0wlsG IWawWwZsOUWZnMuQ/STdKOrJTbZQDFkl6di13Tz+7MatuIA7mvPSS9SvaIq97Xr/pQ JGA2lBv/qEtiA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Marius Cristea , Marek Vasut Cc: Jonathan Cameron Subject: [PATCH v6 1/2] iio: adc: mcp3564: Use device_for_each_child_node_scoped() Date: Sun, 28 Apr 2024 18:40:19 +0100 Message-ID: <20240428174020.1832825-2-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240428174020.1832825-1-jic23@kernel.org> References: <20240428174020.1832825-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Marius Cristea Signed-off-by: Jonathan Cameron Reviewed-by: Marius Cristea Reviewed-by: Marcelo Schmitt --- drivers/iio/adc/mcp3564.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c index 311b613b6057..e2ae13f1e842 100644 --- a/drivers/iio/adc/mcp3564.c +++ b/drivers/iio/adc/mcp3564.c @@ -998,7 +998,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) struct mcp3564_state *adc = iio_priv(indio_dev); struct device *dev = &adc->spi->dev; struct iio_chan_spec *channels; - struct fwnode_handle *child; struct iio_chan_spec chanspec = mcp3564_channel_template; struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template; struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template; @@ -1025,7 +1024,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) if (!channels) return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n"); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { node_name = fwnode_get_name(child); if (fwnode_property_present(child, "diff-channels")) { @@ -1033,26 +1032,25 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) "diff-channels", inputs, ARRAY_SIZE(inputs)); + if (ret) + return ret; + chanspec.differential = 1; } else { ret = fwnode_property_read_u32(child, "reg", &inputs[0]); + if (ret) + return ret; chanspec.differential = 0; inputs[1] = MCP3564_AGND; } - if (ret) { - fwnode_handle_put(child); - return ret; - } if (inputs[0] > MCP3564_INTERNAL_VCM || - inputs[1] > MCP3564_INTERNAL_VCM) { - fwnode_handle_put(child); + inputs[1] > MCP3564_INTERNAL_VCM) return dev_err_probe(&indio_dev->dev, -EINVAL, "Channel index > %d, for %s\n", MCP3564_INTERNAL_VCM + 1, node_name); - } chanspec.address = (inputs[0] << 4) | inputs[1]; chanspec.channel = inputs[0]; From patchwork Sun Apr 28 17:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13646086 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EC91F9D9 for ; Sun, 28 Apr 2024 17:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714326039; cv=none; b=r8x+3S0BNR7US32K1EV2RXNgB+7aIo53WI1JTql4+tlxM3tMNpn+TCJSO83rD7gDbTQkKFbeKRGPQQvuHH7joiwKzsEcgxmA4DUjZskfe7zWY05M9zBFFK00/Q1KOUo78XPXzT2K5QvWfiFI8TL93QI0EHppebi6uoIUcNUYBU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714326039; c=relaxed/simple; bh=m9bHBC6aPtg+HNstAk3kQ6vbYkbeec+pVBvkWAQ5pCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q36624KXPtGHRJouIGKxqt2aM9444C8FCdCFyZq+QQOfzqn+2ZDexQATdzY8zqWglGAzJ+8enKmPPvxdSTkcneyZIAHNBwFYD8O/rAIlV97yBToplPekbVOvCIGVN1QrS78k+gFZkKTYIDpnmaN44v8P+IDgepdUbPw4Uw0SOyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oAuGkSMr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oAuGkSMr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33BE8C113CC; Sun, 28 Apr 2024 17:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714326039; bh=m9bHBC6aPtg+HNstAk3kQ6vbYkbeec+pVBvkWAQ5pCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAuGkSMr8qsT+bf/SHqavzWzRHuEpkVqS7125a7L5MRU9MQUY5VvGpfJZdD+ZUtqW QIqJOhJeHA4p0reSKUt+6I48mwMWzX76a8G821TOhA1Lbh6aZx/NxWOXYn9bCOcaZq gzQvEYvWMcA/bo4b3hXLLgP47BDQjx/i5TN3KPkxvBAqqG6ZD9Eb1Z2vUVctivqmIa Bn8LRIFbXV4yf596lX7Qa5a4UIhEuTXFdsLUTFaglBDl0zwqy5qaZPWB/3i+INEEoY W09EJBiDJX112indPJLKOpOqJQ4VdFHk5e5pudWn5aH3e2v3unp4RydxLDEftRAtMw cEhLAKXY4c/7A== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Marius Cristea , Marek Vasut Cc: Jonathan Cameron , Marcelo Schmitt Subject: [PATCH v6 2/2] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Sun, 28 Apr 2024 18:40:20 +0100 Message-ID: <20240428174020.1832825-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240428174020.1832825-1-jic23@kernel.org> References: <20240428174020.1832825-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Marek Vasut Reviewed-by: Marcelo Schmitt Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads1015.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 6ae967e4d8fa..d3363d02f292 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ads1015_data *data = iio_priv(indio_dev); struct device *dev = &client->dev; - struct fwnode_handle *node; int i = -1; - device_for_each_child_node(dev, node) { + device_for_each_child_node_scoped(dev, node) { u32 pval; unsigned int channel; unsigned int pga = ADS1015_DEFAULT_PGA; @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) pga = pval; if (pga > 5) { dev_err(dev, "invalid gain on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } } @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) data_rate = pval; if (data_rate > 7) { dev_err(dev, "invalid data_rate on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } }