From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 9DF317C for ; Fri, 10 Jun 2022 08:48:37 +0000 (UTC) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25A7noCg005281; Fri, 10 Jun 2022 04:48:12 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3ghq33kqa1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 04:48:11 -0400 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 25A8mAvx023276 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Jun 2022 04:48:10 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Fri, 10 Jun 2022 04:48:09 -0400 Received: from nsa.ad.analog.com ([10.44.3.70]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 25A8imij014275; Fri, 10 Jun 2022 04:47:57 -0400 From: =?UTF-8?q?Nuno=20S=C3=A1?= To: , , , , , Lad Prabhakar , , , , , CC: Cai Huoqing , Benjamin Fair , Jishnu Prakash , "Linus Walleij" , Lars-Peter Clausen , Alexandre Torgue , Amit Kucheria , Andy Gross , Michael Hennerich , Haibo Chen , Benson Leung , "Rafael J. Wysocki" , "Alexandre Belloni" , Christophe Branchereau , Patrick Venture , Arnd Bergmann , Nancy Yuen , Sascha Hauer , Daniel Lezcano , "Gwendal Grignou" , Saravanan Sekar , "Tali Perry" , Maxime Coquelin , Paul Cercueil , Thara Gopinath , Avi Fishman , "Lorenzo Bianconi" , Claudiu Beznea , Pengutronix Kernel Team , Andy Shevchenko , Fabrice Gasnier , Matthias Brugger , Tomer Maimon , Bjorn Andersson , "Nicolas Ferre" , Jonathan Cameron , Zhang Rui , Shawn Guo , "Guenter Roeck" , Fabio Estevam , "Olivier Moysan" , Eugen Hristev , Miquel Raynal Subject: [PATCH 23/34] iio: inkern: split of_iio_channel_get_by_name() Date: Fri, 10 Jun 2022 10:45:34 +0200 Message-ID: <20220610084545.547700-24-nuno.sa@analog.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610084545.547700-1-nuno.sa@analog.com> References: <20220610084545.547700-1-nuno.sa@analog.com> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-10_02,2022-06-09_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100031 This change splits of_iio_channel_get_by_name() so that it decouples looking for channels in the current node from looking in it's parents nodes. This will be helpful when moving to fwnode properties where we need to release the handles when looking for channels in parent's nodes. No functional change intended... Signed-off-by: Nuno Sá --- drivers/iio/inkern.c | 69 ++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 31d9c122199a..dde47324b826 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -211,44 +211,63 @@ static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) return ERR_PTR(err); } +struct iio_channel *__of_iio_channel_get_by_name(struct device_node *np, + const char *name, + bool *parent_lookup) +{ + struct iio_channel *chan; + int index = 0; + + /* + * For named iio channels, first look up the name in the + * "io-channel-names" property. If it cannot be found, the + * index will be an error code, and of_iio_channel_get() + * will fail. + */ + if (name) + index = of_property_match_string(np, "io-channel-names", name); + + chan = of_iio_channel_get(np, index); + if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) { + *parent_lookup = false; + } else if (name && index >= 0) { + pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", + np, name ? name : "", index); + *parent_lookup = false; + } + + return chan; +} + struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, const char *name) { struct iio_channel *chan; + bool parent_lookup = true; /* Walk up the tree of devices looking for a matching iio channel */ + chan = __of_iio_channel_get_by_name(np, name, &parent_lookup); + if (!parent_lookup) + return chan; + + /* + * No matching IIO channel found on this node. + * If the parent node has a "io-channel-ranges" property, + * then we can try one of its channels. + */ + np = np->parent; while (np) { - int index = 0; - - /* - * For named iio channels, first look up the name in the - * "io-channel-names" property. If it cannot be found, the - * index will be an error code, and of_iio_channel_get() - * will fail. - */ - if (name) - index = of_property_match_string(np, "io-channel-names", - name); - chan = of_iio_channel_get(np, index); - if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) + if (!of_get_property(np, "io-channel-ranges", NULL)) return chan; - if (name && index >= 0) { - pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", - np, name ? name : "", index); + + chan = __of_iio_channel_get_by_name(np, name, &parent_lookup); + if (!parent_lookup) return chan; - } - /* - * No matching IIO channel found on this node. - * If the parent node has a "io-channel-ranges" property, - * then we can try one of its channels. - */ np = np->parent; - if (np && !of_get_property(np, "io-channel-ranges", NULL)) - return chan; } - return ERR_PTR(-ENODEV); + return chan; } EXPORT_SYMBOL_GPL(of_iio_channel_get_by_name); -- 2.36.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0232FC433EF for ; Fri, 10 Jun 2022 08:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iW581kA+4KCFd9Sx7UBwSFWVW6vEYrBE/LQ81BvIbkI=; b=yJ28VSJ0eRSrNu gRGwOo+dx4KhIQsfxJKbtNdA5HW6YPuq37MJjuc9EauxdsPpHxVYjrO3UURsaBkq7wo+f0cgbxJUU vLpDpIWgkuV04U2SF/K7MdCbgcPMVwXtusSR3zegw+si3qU332rM4aWD5Phc8NUkb/RNq9kIDD2P1 nScUSNsCPwbkbUfpRJjse5XeW/1cHMX+RtiNWaO278rUO7X/2Debui/39MriIQJWxGZJsMf+o3Z8m iK+IUPv7/1RFHZE2tTifKQYGwEIznaRifHcivRNPBQz9wZm1RoK04igxzIO/Z7Yrx4i6RzN+MOcMF PFA23tiylsM3H/KSTDSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzaJq-006uiF-Ji; Fri, 10 Jun 2022 08:48:38 +0000 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzaJn-006ugO-OP; Fri, 10 Jun 2022 08:48:37 +0000 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25A7noCg005281; Fri, 10 Jun 2022 04:48:12 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3ghq33kqa1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 04:48:11 -0400 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 25A8mAvx023276 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Jun 2022 04:48:10 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Fri, 10 Jun 2022 04:48:09 -0400 Received: from nsa.ad.analog.com ([10.44.3.70]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 25A8imij014275; Fri, 10 Jun 2022 04:47:57 -0400 From: =?UTF-8?q?Nuno=20S=C3=A1?= To: , , , , , Lad Prabhakar , , , , , CC: Cai Huoqing , Benjamin Fair , Jishnu Prakash , "Linus Walleij" , Lars-Peter Clausen , Alexandre Torgue , Amit Kucheria , Andy Gross , Michael Hennerich , Haibo Chen , Benson Leung , "Rafael J. Wysocki" , "Alexandre Belloni" , Christophe Branchereau , Patrick Venture , Arnd Bergmann , Nancy Yuen , Sascha Hauer , Daniel Lezcano , "Gwendal Grignou" , Saravanan Sekar , "Tali Perry" , Maxime Coquelin , Paul Cercueil , Thara Gopinath , Avi Fishman , "Lorenzo Bianconi" , Claudiu Beznea , Pengutronix Kernel Team , Andy Shevchenko , Fabrice Gasnier , Matthias Brugger , Tomer Maimon , Bjorn Andersson , "Nicolas Ferre" , Jonathan Cameron , Zhang Rui , Shawn Guo , "Guenter Roeck" , Fabio Estevam , "Olivier Moysan" , Eugen Hristev , Miquel Raynal Subject: [PATCH 23/34] iio: inkern: split of_iio_channel_get_by_name() Date: Fri, 10 Jun 2022 10:45:34 +0200 Message-ID: <20220610084545.547700-24-nuno.sa@analog.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610084545.547700-1-nuno.sa@analog.com> References: <20220610084545.547700-1-nuno.sa@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-10_02,2022-06-09_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100031 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_014835_825523_AF51C1E2 X-CRM114-Status: GOOD ( 18.37 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org VGhpcyBjaGFuZ2Ugc3BsaXRzIG9mX2lpb19jaGFubmVsX2dldF9ieV9uYW1lKCkgc28gdGhhdCBp dCBkZWNvdXBsZXMKbG9va2luZyBmb3IgY2hhbm5lbHMgaW4gdGhlIGN1cnJlbnQgbm9kZSBmcm9t IGxvb2tpbmcgaW4gaXQncyBwYXJlbnRzCm5vZGVzLiBUaGlzIHdpbGwgYmUgaGVscGZ1bCB3aGVu IG1vdmluZyB0byBmd25vZGUgcHJvcGVydGllcyB3aGVyZSB3ZQpuZ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oYW5uZWwgJXBPRjolcyglaSlcbiIsCi0JCQkJbnAs IG5hbWUgPyBuYW1lIDogIiIsIGluZGV4KTsKKworCQljaGFuID0gX19vZl9paW9fY2hhbm5lbF9n ZXRfYnlfbmFtZShucCwgbmFtZSwgJnBhcmVudF9sb29rdXApOworCQlpZiAoIXBhcmVudF9sb29r dXApCiAJCQlyZXR1cm4gY2hhbjsKLQkJfQogCi0JCS8qCi0JCSAqIE5vIG1hdGNoaW5nIElJTyBj aGFubmVsIGZvdW5kIG9uIHRoaXMgbm9kZS4KLQkJICogSWYgdGhlIHBhcmVudCBub2RlIGhhcyBh ICJpby1jaGFubmVsLXJhbmdlcyIgcHJvcGVydHksCi0JCSAqIHRoZW4gd2UgY2FuIHRyeSBvbmUg b2YgaXRzIGNoYW5uZWxzLgotCQkgKi8KIAkJbnAgPSBucC0+cGFyZW50OwotCQlpZiAobnAgJiYg IW9mX2dldF9wcm9wZXJ0eShucCwgImlvLWNoYW5uZWwtcmFuZ2VzIiwgTlVMTCkpCi0JCQlyZXR1 cm4gY2hhbjsKIAl9CiAKLQlyZXR1cm4gRVJSX1BUUigtRU5PREVWKTsKKwlyZXR1cm4gY2hhbjsK IH0KIEVYUE9SVF9TWU1CT0xfR1BMKG9mX2lpb19jaGFubmVsX2dldF9ieV9uYW1lKTsKIAotLSAK Mi4zNi4xCgoKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18K TGludXgtbWVkaWF0ZWsgbWFpbGluZyBsaXN0CkxpbnV4LW1lZGlhdGVrQGxpc3RzLmluZnJhZGVh ZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVhZC5vcmcvbWFpbG1hbi9saXN0aW5mby9saW51eC1t ZWRpYXRlawo= From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEAB6C43334 for ; Thu, 16 Jun 2022 02:12:54 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LNm0j2LzHz3dsc for ; Thu, 16 Jun 2022 12:12:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=analog.com (client-ip=148.163.135.77; helo=mx0a-00128a01.pphosted.com; envelope-from=nuno.sa@analog.com; receiver=) Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LKF490gfzz3brb for ; Fri, 10 Jun 2022 18:48:40 +1000 (AEST) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25A7noCg005281; Fri, 10 Jun 2022 04:48:12 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3ghq33kqa1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 04:48:11 -0400 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 25A8mAvx023276 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Jun 2022 04:48:10 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 10 Jun 2022 04:48:09 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Fri, 10 Jun 2022 04:48:09 -0400 Received: from nsa.ad.analog.com ([10.44.3.70]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 25A8imij014275; Fri, 10 Jun 2022 04:47:57 -0400 From: =?UTF-8?q?Nuno=20S=C3=A1?= To: , , , , , Lad Prabhakar , , , , , Subject: [PATCH 23/34] iio: inkern: split of_iio_channel_get_by_name() Date: Fri, 10 Jun 2022 10:45:34 +0200 Message-ID: <20220610084545.547700-24-nuno.sa@analog.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610084545.547700-1-nuno.sa@analog.com> References: <20220610084545.547700-1-nuno.sa@analog.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-GUID: 2oH5KYMbOhj-Glg6FwhCeBTGAwA2tiGz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-10_02,2022-06-09_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 spamscore=0 impostorscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100031 X-Mailman-Approved-At: Thu, 16 Jun 2022 12:05:36 +1000 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Daniel Lezcano , Tomer Maimon , "Rafael J. Wysocki" , Linus Walleij , Amit Kucheria , Alexandre Torgue , Tali Perry , Paul Cercueil , Miquel Raynal , Guenter Roeck , Fabio Estevam , Lars-Peter Clausen , Benjamin Fair , Jishnu Prakash , Haibo Chen , Andy Shevchenko , Andy Gross , Olivier Moysan , Zhang Rui , Christophe Branchereau , Saravanan Sekar , Michael Hennerich , Sascha Hauer , Fabrice Gasnier , Cai Huoqing , Matthias Brugger , Gwendal Grignou , Bjorn Andersson , Benson Leung , Pengutronix Kernel Team , Lorenzo Bianconi , Avi Fishman , Patrick Venture , Nicolas Ferre , Thara Gopinath , Arnd Bergmann , Maxime Coquelin , Eugen Hristev , Shawn Guo , Claudiu Beznea , Jonathan Cameron Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" This change splits of_iio_channel_get_by_name() so that it decouples looking for channels in the current node from looking in it's parents nodes. This will be helpful when moving to fwnode properties where we need to release the handles when looking for channels in parent's nodes. No functional change intended... Signed-off-by: Nuno Sá --- drivers/iio/inkern.c | 69 ++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 31d9c122199a..dde47324b826 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -211,44 +211,63 @@ static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) return ERR_PTR(err); } +struct iio_channel *__of_iio_channel_get_by_name(struct device_node *np, + const char *name, + bool *parent_lookup) +{ + struct iio_channel *chan; + int index = 0; + + /* + * For named iio channels, first look up the name in the + * "io-channel-names" property. If it cannot be found, the + * index will be an error code, and of_iio_channel_get() + * will fail. + */ + if (name) + index = of_property_match_string(np, "io-channel-names", name); + + chan = of_iio_channel_get(np, index); + if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) { + *parent_lookup = false; + } else if (name && index >= 0) { + pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", + np, name ? name : "", index); + *parent_lookup = false; + } + + return chan; +} + struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, const char *name) { struct iio_channel *chan; + bool parent_lookup = true; /* Walk up the tree of devices looking for a matching iio channel */ + chan = __of_iio_channel_get_by_name(np, name, &parent_lookup); + if (!parent_lookup) + return chan; + + /* + * No matching IIO channel found on this node. + * If the parent node has a "io-channel-ranges" property, + * then we can try one of its channels. + */ + np = np->parent; while (np) { - int index = 0; - - /* - * For named iio channels, first look up the name in the - * "io-channel-names" property. If it cannot be found, the - * index will be an error code, and of_iio_channel_get() - * will fail. - */ - if (name) - index = of_property_match_string(np, "io-channel-names", - name); - chan = of_iio_channel_get(np, index); - if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) + if (!of_get_property(np, "io-channel-ranges", NULL)) return chan; - if (name && index >= 0) { - pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n", - np, name ? name : "", index); + + chan = __of_iio_channel_get_by_name(np, name, &parent_lookup); + if (!parent_lookup) return chan; - } - /* - * No matching IIO channel found on this node. - * If the parent node has a "io-channel-ranges" property, - * then we can try one of its channels. - */ np = np->parent; - if (np && !of_get_property(np, "io-channel-ranges", NULL)) - return chan; } - return ERR_PTR(-ENODEV); + return chan; } EXPORT_SYMBOL_GPL(of_iio_channel_get_by_name); -- 2.36.1