Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2172346lqb; Mon, 27 May 2024 10:03:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkDKC/1w6ZQ6evBvjOeTI8xoq3qVrtyT4oDZCqFNpUcLLCpx6GHLkyVKUcqCa6kraVc+EIoWl4QqwxB3KNXZ0U45nxuRMrYYrUdtcEpg== X-Google-Smtp-Source: AGHT+IFkR6TzJ6Ut0P5TszIlCjRr4qah8WiPMOjlkQK/eepUjIScOwfbmJY4gO4Nf3+LVKFaIfGK X-Received: by 2002:a17:906:6854:b0:a59:d4f0:cfc3 with SMTP id a640c23a62f3a-a6264f0162dmr693160266b.59.1716829414764; Mon, 27 May 2024 10:03:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716829414; cv=pass; d=google.com; s=arc-20160816; b=hAG/tmDW+nAxxSxFz5lOaT5Te4j4pbjPdYzC40kntn0RZcRQ8VPIZ/kN/pfXwXa4c1 6V2k0s+iLiELSmrtna7ZXcLmTB/Ry0j04kFpmeZMngsem9ukRd+T29zHLchtRiRXn9qc ncm752AYEqWYLEpkVeG8LqETACPJNTEeIyPCg4rqrdPCDUjCmyVXW/AvVr0gjqobnQz6 eu+usBqkTdNWxRK3zeM9iSvBbL7gx8LGjZ6yPgZNy9XuejzXXvS5PYHjFASeNP4AoS7R Zd1XE3oPGTRp76SCK10ayk5EcBI8yBt5m4eHs1RUXBFNevfJxaJnSRJynQvNeY6cJI8e YP9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=90KlsSyf6Yn5RDtjeVW4pqlI6tYTKWqGicZUgEVUicY=; fh=IfiM2EKDZyid5GkCO7huf92vha/Z8VYlvAsd3R8yV00=; b=xwQvFC4U0yRr2kDuxnf2+ecl6vpMgdjV58iz5zPN1+k4IaIxjUPAlcQKTY5MAgB6f6 a6NBn6c9DIxFjyllsiD0vDPVJoaCro42PPYsvsIfbEl9fa7rcwU/BAZmHk08cqF+8JsP 74u0yQi6YeyhTrKwFaX47dTnRVG94F7D4vLH0fdgN/DgoaheAOcXu9AlklQpVqrYVkSB b4cJ/VL2hwMTT1rJdAXSkl/9NeSR/d71iqPJ/uyRBu1I+mgQmiFTnm5qQo5KbiWR0kpy 4vHJoCA1aK0iE2EgkAup6Ivu28lEVqup38pQMeY56Nw59WZIFNoH/9VHXNEcKTUrUVY3 C3cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WiPBrewd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc644a2si399702266b.559.2024.05.27.10.03.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 10:03:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WiPBrewd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191273-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191273-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A071F1F22EE3 for ; Mon, 27 May 2024 17:03:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A99115FA7B; Mon, 27 May 2024 17:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WiPBrewd" 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 3066915EFC1; Mon, 27 May 2024 17:02:40 +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=1716829361; cv=none; b=goO7VehsJ7JCGeegBCbWioOSUEPUz3e4JbVmAxixiaIUY8AZm9CshTKe2EDULkqJLYJ6QIQJeGk/XBQKqR/mJhbE/DAOT4wH3iRvZ2thfWfb4K+ztG7PCuGnU8HAS+aiF1BQUIQayetYk9NdbpGzrnfAUtlpG9i9jxYE+jLbyp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716829361; c=relaxed/simple; bh=mnTuVxNr0E3ciZMolDdevZD+FZjwWFUCdR5eEp6BP5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=irpFjhnHTNWbj1WbKOGNho8fmnn3EbBvWnL5wBHpCX1x1IeALMWnz3CxGgkWErTtF3injvy95BCVbBrQ+qI4D69fzvrfzOHMLQ3WKPdwNTIb91lihBaqHCw1KHOPcDlAYwI23eHpxLcF3Rj5UFNB9U7XAxw8HQF9HGMOHaz+sU4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WiPBrewd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id C07F8C2BBFC; Mon, 27 May 2024 17:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716829360; bh=mnTuVxNr0E3ciZMolDdevZD+FZjwWFUCdR5eEp6BP5w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WiPBrewdBFtnVBf8s4gMXzUiHA/YL8i6mhKaM+B/SJtdgZFs814suIQlQ3KiTwNlR pDlZH9zVw9gdFWi0vUknjXd0HJak2mtwCkTAIpZgUw5M2XqtsPfv+Bk8NaVfXzKJ4a I3MMAoLLP4o1mqcmuaSfnJvBrSx8uLVXXkS9Mn7btVHqqgCg/mBa12KT4AlipPerbz fpgWMwBEJIBfuG9srRACi8U9CfDs6dlulSbPhTi2iAh9MrL1VpSjh5RFjs4bHnDlbr VDXnRq+vgCvEB+hXULwML7v2cYcB3Z+5UMmDSgSMHq4vve07M0jx5mO4NUDDhdPZEK HUIyO4R9mT8uw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB63CC27C43; Mon, 27 May 2024 17:02:40 +0000 (UTC) From: Dumitru Ceclan via B4 Relay Date: Mon, 27 May 2024 20:02:35 +0300 Subject: [PATCH v3 2/6] iio: adc: ad7173: refactor channel configuration parsing Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240527-ad4111-v3-2-7e9eddbbd3eb@analog.com> References: <20240527-ad4111-v3-0-7e9eddbbd3eb@analog.com> In-Reply-To: <20240527-ad4111-v3-0-7e9eddbbd3eb@analog.com> To: Ceclan Dumitru Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , David Lechner , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dumitru Ceclan , Jonathan Cameron X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716829358; l=2347; i=dumitru.ceclan@analog.com; s=20240313; h=from:subject:message-id; bh=3czhFBTraxeF02Od1vA/Atq2gjpymKxEOKbv8x/yVgQ=; b=lsx5ZffZx+8QSMMmyNhexpASH4X/d9nzpYidIgw1x5GZaJIkg0WZjEdx4eZyCsKKh7OtbjOo0 Q51u+EkyBkIAN+hSzdNugEW/FDCqEjhpFklZa4hjtgp7Lygyxa7f2q7 X-Developer-Key: i=dumitru.ceclan@analog.com; a=ed25519; pk=HdqMlVyrcazwoiai7oN6ghU+Bj1pusGUFRl30jhS7Bo= X-Endpoint-Received: by B4 Relay for dumitru.ceclan@analog.com/20240313 with auth_id=140 X-Original-From: Dumitru Ceclan Reply-To: dumitru.ceclan@analog.com From: Dumitru Ceclan Move configurations regarding number of channels from *_fw_parse_device_config to *_fw_parse_channel_config. Suggested-by: Jonathan Cameron Link: https://lore.kernel.org/all/20240303162148.3ad91aa2@jic23-huawei/ Reviewed-by: David Lechner Signed-off-by: Dumitru Ceclan --- drivers/iio/adc/ad7173.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index ebacdacf64b9..9e507e2c66f0 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -913,7 +913,23 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) struct device *dev = indio_dev->dev.parent; struct iio_chan_spec *chan_arr, *chan; unsigned int ain[2], chan_index = 0; - int ref_sel, ret; + int ref_sel, ret, num_channels; + + num_channels = device_get_child_node_count(dev); + + if (st->info->has_temp) + num_channels++; + + if (num_channels == 0) + return dev_err_probe(dev, -ENODATA, "No channels specified\n"); + + if (num_channels > st->info->num_channels) + return dev_err_probe(dev, -EINVAL, + "Too many channels specified. Maximum is %d, not including temperature channel if supported.\n", + st->info->num_channels); + + indio_dev->num_channels = num_channels; + st->num_channels = num_channels; chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), st->num_channels, GFP_KERNEL); @@ -1008,7 +1024,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) { struct ad7173_state *st = iio_priv(indio_dev); struct device *dev = indio_dev->dev.parent; - unsigned int num_channels; int ret; st->regulators[0].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF]; @@ -1067,16 +1082,6 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev) ad7173_sigma_delta_info.irq_line = ret; - num_channels = device_get_child_node_count(dev); - - if (st->info->has_temp) - num_channels++; - - if (num_channels == 0) - return dev_err_probe(dev, -ENODATA, "No channels specified\n"); - indio_dev->num_channels = num_channels; - st->num_channels = num_channels; - return ad7173_fw_parse_channel_config(indio_dev); } -- 2.43.0