From patchwork Sat Mar 30 19:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611659 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 F34EB200D9 for ; Sat, 30 Mar 2024 19:09:06 +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=1711825747; cv=none; b=m5IYNZkGY/fq4lQxaxUMxMrcqJFgQ5GgmqkVYo/OKCxIjgjQLflonMrIZxgJEdDEaSxcCBFlLAo2iePvdO76EPxkg9wyq0oydbSZJmsUpE1ztJ3PtXwaxm79Zazbzm0ZWgQ64+8eZC4Gg6oUu9bxj0JcgBsi0UXXfhO2j6voBy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825747; c=relaxed/simple; bh=pBrBX8N/AVh05V+rxL7ttckidHUEbDcbAnCAdcL7fis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JjZRbq7hUNAVAHjJzZAOYTRHE9tpd8/L2RwO7yPj1VUMT0YOBDSN+1tcz0WSqvhKktR603M/yS0YfXNif9rJ/S7UoCC6FAETUpV8fv7kP9IE09oeznaAL8hXnoXJFqQIhd84zfsZVG/oZrktGOnJ6daSQPXxBKVfA/ZvXrGF15U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NmCL69k6; 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="NmCL69k6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D9BFC43390; Sat, 30 Mar 2024 19:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825746; bh=pBrBX8N/AVh05V+rxL7ttckidHUEbDcbAnCAdcL7fis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NmCL69k6i01OsnPW64Ekkb5PtcHhP2jBDY+DBEEHeOzgrBpJxld2AT4lGUTWR7FVW R4jxB38RZKdGvjsjfqaHGbXSuuhQJeeH+yKpDFV7x0z0TCGJjxsIAcSWq7C13QbT4y KN5PFvcTUuFtHpckR4EcL40c6MAi+v5EXYfkaZXn/chHAA2DNPRL/tl9ZCURcMfi3y k9bU3iUEkL5Bfk4uB90QD69D3RhfZVobcxeN4uh2NAx1CHckC/LSCr9ztvPJddu+Wl Gip6Wvv2jHhIQ8peSznvbMuLDo4zdXYXzqOxEMBIsIypm+MR0/dDQpUvyTGiDTReFD vNTpKSBmQqGRw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 1/8] iio: adc: ab8500-gpadc: Allow COMPILE_TEST builds Date: Sat, 30 Mar 2024 19:08:42 +0000 Message-ID: <20240330190849.1321065-2-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 The dependencies on various ab8500 components prevent this driver being useful but they don't seem to prevent it being built. Improve build coverage by allowing COMPILE_TEST. Cc: Linus Walleij Signed-off-by: Jonathan Cameron --- drivers/iio/adc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 8db68b80b391..e648198b0a0a 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -8,7 +8,7 @@ menu "Analog to digital converters" config AB8500_GPADC bool "ST-Ericsson AB8500 GPADC driver" - depends on AB8500_CORE && REGULATOR_AB8500 + depends on (AB8500_CORE && REGULATOR_AB8500) || COMPILE_TEST default y help AB8500 Analog Baseband, mixed signal integrated circuit GPADC From patchwork Sat Mar 30 19:08:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611660 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 D1E793FB81 for ; Sat, 30 Mar 2024 19:09:09 +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=1711825749; cv=none; b=jzx9gQWZAMkVINhVMrI+WVgMofOyPiZckM3tA07e+zEeeGcNQKwIW/7fYVWZcvCdIY2hzzwuWSp1ADWJyBIz36p6rDnFD5tLcrFYhJZdzsEqqIvnep0GwxRW/cDjhPkXjHl0IV76prNsl7uItYGlACdMLYTFQiT1J5kd5RKeAJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825749; c=relaxed/simple; bh=yaEwnOjwR+uZ4KT7IzIwdUTu/ymz+4wDK9JhXLazASs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XtahXqVnVJSC5v3XFOuBk3aXrMQ4qAdSW/qG15C/n4L/FtEiHghRORp7vnMOgJrAIx87fIl4huYW3bCyeFHprAbeNBJVzp6THO2GmwpFjuE739BOvbs677bH/Z2kW8MDY1iyhoWpnA1Ys7W1XgzTnXbjx6hxd4WwGfmxg97ZBwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NaUsqU2A; 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="NaUsqU2A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F02C433C7; Sat, 30 Mar 2024 19:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825749; bh=yaEwnOjwR+uZ4KT7IzIwdUTu/ymz+4wDK9JhXLazASs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NaUsqU2AYADF2jecmMkiScOo18qZB5Jol3DszsQLFs+IERAPI4Hw+kNxVRqG903/W YtA3vJXa8Jc4J82ebZ+18CJ1kZR8WGzMt8XGyu8UNhQcUA8Kjy3kPCqPJx5G09Rda+ ijYb0SV+XYZVYBsIWwVWp4KBtBGnMvulck48JLHRr6mThOU1+LjGRil5e55d6QpmWK ZOkW9gFNrggv8vSiTlkjE1eLN2+aBFIiEG6QB8fMuoIdloa6c61ERt+Oto+Mep4joy NmrOl7ANQUo00HqSWQdZ/iqrqYzSEuEiji6KFaJ4qkoUHG49/y5lnvBeKxzUz3PuB8 RtS069SnLPldw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 2/8] iio: adc: ab8500-gpadc: Fix kernel-doc parameter names. Date: Sat, 30 Mar 2024 19:08:43 +0000 Message-ID: <20240330190849.1321065-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 Seems these got renamed at somepoint but the documentation wasn't updated to match. Cc: Linus Walleij Signed-off-by: Jonathan Cameron Reviewed-by: Linus Walleij --- drivers/iio/adc/ab8500-gpadc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ab8500-gpadc.c b/drivers/iio/adc/ab8500-gpadc.c index 80645fee79a4..0bc1550c7f11 100644 --- a/drivers/iio/adc/ab8500-gpadc.c +++ b/drivers/iio/adc/ab8500-gpadc.c @@ -1021,8 +1021,8 @@ static int ab8500_gpadc_parse_channel(struct device *dev, /** * ab8500_gpadc_parse_channels() - Parse the GPADC channels from DT * @gpadc: the GPADC to configure the channels for - * @chans: the IIO channels we parsed - * @nchans: the number of IIO channels we parsed + * @chans_parsed: the IIO channels we parsed + * @nchans_parsed: the number of IIO channels we parsed */ static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, struct iio_chan_spec **chans_parsed, From patchwork Sat Mar 30 19:08:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611661 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 581613FB81 for ; Sat, 30 Mar 2024 19:09:13 +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=1711825753; cv=none; b=t1rTdvlYsdYz7CZHGMWNYubHmOJjvWAGwwsYdyD4F6Z82Xl5xzR7SOwcvkaILtYqBlA9fnlF+LMgvRNiUXnHO4GC8CRKHAnpgAvLZRzTSpYCvouJQ9MGcmHQ3hZvEowsKHnzy+njn8cRbkBmxD2RGHOCecXgbFdp5QfLsMDJsEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825753; c=relaxed/simple; bh=h99Hg6GwiZm8R1GlrKNeI5fpGvHJAFB/VxgKTYEkcv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IKHVwkQxSeGmG2VOe85s3h4PooaRsgmknDjhXCsJfdNp0FTf4KWKLyzpOx8Rpfmk9q7IgTe22HOXxI3y7YWsDWJmrLnZUe9G+QYhnneCrQ/OQt0BZNR8Pvm2Y0dm/D9hceiiq58L1226iotqngAM2Djn9PKXHImnZu3rGgEjOqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FRpJiceW; 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="FRpJiceW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CEC9C433C7; Sat, 30 Mar 2024 19:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825753; bh=h99Hg6GwiZm8R1GlrKNeI5fpGvHJAFB/VxgKTYEkcv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRpJiceW1XGm2YqdtGTNtljHaFJJ9jb62S+zeBw5A7ltpoedID3TC5XwYI6ZpyrnM J576PkJspHS7Cet1oxpEGDY/oxfK5LOXiMRtjpMnS5cj9htSnk4QHkTEQmcj6o99M4 3YJt10DXijarQ9qgQv5WTEaitbIpNMfTiAtZpWQ/W4HAKYSStpItSq+zN/NfX0BjZD nVaGX4zw0XgLoEj7BqRvYhukGZASzpAnvqDmCiMF9qgaugrM3wPWuvvMfxiYH0w+a9 5WH72WLiDLW65ZsOrWV6PBoj5d3Y2fiV8pbvO0FQ9FPvzpFIQYDKEUQBEpsDreKw3D i1v+OF22au2VQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 3/8] iio: adc: ab8500-gpadc: Use device_for_each_child_node_scoped() to simplify erorr paths. Date: Sat, 30 Mar 2024 19:08:44 +0000 Message-ID: <20240330190849.1321065-4-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 This new loop definition automatically releases the handle on early exit reducing the chance of bugs that cause resource leaks. Cc: Linus Walleij Signed-off-by: Jonathan Cameron Reviewed-by: Linus Walleij --- drivers/iio/adc/ab8500-gpadc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iio/adc/ab8500-gpadc.c b/drivers/iio/adc/ab8500-gpadc.c index 0bc1550c7f11..59f66e9cb0e8 100644 --- a/drivers/iio/adc/ab8500-gpadc.c +++ b/drivers/iio/adc/ab8500-gpadc.c @@ -1028,7 +1028,6 @@ static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, struct iio_chan_spec **chans_parsed, unsigned int *nchans_parsed) { - struct fwnode_handle *child; struct ab8500_gpadc_chan_info *ch; struct iio_chan_spec *iio_chans; unsigned int nchans; @@ -1052,7 +1051,7 @@ static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, return -ENOMEM; i = 0; - device_for_each_child_node(gpadc->dev, child) { + device_for_each_child_node_scoped(gpadc->dev, child) { struct iio_chan_spec *iio_chan; int ret; @@ -1062,7 +1061,6 @@ static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, ret = ab8500_gpadc_parse_channel(gpadc->dev, child, ch, iio_chan); if (ret) { - fwnode_handle_put(child); return ret; } i++; From patchwork Sat Mar 30 19:08:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611662 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 CB9D5200D9 for ; Sat, 30 Mar 2024 19:09:16 +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=1711825756; cv=none; b=BO547/XrSWdN3ns1ZAQsQfM3GBNWj34NfMM23eJYJwWSV+JCZQvsZWJzKUdnnJ1OEYJ7QgYf4vC7t4s7wO1Zwxqpqs32EW71c3Loh6f0LDemVzoHafBCR9BfcF2ct5m8wdX7xwjkGMImKiXnik9c3w7Tsy6mVTHwZXRAO0go1XY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825756; c=relaxed/simple; bh=9VhaaU0wBIDEiUet4doMfR7XyJ63UDMd34J1DY1qlDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uX/zeljF334Yx3MW0gAYka5ytCiUrZ5Sj3u2g9KuifQNijn4czCWlEZTSCsNnTmPd9jGg0IGCINrYS0d5L0lqBI7ILl+lRuUzrW014sVrMdCtxOhlgADUwlWKcYyLZyMLOFAMrAtblVQ2IJo0qGn61HAYt0adn5GYGOCdzKEBv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K5dZrqqO; 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="K5dZrqqO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A0DC433C7; Sat, 30 Mar 2024 19:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825756; bh=9VhaaU0wBIDEiUet4doMfR7XyJ63UDMd34J1DY1qlDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5dZrqqOH2aHEJa5T2rinI5eVQPK6Z8E8T+KuSRA1SUMG2xZ2I9dAxKdDr1x4vlLt 9Qdo5mp2XjlP2cnA50HzIKCH99wTC5iZUFQVuMbcTyhKV/DuKTsq36CFuVI1Y3NB91 JpeemrF4JrVCHxI+erKqH7eDYTQjtWWIAaNBg8IJG0AShfkVFtjJ8Fy10pvvv0rOXK CfoVAYMn8wT4LXUFIqsuIeL9bcpDC8ZD+zk2ZLoWNY99eBcTArrh+YnltC1iWMSZuW QRa8Pl4ftpi6yVY34Ne3MKSAmsMBe7jKvr14hcm372e7odPaARpDGHlylK9+F5iU3O TCVyRVvLY9SMg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 4/8] iio: adc: ad4130: Use device_for_each_child_node_scoped() to simplify error paths. Date: Sat, 30 Mar 2024 19:08:45 +0000 Message-ID: <20240330190849.1321065-5-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 This loop definition removes the need for manual releasing of the fwnode_handle in early exit paths (here an error path) allow simplfication of the code and reducing the chance of future modificiations not releasing fwnode_handle correctly. Cc: Cosmin Tanislav Cc: Nuno Sa Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad4130.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad4130.c b/drivers/iio/adc/ad4130.c index febb64e67955..aaf1fb0ac447 100644 --- a/drivers/iio/adc/ad4130.c +++ b/drivers/iio/adc/ad4130.c @@ -1600,17 +1600,14 @@ static int ad4130_parse_fw_children(struct iio_dev *indio_dev) { struct ad4130_state *st = iio_priv(indio_dev); struct device *dev = &st->spi->dev; - struct fwnode_handle *child; int ret; indio_dev->channels = st->chans; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { ret = ad4130_parse_fw_channel(indio_dev, child); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } } return 0; From patchwork Sat Mar 30 19:08:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611663 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 3A6B7200D9 for ; Sat, 30 Mar 2024 19:09:19 +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=1711825760; cv=none; b=Gl68EkmUEZxLlzoUVZ5cz5OM3fMBy8De5wtbvaDqwirg+8Yl8+q24BjHyanDEIj4tqhUc6z8y3XE5tqyM+OLGGCzenZSs6SHIWqRBFrdfs3dHNBVZw5PN/Qo1Mqa+tgPzE+bVA3JPQ6gFeZQvX+ssBjMhVnfVbEeffCtnhdoMGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825760; c=relaxed/simple; bh=bDFmcN+PEwQtVnUZbRbjcyvkGVvHlaTDyN9NrX0fpi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VNnyAGI1ty5SI+DgIrquKCXNAkGs/SFPJZkqnaVyD80Vz6U8SRCf8mMd6zYBnMXMHbV5TppqXXgiep6SJHjLs3kvuq1eVjH6BboTaV+AK6jUq/vskdqOpCe8L2WicDj66mmjZi7+UtqUJBSZn/oXNUB9KSFzwDU7gxRKse12Muo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p90SeOCR; 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="p90SeOCR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BFB2C43394; Sat, 30 Mar 2024 19:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825759; bh=bDFmcN+PEwQtVnUZbRbjcyvkGVvHlaTDyN9NrX0fpi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p90SeOCRKa+GQsTbeV/Oqonfrh7Muu6iLiYWoOxc4TL4XhcqyDXueRB2rNX3UmAf7 mPThFlw7FL6clcLNUhshW7e/c1s9FDS0hoY/AQo4pxMJ52wv0mvS9+3hU2VimcHcJg 14FXlxJwsmsuQJxDh5RYhRU3HSGirqAIRCav0h7E8ksvnaDHXiPlvgttDArmYS+/st SEp7p6fjEYHL/d4JDD31xT6qcMVOd2wXbtgE+t/sQqWxIe0KDGKl+nToDicgF1gIuX RslrlOWP01M7lNw+gGJn2ZKYkm/8PE6UGKRBnwpMvz1l2+W1ljbb+ztpr48VstHpWL 9bsdy1eKNs5uw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 5/8] iio: adc: ad7173: Use device_for_each_child_node_scoped() to simplify error paths. Date: Sat, 30 Mar 2024 19:08:46 +0000 Message-ID: <20240330190849.1321065-6-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 This loop definition automatically releases the fwnode_handle on early exit such as the error cases seen here. This reducing boilerplate and the chance of a resource leak being introduced in future. Cc: Dumitru Ceclan Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ad7173.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c index 4ff6ce46b02c..f6d29abe1d04 100644 --- a/drivers/iio/adc/ad7173.c +++ b/drivers/iio/adc/ad7173.c @@ -910,7 +910,6 @@ 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; - struct fwnode_handle *child; int ref_sel, ret; chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), @@ -940,23 +939,19 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) chan_index++; } - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { chan = &chan_arr[chan_index]; chan_st_priv = &chans_st_arr[chan_index]; ret = fwnode_property_read_u32_array(child, "diff-channels", ain, ARRAY_SIZE(ain)); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } if (ain[0] >= st->info->num_inputs || - ain[1] >= st->info->num_inputs) { - fwnode_handle_put(child); + ain[1] >= st->info->num_inputs) return dev_err_probe(dev, -EINVAL, "Input pin number out of range for pair (%d %d).\n", ain[0], ain[1]); - } ret = fwnode_property_match_property_string(child, "adi,reference-select", @@ -968,24 +963,19 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) ref_sel = ret; if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && - !st->info->has_int_ref) { - fwnode_handle_put(child); + !st->info->has_int_ref) return dev_err_probe(dev, -EINVAL, "Internal reference is not available on current model.\n"); - } - if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) { - fwnode_handle_put(child); + if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) return dev_err_probe(dev, -EINVAL, "External reference 2 is not available on current model.\n"); - } ret = ad7173_get_ref_voltage_milli(st, ref_sel); - if (ret < 0) { - fwnode_handle_put(child); + if (ret < 0) return dev_err_probe(dev, ret, "Cannot use reference %u\n", ref_sel); - } + if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF) st->adc_mode |= AD7173_ADC_MODE_REF_EN; chan_st_priv->cfg.ref_sel = ref_sel; From patchwork Sat Mar 30 19:08:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611664 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 F358F200D9 for ; Sat, 30 Mar 2024 19:09:23 +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=1711825764; cv=none; b=JzIVw6ggqSvfDeRyT7zojWVsRkj9uJql1DErWNhm7M1fivVamLBcUOHl8hyoMBgCioRD0Xw1Kxu0YSmPqC1bsUwZRKfU9M82zmGfGYSgT8nZLjVwv9MRpNPW/9DQBTbViw7X0NsZeaMq7r/5PEcup/mZUhqx0EvMT1sYJzzu70Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825764; c=relaxed/simple; bh=CAkeo+GKk3RatumWU31CHPHEyLJ87H39Sk1V9uNQku4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nxf1O2k8duzsuiO9C3IMiiIewLS41fQQX5zp0MXmt08UExuStpBXJPToovck9PT38LD492Vk8WKir+2QYUZjLgInPU3pTB2EsrbSKC1GXNYofT1zjvw+Dk8f045IwaLOl8ODu9AIsiiibIEyDQPjjaAzNcnZIKYm1q5TMwvPtkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qx2W28Zw; 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="Qx2W28Zw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E3CC43390; Sat, 30 Mar 2024 19:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825763; bh=CAkeo+GKk3RatumWU31CHPHEyLJ87H39Sk1V9uNQku4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qx2W28ZwSf+NdI0lgxPF2eOW/c4EsIsgMAKA6oSyvtuUwSrq2Ieln2XxrGtRiEl25 E+UFh+d96/glc07dFLCZPONt6LuqYyKrQMm1R6R6Aw+crWl/kIDIxL7wl5tG6icqGi lJGbz//wbflETpCldcCzzRmjCOR36lPi2xIevy0fV2p8vD0ReArtqMdLEUwXrS8GQ9 80QGZk0uvrsAhGBvUXUuqA7Z9lhVRAQ8c5CMDZNGW8Lffh8QMNeNUds33G1WmQMh9v qYlQTHGek/b7QukJt91M/QYOu0W8dn0ixtgLov5+Ca5qkffJpQA0AMqSY8Bo3ybTpb VzzvEcVjl0eqQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 6/8] iio: frequency: admfm2000: Use device_for_each_child_node_scoped() to simplify error paths. Date: Sat, 30 Mar 2024 19:08:47 +0000 Message-ID: <20240330190849.1321065-7-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 This loop definition automatically release the fwnode_handle on early exit simplifying error handling paths. Cc: Kim Seer Paller Signed-off-by: Jonathan Cameron --- drivers/iio/frequency/admfm2000.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/iio/frequency/admfm2000.c b/drivers/iio/frequency/admfm2000.c index c34d79e55a7c..b2263b9afeda 100644 --- a/drivers/iio/frequency/admfm2000.c +++ b/drivers/iio/frequency/admfm2000.c @@ -160,26 +160,21 @@ static int admfm2000_channel_config(struct admfm2000_state *st, { struct platform_device *pdev = to_platform_device(indio_dev->dev.parent); struct device *dev = &pdev->dev; - struct fwnode_handle *child; struct gpio_desc **dsa; struct gpio_desc **sw; int ret, i; bool mode; u32 reg; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - fwnode_handle_put(child); + if (ret) return dev_err_probe(dev, ret, "Failed to get reg property\n"); - } - if (reg >= indio_dev->num_channels) { - fwnode_handle_put(child); + if (reg >= indio_dev->num_channels) return dev_err_probe(dev, -EINVAL, "reg bigger than: %d\n", indio_dev->num_channels); - } if (fwnode_property_present(child, "adi,mixer-mode")) mode = ADMFM2000_MIXER_MODE; @@ -196,36 +191,29 @@ static int admfm2000_channel_config(struct admfm2000_state *st, dsa = st->dsa2_gpios; break; default: - fwnode_handle_put(child); return -EINVAL; } for (i = 0; i < ADMFM2000_MODE_GPIOS; i++) { sw[i] = devm_fwnode_gpiod_get_index(dev, child, "switch", i, GPIOD_OUT_LOW, NULL); - if (IS_ERR(sw[i])) { - fwnode_handle_put(child); + if (IS_ERR(sw[i])) return dev_err_probe(dev, PTR_ERR(sw[i]), "Failed to get gpios\n"); - } } for (i = 0; i < ADMFM2000_DSA_GPIOS; i++) { dsa[i] = devm_fwnode_gpiod_get_index(dev, child, "attenuation", i, GPIOD_OUT_LOW, NULL); - if (IS_ERR(dsa[i])) { - fwnode_handle_put(child); + if (IS_ERR(dsa[i])) return dev_err_probe(dev, PTR_ERR(dsa[i]), "Failed to get gpios\n"); - } } ret = admfm2000_mode(indio_dev, reg, mode); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } } return 0; From patchwork Sat Mar 30 19:08:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611665 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 85E4B200D9 for ; Sat, 30 Mar 2024 19:09:27 +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=1711825767; cv=none; b=rl+92ybSo7T2fXUMOT36XEBRtXuNHLmpi23TapahRy/r+FBnzeUbbQe57iYwZ8x2rsrVxOiKrJTmmfjJqapo4GPP86Ge8dfl1+dPRS0KssDbrF/CKVeulcJxjP17xlb2B5Cmxx2zawyB2xKlABKAx9KF4F48kPQyn3LQPCyY+Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825767; c=relaxed/simple; bh=qf+vFt4eHBKb9wC1ML+JrZeUlBlFfrqpC/PNsmXCNhc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4vGKihNJiN3qcrCD7oXN2xZwGHjh1vIxnyWUJMqYa9GV9dwhOqwFLKwHDQitXmxDE2kTn21AUUhhcor00Wv5VqaUUkeJ3kok0h/S8PT5CyDbkTQtiA90dKN7UYWTiqyxkt4LRCrFXRCUyYw5uHIoEQ9zqsMD2/rRoWED6M/o88= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uo9RHRe4; 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="uo9RHRe4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64283C433F1; Sat, 30 Mar 2024 19:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825767; bh=qf+vFt4eHBKb9wC1ML+JrZeUlBlFfrqpC/PNsmXCNhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uo9RHRe4DIrrcBYYkXjFVCXY9HnZki/b3Wu4w9depCOHFFim0Hbsy3KIDikSqbBSQ gDsZNhwZKpuaiCQ6CBoBgAvx9XXuR9QnY19AS+NOYrDNN3oPbWlE/U1g6hfSkw+ZHf gZiW71YEw+LNYQezyvE0PMib0KhmNTy2I4XAH997vDFfGYjduYBcz0NJSoa23RVG8J 6o3Gh0GPmAMmJ4mNTFjjh1EcO1ujOEBAmES2k2mDBifeA0E4d4nBKo9nMPRa+TSXZG SPQmgf9UxdRC62ftSYJwNg6izFruGuHN0DwjyZW/edyIQ6uyM2oUe58Mm4+/R87y5i oGk4TK+HhfGEA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 7/8] iio: dac: ad3552: Use __free(fwnode_handle) to simplify error handling. Date: Sat, 30 Mar 2024 19:08:48 +0000 Message-ID: <20240330190849.1321065-8-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 By using this scoped based cleanup direct returns on errors are enabled simplifying the code. Cc: Mihail Chindris Cc: Marcelo Schmitt Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad3552r.c | 59 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index e14a065b29ca..8aa942896b5b 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -801,51 +801,45 @@ static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, u32 ch) { struct device *dev = &dac->spi->dev; - struct fwnode_handle *gain_child; u32 val; int err; u8 addr; u16 reg = 0, offset; - gain_child = fwnode_get_named_child_node(child, - "custom-output-range-config"); - if (!gain_child) { - dev_err(dev, - "mandatory custom-output-range-config property missing\n"); - return -EINVAL; - } + struct fwnode_handle *gain_child __free(fwnode_handle) + = fwnode_get_named_child_node(child, + "custom-output-range-config"); + if (!gain_child) + return dev_err_probe(dev, -EINVAL, + "mandatory custom-output-range-config property missing\n"); dac->ch_data[ch].range_override = 1; reg |= ad3552r_field_prep(1, AD3552R_MASK_CH_RANGE_OVERRIDE); err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); - if (err) { - dev_err(dev, "mandatory adi,gain-scaling-p property missing\n"); - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory adi,gain-scaling-p property missing\n"); reg |= ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_P); dac->ch_data[ch].p = val; err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); - if (err) { - dev_err(dev, "mandatory adi,gain-scaling-n property missing\n"); - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory adi,gain-scaling-n property missing\n"); reg |= ad3552r_field_prep(val, AD3552R_MASK_CH_GAIN_SCALING_N); dac->ch_data[ch].n = val; err = fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); - if (err) { - dev_err(dev, "mandatory adi,rfb-ohms property missing\n"); - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory adi,rfb-ohms property missing\n"); dac->ch_data[ch].rfb = val; err = fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); - if (err) { - dev_err(dev, "mandatory adi,gain-offset property missing\n"); - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory adi,gain-offset property missing\n"); dac->ch_data[ch].gain_offset = val; offset = abs((s32)val); @@ -855,21 +849,14 @@ static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, addr = AD3552R_REG_ADDR_CH_GAIN(ch); err = ad3552r_write_reg(dac, addr, offset & AD3552R_MASK_CH_OFFSET_BITS_0_7); - if (err) { - dev_err(dev, "Error writing register\n"); - goto put_child; - } + if (err) + return dev_err_probe(dev, err, "Error writing register\n"); err = ad3552r_write_reg(dac, addr, reg); - if (err) { - dev_err(dev, "Error writing register\n"); - goto put_child; - } - -put_child: - fwnode_handle_put(gain_child); + if (err) + return dev_err_probe(dev, err, "Error writing register\n"); - return err; + return 0; } static void ad3552r_reg_disable(void *reg) From patchwork Sat Mar 30 19:08:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611666 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 3C5AA200D9 for ; Sat, 30 Mar 2024 19:09:30 +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=1711825771; cv=none; b=dx5spUV9yEq0XSfnnQqtvvBg8sk6jS/gXqJulpLjGUAPM93NvKe2Gh+ovRXb1XEc1toqkv9p+CEjwFzRl/7hfg7KLEJwQxKUQ1lWsTNnxX9H4hGF7E4NbsFyxsqdvXkO79InjhWUAOCFvFGdL0NbX7h36uZ+xVHijb8KHqL7Y7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711825771; c=relaxed/simple; bh=zO1Fm8arirm596tju5FVU2TBB6HGajHMgVL9jq1CBWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TbK7QImdIzgd/dBIB6AcRTpO1MJ05bAWvSs+cOJ9crJV/e0cMfv3SvFaA70SerBOElnfLZbbpIsBY0Zx8lw8Pi6MkXfXsx8x9bFXpXoVhJxCGKPRW2ofl2/5Zj3JcPxVU4OWTlXoo0MDgJKqpeoy1MafASBljU8jlwiKRwDJWHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k05ELnRy; 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="k05ELnRy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18B89C433F1; Sat, 30 Mar 2024 19:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711825770; bh=zO1Fm8arirm596tju5FVU2TBB6HGajHMgVL9jq1CBWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k05ELnRyYMDjukwGoEfJN4m9k+/elgh44O7nr8JqTmex4I4L34h41B0937KH/zKe2 feCIqShs81L1x+Omu8xSns9kxp6agbvjtrfgB3OG3Wmnpa2q9JU8kpND/RF+tZvfjB GCrVNmVfmk6MaVfzy1MNLhAqd0nDdYku/YekcobfFkBMoarVw42MHfto7YoOsrDuhs pLpB49G5VXJGcsg/7yBzGStO/0SS0AT/TTScyPYTA6IwMs/aCVRb6JFKV3fZQS/ZPw Hebjx+Rk17IIlKuIN37bw2/1Baav8wqi5Vnd7pJokdOLK/xbp4B0/Id9swi0tcMStU 3S7QUV6kmJvBA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Marius Cristea , Mihail Chindris , Marcelo Schmitt , Kim Seer Paller , Dumitru Ceclan , Cosmin Tanislav , Nuno Sa , Linus Walleij , Jonathan Cameron Subject: [PATCH 8/8] iio: adc: pac1934: Use device_for_each_available_child_node_scoped() to simplify error handling. Date: Sat, 30 Mar 2024 19:08:49 +0000 Message-ID: <20240330190849.1321065-9-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org> References: <20240330190849.1321065-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 Also change both firmware parsing functions to return meaningful errors. Whilst for the ACPI case this isn't that useful, for the generic fwnode case we can return the errors coming from the property parsing instead of just whether we succeeded or not. Cc: Marius Cristea Signed-off-by: Jonathan Cameron --- drivers/iio/adc/pac1934.c | 77 ++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c index e0c2742da523..f751260605e4 100644 --- a/drivers/iio/adc/pac1934.c +++ b/drivers/iio/adc/pac1934.c @@ -1079,8 +1079,8 @@ static int pac1934_chip_identify(struct pac1934_chip_info *info) * documentation related to the ACPI device definition * https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ApplicationNotes/ApplicationNotes/PAC1934-Integration-Notes-for-Microsoft-Windows-10-and-Windows-11-Driver-Support-DS00002534.pdf */ -static bool pac1934_acpi_parse_channel_config(struct i2c_client *client, - struct pac1934_chip_info *info) +static int pac1934_acpi_parse_channel_config(struct i2c_client *client, + struct pac1934_chip_info *info) { acpi_handle handle; union acpi_object *rez; @@ -1095,7 +1095,7 @@ static bool pac1934_acpi_parse_channel_config(struct i2c_client *client, rez = acpi_evaluate_dsm(handle, &guid, 0, PAC1934_ACPI_GET_NAMES_AND_MOHMS_VALS, NULL); if (!rez) - return false; + return -EINVAL; for (i = 0; i < rez->package.count; i += 2) { idx = i / 2; @@ -1118,7 +1118,7 @@ static bool pac1934_acpi_parse_channel_config(struct i2c_client *client, * and assign the default sampling rate */ info->sample_rate_value = PAC1934_DEFAULT_CHIP_SAMP_SPEED_HZ; - return true; + return 0; } for (i = 0; i < rez->package.count; i++) { @@ -1131,7 +1131,7 @@ static bool pac1934_acpi_parse_channel_config(struct i2c_client *client, rez = acpi_evaluate_dsm(handle, &guid, 1, PAC1934_ACPI_GET_BIPOLAR_SETTINGS, NULL); if (!rez) - return false; + return -EINVAL; bi_dir_mask = rez->package.elements[0].integer.value; info->bi_dir[0] = ((bi_dir_mask & (1 << 3)) | (bi_dir_mask & (1 << 7))) != 0; @@ -1143,19 +1143,18 @@ static bool pac1934_acpi_parse_channel_config(struct i2c_client *client, rez = acpi_evaluate_dsm(handle, &guid, 1, PAC1934_ACPI_GET_SAMP, NULL); if (!rez) - return false; + return -EINVAL; info->sample_rate_value = rez->package.elements[0].integer.value; ACPI_FREE(rez); - return true; + return 0; } -static bool pac1934_of_parse_channel_config(struct i2c_client *client, - struct pac1934_chip_info *info) +static int pac1934_fw_parse_channel_config(struct i2c_client *client, + struct pac1934_chip_info *info) { - struct fwnode_handle *node, *fwnode; struct device *dev = &client->dev; unsigned int current_channel; int idx, ret; @@ -1163,46 +1162,38 @@ static bool pac1934_of_parse_channel_config(struct i2c_client *client, info->sample_rate_value = 1024; current_channel = 1; - fwnode = dev_fwnode(dev); - fwnode_for_each_available_child_node(fwnode, node) { + device_for_each_child_node_scoped(dev, node) { ret = fwnode_property_read_u32(node, "reg", &idx); - if (ret) { - dev_err_probe(dev, ret, - "reading invalid channel index\n"); - goto err_fwnode; - } + if (ret) + return dev_err_probe(dev, ret, + "reading invalid channel index\n"); + /* adjust idx to match channel index (1 to 4) from the datasheet */ idx--; if (current_channel >= (info->phys_channels + 1) || - idx >= info->phys_channels || idx < 0) { - dev_err_probe(dev, -EINVAL, - "%s: invalid channel_index %d value\n", - fwnode_get_name(node), idx); - goto err_fwnode; - } + idx >= info->phys_channels || idx < 0) + return dev_err_probe(dev, -EINVAL, + "%s: invalid channel_index %d value\n", + fwnode_get_name(node), idx); /* enable channel */ info->active_channels[idx] = true; ret = fwnode_property_read_u32(node, "shunt-resistor-micro-ohms", &info->shunts[idx]); - if (ret) { - dev_err_probe(dev, ret, - "%s: invalid shunt-resistor value: %d\n", - fwnode_get_name(node), info->shunts[idx]); - goto err_fwnode; - } + if (ret) + return dev_err_probe(dev, ret, + "%s: invalid shunt-resistor value: %d\n", + fwnode_get_name(node), info->shunts[idx]); if (fwnode_property_present(node, "label")) { ret = fwnode_property_read_string(node, "label", (const char **)&info->labels[idx]); - if (ret) { - dev_err_probe(dev, ret, - "%s: invalid rail-name value\n", - fwnode_get_name(node)); - goto err_fwnode; - } + if (ret) + return dev_err_probe(dev, ret, + "%s: invalid rail-name value\n", + fwnode_get_name(node)); } info->bi_dir[idx] = fwnode_property_read_bool(node, "bipolar"); @@ -1210,12 +1201,7 @@ static bool pac1934_of_parse_channel_config(struct i2c_client *client, current_channel++; } - return true; - -err_fwnode: - fwnode_handle_put(node); - - return false; + return 0; } static void pac1934_cancel_delayed_work(void *dwork) @@ -1485,7 +1471,6 @@ static int pac1934_probe(struct i2c_client *client) const struct pac1934_features *chip; struct iio_dev *indio_dev; int cnt, ret; - bool match = false; struct device *dev = &client->dev; indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); @@ -1519,16 +1504,16 @@ static int pac1934_probe(struct i2c_client *client) } if (acpi_match_device(dev->driver->acpi_match_table, dev)) - match = pac1934_acpi_parse_channel_config(client, info); + ret = pac1934_acpi_parse_channel_config(client, info); else /* * This makes it possible to use also ACPI PRP0001 for * registering the device using device tree properties. */ - match = pac1934_of_parse_channel_config(client, info); + ret = pac1934_fw_parse_channel_config(client, info); - if (!match) - return dev_err_probe(dev, -EINVAL, + if (ret) + return dev_err_probe(dev, ret, "parameter parsing returned an error\n"); mutex_init(&info->lock);