From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: Re: [for-upstream/dovetail 1/2] drivers/gpio: core: introduce helper to find array of gpiochips References: <20210513010238.32466-1-hongzhan.chen@intel.com> <20210513010238.32466-2-hongzhan.chen@intel.com> From: Florian Bezdeka Message-ID: Date: Fri, 14 May 2021 10:55:35 +0200 In-Reply-To: <20210513010238.32466-2-hongzhan.chen@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit MIME-Version: 1.0 List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: hongzha1 , xenomai@xenomai.org On 13.05.21 03:02, hongzha1 via Xenomai wrote: > To find array of gpiochips for non-OF platform > > Signed-off-by: hongzha1 > --- > include/cobalt/kernel/rtdm/gpio.h | 4 ++++ > kernel/drivers/gpio/gpio-core.c | 19 +++++++++++++++++++ > 2 files changed, 23 insertions(+) > > diff --git a/include/cobalt/kernel/rtdm/gpio.h b/include/cobalt/kernel/rtdm/gpio.h > index c5fb20f25..99772f558 100644 > --- a/include/cobalt/kernel/rtdm/gpio.h > +++ b/include/cobalt/kernel/rtdm/gpio.h > @@ -64,6 +64,10 @@ int rtdm_gpiochip_post_event(struct rtdm_gpio_chip *rgc, > int rtdm_gpiochip_find(struct device_node *from, > const char *label, int type); > > +int rtdm_gpiochip_array_find(struct device_node *from, > + const char *compat[], > + int nentries, int type); > + > #ifdef CONFIG_OF > > int rtdm_gpiochip_scan_of(struct device_node *from, > diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c > index b3d801fa1..20a6d7875 100644 > --- a/kernel/drivers/gpio/gpio-core.c > +++ b/kernel/drivers/gpio/gpio-core.c > @@ -543,6 +543,25 @@ int rtdm_gpiochip_find(struct device_node *from, const char *label, > } > EXPORT_SYMBOL_GPL(rtdm_gpiochip_find); > > +int rtdm_gpiochip_array_find(struct device_node *from, > + const char *compat[], > + int nentries, int type) > +{ > + int ret = -ENODEV, _ret, n; > + > + for (n = 0; n < nentries; n++) { > + _ret = rtdm_gpiochip_find(from, compat[n], type); > + if (_ret) { > + if (_ret != -ENODEV) > + return _ret; > + } else > + ret = 0; > + } > + > + return ret; > +} I'm not sure if I completely understand the code, but maybe it could be simplified to: { int ret, n; for (n = 0; n < nentries; n++) { ret = rtdm_gpiochip_find(from, compat[n], type); if (ret && ret != -ENODEV) break; } return ret; } > +EXPORT_SYMBOL_GPL(rtdm_gpiochip_array_find); > + > #ifdef CONFIG_OF > > #include > -- Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux