[{"id":34662,"web_url":"https://patchwork.libcamera.org/comment/34662/","msgid":"<20250626131027.GP8738@pendragon.ideasonboard.com>","date":"2025-06-26T13:10:27","subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Dan,\n\nThank you for the patch.\n\nOn Wed, Jun 25, 2025 at 04:53:07PM +0100, Daniel Scally wrote:\n> Some entities in a media graph have names that might differ from\n> implementation to implementation; for example the Camera Receiver\n> Unit and CSI-2 receiver on the KakiP board have entities with names\n> that include their address, in the form \"csi-16000400.csi2\". Passing\n> that entity name to DeviceMatch is too inflexible given it would only\n> work if that specific CSI-2 receiver were the one being used.\n> \n> Update DeviceMatch.add() such that the string passed to it is used to\n> create a std::basic_regex, and use std::regex_search() instead of a\n> direct string comparison in DeviceMatch::match(). This allows us to\n> pass a string that will form a regex expression to match to the entity\n> instead, for example \"csi-[0-9]{8}.csi2\".\n\nSo you'll only support SoCs whose CSI-2 receiver are mapped to an\naddress that contains no alphabetic digits ? :-)\n\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n>  .../libcamera/internal/device_enumerator.h    |  3 ++-\n>  src/libcamera/device_enumerator.cpp           | 27 ++++++++++---------\n>  2 files changed, 16 insertions(+), 14 deletions(-)\n> \n> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> index db3532a9..fce7f0ea 100644\n> --- a/include/libcamera/internal/device_enumerator.h\n> +++ b/include/libcamera/internal/device_enumerator.h\n> @@ -8,6 +8,7 @@\n>  #pragma once\n>  \n>  #include <memory>\n> +#include <regex>\n\nSee commit b01918978c82 (\"libcamera: v4l2_subdevice: Work around false\npositive warning\").\n\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -28,7 +29,7 @@ public:\n>  \n>  private:\n>  \tstd::string driver_;\n> -\tstd::vector<std::string> entities_;\n> +\tstd::vector<std::regex> entities_;\n>  };\n>  \n>  class DeviceEnumerator\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index ae17862f..e22d2822 100644\n> --- a/src/libcamera/device_enumerator.cpp\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n>   * device enumerator to find matching media devices.\n>   *\n>   * A DeviceMatch is created with a specific Linux device driver in mind,\n> - * therefore the name of the driver is a required property. One or more Entity\n> - * names can be added as match criteria.\n> + * therefore the name of the driver is a required property. Regex expressions to\n> + * match one or more Entity names can be added as match criteria.\n>   *\n> - * Pipeline handlers are recommended to add entities to DeviceMatch as\n> - * appropriate to ensure that the media device they need can be uniquely\n> - * identified. This is useful when the corresponding kernel driver can produce\n> - * different graphs, for instance as a result of different driver versions or\n> - * hardware configurations, and not all those graphs are suitable for a pipeline\n> - * handler.\n> + * Pipeline handlers are recommended to add regex expressions for entities to\n> + * DeviceMatch as appropriate to ensure that the media device they need can be\n> + * uniquely identified. This is useful when the corresponding kernel driver can\n> + * produce different graphs, for instance as a result of different driver\n> + * versions or hardware configurations, and not all those graphs are suitable\n> + * for a pipeline handler.\n>   */\n>  \n>  /**\n> @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver)\n>  }\n>  \n>  /**\n> - * \\brief Add a media entity name to the search pattern\n> - * \\param[in] entity The name of the entity in the media graph\n> + * \\brief Add a media entity regex string to the search pattern\n> + * \\param[in] entity A regex string to match the entity in the media graph\n>   */\n>  void DeviceMatch::add(const std::string &entity)\n>  {\n> -\tentities_.push_back(entity);\n> +\tstd::regex entity_regex(entity);\n\ncamelCase. Same below.\n\n> +\tentities_.push_back(entity_regex);\n\nConstruct in-place with emplace_back, don't use a local variable.\n\n>  }\n>  \n>  /**\n> @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const\n>  \tif (driver_ != device->driver())\n>  \t\treturn false;\n>  \n> -\tfor (const std::string &name : entities_) {\n> +\tfor (const std::regex &name_regex : entities_) {\n>  \t\tbool found = false;\n>  \n>  \t\tfor (const MediaEntity *entity : device->entities()) {\n> -\t\t\tif (name == entity->name()) {\n> +\t\t\tif (std::regex_search(entity->name(), name_regex)) {\n>  \t\t\t\tif (!entity->deviceNode().empty()) {\n>  \t\t\t\t\tfound = true;\n>  \t\t\t\t\tbreak;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BBEE1BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Jun 2025 13:10:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2067868DF9;\n\tThu, 26 Jun 2025 15:10:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8702C68DE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jun 2025 15:10:52 +0200 (CEST)","from pendragon.ideasonboard.com (85-76-34-12-nat.elisa-mobile.fi\n\t[85.76.34.12])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 1455F6AE;\n\tThu, 26 Jun 2025 15:10:32 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KK/T8KD3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750943433;\n\tbh=KTakngmyn3ueks8V95Fh0EgFoWJloH2f3XINVVSBzDs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=KK/T8KD336BJq4lMsSrchAXyBIs6co4enCxTqKcTl5yQwF79EtsHdsOg07+E3JSy2\n\tFVKEDaQ2XjChyD7U/Qe0GWvy8DtoVrEBcwPCCd8xZa54XHTuO4FONjMavS4ZZLTrX3\n\tjC0I15aerus9TF3yX/giOyusF7dEWf4SzqXrHF1E=","Date":"Thu, 26 Jun 2025 16:10:27 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","Message-ID":"<20250626131027.GP8738@pendragon.ideasonboard.com>","References":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>\n\t<20250625155308.2325438-2-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250625155308.2325438-2-dan.scally@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34663,"web_url":"https://patchwork.libcamera.org/comment/34663/","msgid":"<20250626131122.GQ8738@pendragon.ideasonboard.com>","date":"2025-06-26T13:11:22","subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Jun 26, 2025 at 04:10:31PM +0300, Laurent Pinchart wrote:\n> Hi Dan,\n> \n> Thank you for the patch.\n> \n> On Wed, Jun 25, 2025 at 04:53:07PM +0100, Daniel Scally wrote:\n> > Some entities in a media graph have names that might differ from\n> > implementation to implementation; for example the Camera Receiver\n> > Unit and CSI-2 receiver on the KakiP board have entities with names\n> > that include their address, in the form \"csi-16000400.csi2\". Passing\n> > that entity name to DeviceMatch is too inflexible given it would only\n> > work if that specific CSI-2 receiver were the one being used.\n> > \n> > Update DeviceMatch.add() such that the string passed to it is used to\n> > create a std::basic_regex, and use std::regex_search() instead of a\n> > direct string comparison in DeviceMatch::match(). This allows us to\n> > pass a string that will form a regex expression to match to the entity\n> > instead, for example \"csi-[0-9]{8}.csi2\".\n> \n> So you'll only support SoCs whose CSI-2 receiver are mapped to an\n> address that contains no alphabetic digits ? :-)\n\nAlso note that the '.' in the regex can now match any character. Do we\nneed to update all users of DeviceMatch to escape '.' ?\n\n> > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> > ---\n> >  .../libcamera/internal/device_enumerator.h    |  3 ++-\n> >  src/libcamera/device_enumerator.cpp           | 27 ++++++++++---------\n> >  2 files changed, 16 insertions(+), 14 deletions(-)\n> > \n> > diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> > index db3532a9..fce7f0ea 100644\n> > --- a/include/libcamera/internal/device_enumerator.h\n> > +++ b/include/libcamera/internal/device_enumerator.h\n> > @@ -8,6 +8,7 @@\n> >  #pragma once\n> >  \n> >  #include <memory>\n> > +#include <regex>\n> \n> See commit b01918978c82 (\"libcamera: v4l2_subdevice: Work around false\n> positive warning\").\n> \n> >  #include <string>\n> >  #include <vector>\n> >  \n> > @@ -28,7 +29,7 @@ public:\n> >  \n> >  private:\n> >  \tstd::string driver_;\n> > -\tstd::vector<std::string> entities_;\n> > +\tstd::vector<std::regex> entities_;\n> >  };\n> >  \n> >  class DeviceEnumerator\n> > diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> > index ae17862f..e22d2822 100644\n> > --- a/src/libcamera/device_enumerator.cpp\n> > +++ b/src/libcamera/device_enumerator.cpp\n> > @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n> >   * device enumerator to find matching media devices.\n> >   *\n> >   * A DeviceMatch is created with a specific Linux device driver in mind,\n> > - * therefore the name of the driver is a required property. One or more Entity\n> > - * names can be added as match criteria.\n> > + * therefore the name of the driver is a required property. Regex expressions to\n> > + * match one or more Entity names can be added as match criteria.\n> >   *\n> > - * Pipeline handlers are recommended to add entities to DeviceMatch as\n> > - * appropriate to ensure that the media device they need can be uniquely\n> > - * identified. This is useful when the corresponding kernel driver can produce\n> > - * different graphs, for instance as a result of different driver versions or\n> > - * hardware configurations, and not all those graphs are suitable for a pipeline\n> > - * handler.\n> > + * Pipeline handlers are recommended to add regex expressions for entities to\n> > + * DeviceMatch as appropriate to ensure that the media device they need can be\n> > + * uniquely identified. This is useful when the corresponding kernel driver can\n> > + * produce different graphs, for instance as a result of different driver\n> > + * versions or hardware configurations, and not all those graphs are suitable\n> > + * for a pipeline handler.\n> >   */\n> >  \n> >  /**\n> > @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver)\n> >  }\n> >  \n> >  /**\n> > - * \\brief Add a media entity name to the search pattern\n> > - * \\param[in] entity The name of the entity in the media graph\n> > + * \\brief Add a media entity regex string to the search pattern\n> > + * \\param[in] entity A regex string to match the entity in the media graph\n> >   */\n> >  void DeviceMatch::add(const std::string &entity)\n> >  {\n> > -\tentities_.push_back(entity);\n> > +\tstd::regex entity_regex(entity);\n> \n> camelCase. Same below.\n> \n> > +\tentities_.push_back(entity_regex);\n> \n> Construct in-place with emplace_back, don't use a local variable.\n> \n> >  }\n> >  \n> >  /**\n> > @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const\n> >  \tif (driver_ != device->driver())\n> >  \t\treturn false;\n> >  \n> > -\tfor (const std::string &name : entities_) {\n> > +\tfor (const std::regex &name_regex : entities_) {\n> >  \t\tbool found = false;\n> >  \n> >  \t\tfor (const MediaEntity *entity : device->entities()) {\n> > -\t\t\tif (name == entity->name()) {\n> > +\t\t\tif (std::regex_search(entity->name(), name_regex)) {\n> >  \t\t\t\tif (!entity->deviceNode().empty()) {\n> >  \t\t\t\t\tfound = true;\n> >  \t\t\t\t\tbreak;\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3414ABDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Jun 2025 13:11:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CF20168DF6;\n\tThu, 26 Jun 2025 15:11:46 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E4B2A68DE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jun 2025 15:11:45 +0200 (CEST)","from pendragon.ideasonboard.com (85-76-34-12-nat.elisa-mobile.fi\n\t[85.76.34.12])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id EDAD76AE;\n\tThu, 26 Jun 2025 15:11:26 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"U4u1CddP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750943487;\n\tbh=1YlXQHtHh0pPgvcDJcNKoeiEhCsgAHImzN4HwVEuTvQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=U4u1CddPTaQksxgGbwF/WcmLHR6+36iPpxFedKQE6YFQ0y6w0q2+YqB/ZwhWpFDV5\n\ter0AnrZN7wNVxxYtUhFf9kZxXxJ/9lDWnvC5pVCWMPpbzLjZUjF4uPFjH1R9CN5yXN\n\tLibdIt9w4Vf6IpMFKKuYEOSRVMqjCIeCOqev/coY=","Date":"Thu, 26 Jun 2025 16:11:22 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","Message-ID":"<20250626131122.GQ8738@pendragon.ideasonboard.com>","References":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>\n\t<20250625155308.2325438-2-dan.scally@ideasonboard.com>\n\t<20250626131027.GP8738@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250626131027.GP8738@pendragon.ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34665,"web_url":"https://patchwork.libcamera.org/comment/34665/","msgid":"<474b7e67-6208-47a8-9821-979f5060c43f@ideasonboard.com>","date":"2025-06-26T13:26:29","subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Laurent\n\nOn 26/06/2025 14:10, Laurent Pinchart wrote:\n> Hi Dan,\n>\n> Thank you for the patch.\n>\n> On Wed, Jun 25, 2025 at 04:53:07PM +0100, Daniel Scally wrote:\n>> Some entities in a media graph have names that might differ from\n>> implementation to implementation; for example the Camera Receiver\n>> Unit and CSI-2 receiver on the KakiP board have entities with names\n>> that include their address, in the form \"csi-16000400.csi2\". Passing\n>> that entity name to DeviceMatch is too inflexible given it would only\n>> work if that specific CSI-2 receiver were the one being used.\n>>\n>> Update DeviceMatch.add() such that the string passed to it is used to\n>> create a std::basic_regex, and use std::regex_search() instead of a\n>> direct string comparison in DeviceMatch::match(). This allows us to\n>> pass a string that will form a regex expression to match to the entity\n>> instead, for example \"csi-[0-9]{8}.csi2\".\n> So you'll only support SoCs whose CSI-2 receiver are mapped to an\n> address that contains no alphabetic digits ? :-)\n\n\nOh yeah...erm, \"csi-[0-9a-fA-F]{8}.csi2\" then?\n\n>\n>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n>> ---\n>>   .../libcamera/internal/device_enumerator.h    |  3 ++-\n>>   src/libcamera/device_enumerator.cpp           | 27 ++++++++++---------\n>>   2 files changed, 16 insertions(+), 14 deletions(-)\n>>\n>> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n>> index db3532a9..fce7f0ea 100644\n>> --- a/include/libcamera/internal/device_enumerator.h\n>> +++ b/include/libcamera/internal/device_enumerator.h\n>> @@ -8,6 +8,7 @@\n>>   #pragma once\n>>   \n>>   #include <memory>\n>> +#include <regex>\n> See commit b01918978c82 (\"libcamera: v4l2_subdevice: Work around false\n> positive warning\").\n\n\nOoh. OK...I guess it's time for a wrapper then...do you mean in your commit message comment that we \nought to create a libcamera::regex class that wraps the std class, with that #pragma guarding the \ninclude in the source file?\n\n>\n>>   #include <string>\n>>   #include <vector>\n>>   \n>> @@ -28,7 +29,7 @@ public:\n>>   \n>>   private:\n>>   \tstd::string driver_;\n>> -\tstd::vector<std::string> entities_;\n>> +\tstd::vector<std::regex> entities_;\n>>   };\n>>   \n>>   class DeviceEnumerator\n>> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n>> index ae17862f..e22d2822 100644\n>> --- a/src/libcamera/device_enumerator.cpp\n>> +++ b/src/libcamera/device_enumerator.cpp\n>> @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n>>    * device enumerator to find matching media devices.\n>>    *\n>>    * A DeviceMatch is created with a specific Linux device driver in mind,\n>> - * therefore the name of the driver is a required property. One or more Entity\n>> - * names can be added as match criteria.\n>> + * therefore the name of the driver is a required property. Regex expressions to\n>> + * match one or more Entity names can be added as match criteria.\n>>    *\n>> - * Pipeline handlers are recommended to add entities to DeviceMatch as\n>> - * appropriate to ensure that the media device they need can be uniquely\n>> - * identified. This is useful when the corresponding kernel driver can produce\n>> - * different graphs, for instance as a result of different driver versions or\n>> - * hardware configurations, and not all those graphs are suitable for a pipeline\n>> - * handler.\n>> + * Pipeline handlers are recommended to add regex expressions for entities to\n>> + * DeviceMatch as appropriate to ensure that the media device they need can be\n>> + * uniquely identified. This is useful when the corresponding kernel driver can\n>> + * produce different graphs, for instance as a result of different driver\n>> + * versions or hardware configurations, and not all those graphs are suitable\n>> + * for a pipeline handler.\n>>    */\n>>   \n>>   /**\n>> @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver)\n>>   }\n>>   \n>>   /**\n>> - * \\brief Add a media entity name to the search pattern\n>> - * \\param[in] entity The name of the entity in the media graph\n>> + * \\brief Add a media entity regex string to the search pattern\n>> + * \\param[in] entity A regex string to match the entity in the media graph\n>>    */\n>>   void DeviceMatch::add(const std::string &entity)\n>>   {\n>> -\tentities_.push_back(entity);\n>> +\tstd::regex entity_regex(entity);\n> camelCase. Same below.\n>\n>> +\tentities_.push_back(entity_regex);\n> Construct in-place with emplace_back, don't use a local variable.\n>\n>>   }\n>>   \n>>   /**\n>> @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const\n>>   \tif (driver_ != device->driver())\n>>   \t\treturn false;\n>>   \n>> -\tfor (const std::string &name : entities_) {\n>> +\tfor (const std::regex &name_regex : entities_) {\n>>   \t\tbool found = false;\n>>   \n>>   \t\tfor (const MediaEntity *entity : device->entities()) {\n>> -\t\t\tif (name == entity->name()) {\n>> +\t\t\tif (std::regex_search(entity->name(), name_regex)) {\n>>   \t\t\t\tif (!entity->deviceNode().empty()) {\n>>   \t\t\t\t\tfound = true;\n>>   \t\t\t\t\tbreak;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 73CE8BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Jun 2025 13:26:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D9C4268DF6;\n\tThu, 26 Jun 2025 15:26:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9335768DE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jun 2025 15:26:32 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6AFD1833;\n\tThu, 26 Jun 2025 15:26:13 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VEPwR1uT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750944373;\n\tbh=CSKB8NQzMW+/v4EwJqbfaw6DSWyUfGuwtSiYTVUE3dU=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=VEPwR1uTjDVXGxV53+5KyBeYl7B6Sx5cvVPuQpTbdaG/8E/GeD42YLpMf8KL/wCrk\n\tpdCzg7+SFvNQdPaFCrQ1DXcWXZAfeMyqM2Ghh1i2+t2LcNYf81nLzZEb2ap/VgkpAA\n\tKIRJ60lgWl4thgqPEHBCoDCJXmkF+23WTOhBCuPQ=","Message-ID":"<474b7e67-6208-47a8-9821-979f5060c43f@ideasonboard.com>","Date":"Thu, 26 Jun 2025 14:26:29 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>\n\t<20250625155308.2325438-2-dan.scally@ideasonboard.com>\n\t<20250626131027.GP8738@pendragon.ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideas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ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34667,"web_url":"https://patchwork.libcamera.org/comment/34667/","msgid":"<20250626133008.GS8738@pendragon.ideasonboard.com>","date":"2025-06-26T13:30:08","subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Jun 26, 2025 at 02:26:29PM +0100, Daniel Scally wrote:\n> On 26/06/2025 14:10, Laurent Pinchart wrote:\n> > On Wed, Jun 25, 2025 at 04:53:07PM +0100, Daniel Scally wrote:\n> >> Some entities in a media graph have names that might differ from\n> >> implementation to implementation; for example the Camera Receiver\n> >> Unit and CSI-2 receiver on the KakiP board have entities with names\n> >> that include their address, in the form \"csi-16000400.csi2\". Passing\n> >> that entity name to DeviceMatch is too inflexible given it would only\n> >> work if that specific CSI-2 receiver were the one being used.\n> >>\n> >> Update DeviceMatch.add() such that the string passed to it is used to\n> >> create a std::basic_regex, and use std::regex_search() instead of a\n> >> direct string comparison in DeviceMatch::match(). This allows us to\n> >> pass a string that will form a regex expression to match to the entity\n> >> instead, for example \"csi-[0-9]{8}.csi2\".\n> >\n> > So you'll only support SoCs whose CSI-2 receiver are mapped to an\n> > address that contains no alphabetic digits ? :-)\n> \n> Oh yeah...erm, \"csi-[0-9a-fA-F]{8}.csi2\" then?\n\nI would have hoped the kernel would only use lowercase hex values.\n\n> >> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> >> ---\n> >>   .../libcamera/internal/device_enumerator.h    |  3 ++-\n> >>   src/libcamera/device_enumerator.cpp           | 27 ++++++++++---------\n> >>   2 files changed, 16 insertions(+), 14 deletions(-)\n> >>\n> >> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> >> index db3532a9..fce7f0ea 100644\n> >> --- a/include/libcamera/internal/device_enumerator.h\n> >> +++ b/include/libcamera/internal/device_enumerator.h\n> >> @@ -8,6 +8,7 @@\n> >>   #pragma once\n> >>   \n> >>   #include <memory>\n> >> +#include <regex>\n> >\n> > See commit b01918978c82 (\"libcamera: v4l2_subdevice: Work around false\n> > positive warning\").\n> \n> Ooh. OK...I guess it's time for a wrapper then...do you mean in your commit message comment that we \n> ought to create a libcamera::regex class that wraps the std class, with that #pragma guarding the \n> include in the source file?\n\nI think a libcamera/base/regex.h file that wraps regex is enough, no\nneed for a class.\n\n> >>   #include <string>\n> >>   #include <vector>\n> >>   \n> >> @@ -28,7 +29,7 @@ public:\n> >>   \n> >>   private:\n> >>   \tstd::string driver_;\n> >> -\tstd::vector<std::string> entities_;\n> >> +\tstd::vector<std::regex> entities_;\n> >>   };\n> >>   \n> >>   class DeviceEnumerator\n> >> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> >> index ae17862f..e22d2822 100644\n> >> --- a/src/libcamera/device_enumerator.cpp\n> >> +++ b/src/libcamera/device_enumerator.cpp\n> >> @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n> >>    * device enumerator to find matching media devices.\n> >>    *\n> >>    * A DeviceMatch is created with a specific Linux device driver in mind,\n> >> - * therefore the name of the driver is a required property. One or more Entity\n> >> - * names can be added as match criteria.\n> >> + * therefore the name of the driver is a required property. Regex expressions to\n> >> + * match one or more Entity names can be added as match criteria.\n> >>    *\n> >> - * Pipeline handlers are recommended to add entities to DeviceMatch as\n> >> - * appropriate to ensure that the media device they need can be uniquely\n> >> - * identified. This is useful when the corresponding kernel driver can produce\n> >> - * different graphs, for instance as a result of different driver versions or\n> >> - * hardware configurations, and not all those graphs are suitable for a pipeline\n> >> - * handler.\n> >> + * Pipeline handlers are recommended to add regex expressions for entities to\n> >> + * DeviceMatch as appropriate to ensure that the media device they need can be\n> >> + * uniquely identified. This is useful when the corresponding kernel driver can\n> >> + * produce different graphs, for instance as a result of different driver\n> >> + * versions or hardware configurations, and not all those graphs are suitable\n> >> + * for a pipeline handler.\n> >>    */\n> >>   \n> >>   /**\n> >> @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver)\n> >>   }\n> >>   \n> >>   /**\n> >> - * \\brief Add a media entity name to the search pattern\n> >> - * \\param[in] entity The name of the entity in the media graph\n> >> + * \\brief Add a media entity regex string to the search pattern\n> >> + * \\param[in] entity A regex string to match the entity in the media graph\n> >>    */\n> >>   void DeviceMatch::add(const std::string &entity)\n> >>   {\n> >> -\tentities_.push_back(entity);\n> >> +\tstd::regex entity_regex(entity);\n> >\n> > camelCase. Same below.\n> >\n> >> +\tentities_.push_back(entity_regex);\n> >\n> > Construct in-place with emplace_back, don't use a local variable.\n> >\n> >>   }\n> >>   \n> >>   /**\n> >> @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const\n> >>   \tif (driver_ != device->driver())\n> >>   \t\treturn false;\n> >>   \n> >> -\tfor (const std::string &name : entities_) {\n> >> +\tfor (const std::regex &name_regex : entities_) {\n> >>   \t\tbool found = false;\n> >>   \n> >>   \t\tfor (const MediaEntity *entity : device->entities()) {\n> >> -\t\t\tif (name == entity->name()) {\n> >> +\t\t\tif (std::regex_search(entity->name(), name_regex)) {\n> >>   \t\t\t\tif (!entity->deviceNode().empty()) {\n> >>   \t\t\t\t\tfound = true;\n> >>   \t\t\t\t\tbreak;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 501EAC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Jun 2025 13:30:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 043C268DF6;\n\tThu, 26 Jun 2025 15:30:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3590868DE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Jun 2025 15:30:32 +0200 (CEST)","from pendragon.ideasonboard.com (85-76-34-12-nat.elisa-mobile.fi\n\t[85.76.34.12])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 1A971833;\n\tThu, 26 Jun 2025 15:30:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Meks3ZCp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750944613;\n\tbh=EwuiAJmer36Yi0LBvo/aoXOQGiYlZQLKj/k/OdfqR24=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Meks3ZCpVhw2FcWrxfvL4Oo5iGSLITa93UjI43VQLy4ClAAWEm9wgjyTkWtn2GpC5\n\tWoQDr9FPx1eHKRObJKJLPaFa2YSshiKTfNkX0cQhmz/EJT2OvXDRV8aw9RBqWQ5Sk/\n\tai6jHi1l+1SjsqAARiGUvgo+L46DqRr7jEFTQ/8Q=","Date":"Thu, 26 Jun 2025 16:30:08 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Dan Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","Message-ID":"<20250626133008.GS8738@pendragon.ideasonboard.com>","References":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>\n\t<20250625155308.2325438-2-dan.scally@ideasonboard.com>\n\t<20250626131027.GP8738@pendragon.ideasonboard.com>\n\t<474b7e67-6208-47a8-9821-979f5060c43f@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<474b7e67-6208-47a8-9821-979f5060c43f@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34903,"web_url":"https://patchwork.libcamera.org/comment/34903/","msgid":"<4b7a1d6f-5f65-455d-baa9-3c87f4a196db@ideasonboard.com>","date":"2025-07-15T14:17:48","subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Laurent\n\nOn 26/06/2025 14:11, Laurent Pinchart wrote:\n> On Thu, Jun 26, 2025 at 04:10:31PM +0300, Laurent Pinchart wrote:\n>> Hi Dan,\n>>\n>> Thank you for the patch.\n>>\n>> On Wed, Jun 25, 2025 at 04:53:07PM +0100, Daniel Scally wrote:\n>>> Some entities in a media graph have names that might differ from\n>>> implementation to implementation; for example the Camera Receiver\n>>> Unit and CSI-2 receiver on the KakiP board have entities with names\n>>> that include their address, in the form \"csi-16000400.csi2\". Passing\n>>> that entity name to DeviceMatch is too inflexible given it would only\n>>> work if that specific CSI-2 receiver were the one being used.\n>>>\n>>> Update DeviceMatch.add() such that the string passed to it is used to\n>>> create a std::basic_regex, and use std::regex_search() instead of a\n>>> direct string comparison in DeviceMatch::match(). This allows us to\n>>> pass a string that will form a regex expression to match to the entity\n>>> instead, for example \"csi-[0-9]{8}.csi2\".\n>> So you'll only support SoCs whose CSI-2 receiver are mapped to an\n>> address that contains no alphabetic digits ? :-)\n> Also note that the '.' in the regex can now match any character. Do we\n> need to update all users of DeviceMatch to escape '.' ?\n\n\nAh; damn, of course it does...that's horrible. In that case I think we can either update all the \nusers or else extend this change to differentiate between an exact match method and a regex match \nmethod - I think that that's probably the better approach.\n\n>\n>>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n>>> ---\n>>>   .../libcamera/internal/device_enumerator.h    |  3 ++-\n>>>   src/libcamera/device_enumerator.cpp           | 27 ++++++++++---------\n>>>   2 files changed, 16 insertions(+), 14 deletions(-)\n>>>\n>>> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n>>> index db3532a9..fce7f0ea 100644\n>>> --- a/include/libcamera/internal/device_enumerator.h\n>>> +++ b/include/libcamera/internal/device_enumerator.h\n>>> @@ -8,6 +8,7 @@\n>>>   #pragma once\n>>>   \n>>>   #include <memory>\n>>> +#include <regex>\n>> See commit b01918978c82 (\"libcamera: v4l2_subdevice: Work around false\n>> positive warning\").\n>>\n>>>   #include <string>\n>>>   #include <vector>\n>>>   \n>>> @@ -28,7 +29,7 @@ public:\n>>>   \n>>>   private:\n>>>   \tstd::string driver_;\n>>> -\tstd::vector<std::string> entities_;\n>>> +\tstd::vector<std::regex> entities_;\n>>>   };\n>>>   \n>>>   class DeviceEnumerator\n>>> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n>>> index ae17862f..e22d2822 100644\n>>> --- a/src/libcamera/device_enumerator.cpp\n>>> +++ b/src/libcamera/device_enumerator.cpp\n>>> @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n>>>    * device enumerator to find matching media devices.\n>>>    *\n>>>    * A DeviceMatch is created with a specific Linux device driver in mind,\n>>> - * therefore the name of the driver is a required property. One or more Entity\n>>> - * names can be added as match criteria.\n>>> + * therefore the name of the driver is a required property. Regex expressions to\n>>> + * match one or more Entity names can be added as match criteria.\n>>>    *\n>>> - * Pipeline handlers are recommended to add entities to DeviceMatch as\n>>> - * appropriate to ensure that the media device they need can be uniquely\n>>> - * identified. This is useful when the corresponding kernel driver can produce\n>>> - * different graphs, for instance as a result of different driver versions or\n>>> - * hardware configurations, and not all those graphs are suitable for a pipeline\n>>> - * handler.\n>>> + * Pipeline handlers are recommended to add regex expressions for entities to\n>>> + * DeviceMatch as appropriate to ensure that the media device they need can be\n>>> + * uniquely identified. This is useful when the corresponding kernel driver can\n>>> + * produce different graphs, for instance as a result of different driver\n>>> + * versions or hardware configurations, and not all those graphs are suitable\n>>> + * for a pipeline handler.\n>>>    */\n>>>   \n>>>   /**\n>>> @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver)\n>>>   }\n>>>   \n>>>   /**\n>>> - * \\brief Add a media entity name to the search pattern\n>>> - * \\param[in] entity The name of the entity in the media graph\n>>> + * \\brief Add a media entity regex string to the search pattern\n>>> + * \\param[in] entity A regex string to match the entity in the media graph\n>>>    */\n>>>   void DeviceMatch::add(const std::string &entity)\n>>>   {\n>>> -\tentities_.push_back(entity);\n>>> +\tstd::regex entity_regex(entity);\n>> camelCase. Same below.\n>>\n>>> +\tentities_.push_back(entity_regex);\n>> Construct in-place with emplace_back, don't use a local variable.\n>>\n>>>   }\n>>>   \n>>>   /**\n>>> @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const\n>>>   \tif (driver_ != device->driver())\n>>>   \t\treturn false;\n>>>   \n>>> -\tfor (const std::string &name : entities_) {\n>>> +\tfor (const std::regex &name_regex : entities_) {\n>>>   \t\tbool found = false;\n>>>   \n>>>   \t\tfor (const MediaEntity *entity : device->entities()) {\n>>> -\t\t\tif (name == entity->name()) {\n>>> +\t\t\tif (std::regex_search(entity->name(), name_regex)) {\n>>>   \t\t\t\tif (!entity->deviceNode().empty()) {\n>>>   \t\t\t\t\tfound = true;\n>>>   \t\t\t\t\tbreak;\n>> -- \n>> Regards,\n>>\n>> Laurent Pinchart","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 928CCC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 15 Jul 2025 14:17:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7D5606186B;\n\tTue, 15 Jul 2025 16:17:53 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 02A276186B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jul 2025 16:17:51 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E86A78E;\n\tTue, 15 Jul 2025 16:17:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"F1htiLFz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1752589039;\n\tbh=7e0EkacZnBnILR9B4PWR40m73TOLBIV+gm0bKOgwOew=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=F1htiLFzp/gSe3IN/xxUooc3LpIBM6BxHY84xJvWTRW91qfUbbMPFtFiWP+nR5qsM\n\tOx4JHxuQ19xXBG7VDdJPC7WmizkLQtMsYnOoQ/Sy4q74cLzKba8KGhDjhX22D+1Kum\n\tNrwO0kBSikVdCNKwYCLhwJo6GbUYxvcTibsT6TLI=","Message-ID":"<4b7a1d6f-5f65-455d-baa9-3c87f4a196db@ideasonboard.com>","Date":"Tue, 15 Jul 2025 15:17:48 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match\n\tentity names","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>\n\t<20250625155308.2325438-2-dan.scally@ideasonboard.com>\n\t<20250626131027.GP8738@pendragon.ideasonboard.com>\n\t<20250626131122.GQ8738@pendragon.ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideasonboard.com; keydata=\n\txsFNBGLydlEBEADa5O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-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]