[{"id":4395,"web_url":"https://patchwork.libcamera.org/comment/4395/","msgid":"<20200407202735.GK1716317@oden.dyn.berto.se>","date":"2020-04-07T20:27:35","subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-04-04 04:56:18 +0300, Laurent Pinchart wrote:\n> Create a helper class to handle cleanup of the mapped file to simplify\n> error handling in loadIPAModuleInfo().\n\ns/Create/Use the File/\n\nWit this fixed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nI like some of the usage of tie{} and/or span<> in this patch, I think \nit could be used in cam/qcam to make the mapping of FileDescriptor(s) \nand their caching nicer.\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/ipa_module.cpp | 58 +++++++++++++-----------------------\n>  1 file changed, 21 insertions(+), 37 deletions(-)\n> \n> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\n> index a01d0757ff8f..d1c411e14ba9 100644\n> --- a/src/libcamera/ipa_module.cpp\n> +++ b/src/libcamera/ipa_module.cpp\n> @@ -21,6 +21,7 @@\n>  #include <tuple>\n>  #include <unistd.h>\n>  \n> +#include \"file.h\"\n>  #include \"log.h\"\n>  #include \"pipeline_handler.h\"\n>  #include \"utils.h\"\n> @@ -283,55 +284,38 @@ IPAModule::~IPAModule()\n>  \n>  int IPAModule::loadIPAModuleInfo()\n>  {\n> -\tint fd = open(libPath_.c_str(), O_RDONLY);\n> -\tif (fd < 0) {\n> -\t\tint ret = -errno;\n> +\tFile file{ libPath_ };\n> +\tif (!file.open(File::ReadOnly)) {\n>  \t\tLOG(IPAModule, Error) << \"Failed to open IPA library: \"\n> -\t\t\t\t      << strerror(-ret);\n> -\t\treturn ret;\n> +\t\t\t\t      << strerror(-file.error());\n> +\t\treturn file.error();\n>  \t}\n>  \n> -\tvoid *data = nullptr;\n> -\tsize_t dataSize;\n> -\tvoid *map;\n> -\tsize_t soSize;\n> -\tstruct stat st;\n> -\tint ret = fstat(fd, &st);\n> -\tif (ret < 0)\n> -\t\tgoto close;\n> -\tsoSize = st.st_size;\n> -\tmap = mmap(NULL, soSize, PROT_READ, MAP_PRIVATE, fd, 0);\n> -\tif (map == MAP_FAILED) {\n> -\t\tret = -errno;\n> -\t\tgoto close;\n> +\tSpan<uint8_t> data = file.map(0, -1, File::MapPrivate);\n> +\tint ret = elfVerifyIdent(data.data(), data.size());\n> +\tif (ret) {\n> +\t\tLOG(IPAModule, Error) << \"IPA module is not an ELF file\";\n> +\t\treturn ret;\n>  \t}\n>  \n> -\tret = elfVerifyIdent(map, soSize);\n> -\tif (ret)\n> -\t\tgoto unmap;\n> +\tvoid *info = nullptr;\n> +\tsize_t infoSize;\n>  \n> -\tstd::tie(data, dataSize) = elfLoadSymbol(map, soSize, \"ipaModuleInfo\");\n> -\n> -\tif (data && dataSize == sizeof(info_))\n> -\t\tmemcpy(&info_, data, dataSize);\n> +\tstd::tie(info, infoSize) = elfLoadSymbol(data.data(), data.size(),\n> +\t\t\t\t\t\t \"ipaModuleInfo\");\n> +\tif (!info || infoSize != sizeof(info_)) {\n> +\t\tLOG(IPAModule, Error) << \"IPA module has no valid info\";\n> +\t\treturn -EINVAL;\n> +\t}\n>  \n> -\tif (!data)\n> -\t\tgoto unmap;\n> +\tmemcpy(&info_, info, infoSize);\n>  \n>  \tif (info_.moduleAPIVersion != IPA_MODULE_API_VERSION) {\n>  \t\tLOG(IPAModule, Error) << \"IPA module API version mismatch\";\n> -\t\tret = -EINVAL;\n> +\t\treturn -EINVAL;\n>  \t}\n>  \n> -unmap:\n> -\tmunmap(map, soSize);\n> -close:\n> -\tif (ret || !data)\n> -\t\tLOG(IPAModule, Error)\n> -\t\t\t<< \"Error loading IPA module info for \" << libPath_;\n> -\n> -\tclose(fd);\n> -\treturn ret;\n> +\treturn 0;\n>  }\n>  \n>  /**\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x143.google.com (mail-lf1-x143.google.com\n\t[IPv6:2a00:1450:4864:20::143])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A9045600F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Apr 2020 22:27:37 +0200 (CEST)","by mail-lf1-x143.google.com with SMTP id h6so3465543lfc.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Apr 2020 13:27:37 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\tc22sm13786223lfi.41.2020.04.07.13.27.36\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Apr 2020 13:27:36 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"W46ChWNF\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=dEcXZfc9ejDda82iCIUo+HMxUpdae955bA7aWr/U5qI=;\n\tb=W46ChWNFvEiGfv0sxnTwasBSXoDEYUaFf4BShsdg63CnRCy1pnuh+5Ro/OBCfvAKnm\n\tZKX6LB8vR+cr4hS54N4ZDtK7N2K8HVry9Q+Y3NFaBu9W5YMq3/Qtu1FIn+OThCHBOTm6\n\tcVxBKX18TzM/vNCOTDlSNJh+o6s4XLH+sHQ1u42wZnjVRCOtkBCzMmZAVOZciZcla1Gm\n\tbuxzLWDRWQtbpSx202paNPIcAYF74XRuxfgf7wMzoMFD9zTuUkEdBCKuVSXHQW6WwGJp\n\t6FLdEhjPto2FRCTAKfX9dj+rzhAgLTB2v4HVPzesWQrVKj43VpB5CBELn4OBnM+COXaq\n\trVpA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=dEcXZfc9ejDda82iCIUo+HMxUpdae955bA7aWr/U5qI=;\n\tb=DhtSrh4ZHKCzCSlAMs313aaDWbQyx24PLBuHnxmoByiTDcB1isa3CWcVqfLchzxv1b\n\tRGJggxQTZW1TDc4NPgAHM9J58Ncju6OJUg1Izgi6oldR2lNb9KtaOxi0p3h+wP/UHbEM\n\tK8Svd09itgCBxIW8kPhdTyP55MjPnL00ypfPgzYwhCVNOudNlpEFCx7CK9kl/SkcyOui\n\tABDXqQ1i7h9nwuIUm1JEhpDwte4meSk3aMzywpcNYzRUxnWydnmwgWJ10EhtptOQdJOd\n\tJqGbzubm1lVQunZ4gsfr0wlNgE32le57EeyRu4dWL87NcfZMNHy2deyhI557f/mjpXiG\n\th3ag==","X-Gm-Message-State":"AGi0PubKAIy9Xh0y/IyHwPudwkECdsUFxeDn7EftG+6hmOjWDOJPmR6N\n\t3cWaV726qmvp4340GHcUt3yNKkq8nrs=","X-Google-Smtp-Source":"APiQypKz7hHH/SO5tVV8GEtrZZKBQWTImfe2vPlVhjDqGFEQZw1ANGw6LUSRlpnuefwd+7D64sAZUg==","X-Received":"by 2002:a19:e00b:: with SMTP id\n\tx11mr2449882lfg.147.1586291256875; \n\tTue, 07 Apr 2020 13:27:36 -0700 (PDT)","Date":"Tue, 7 Apr 2020 22:27:35 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407202735.GK1716317@oden.dyn.berto.se>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-6-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200404015624.30440-6-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","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>","X-List-Received-Date":"Tue, 07 Apr 2020 20:27:37 -0000"}},{"id":4408,"web_url":"https://patchwork.libcamera.org/comment/4408/","msgid":"<20200407230729.GM4751@pendragon.ideasonboard.com>","date":"2020-04-07T23:07:29","subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nOn Tue, Apr 07, 2020 at 10:27:35PM +0200, Niklas Söderlund wrote:\n> On 2020-04-04 04:56:18 +0300, Laurent Pinchart wrote:\n> > Create a helper class to handle cleanup of the mapped file to simplify\n> > error handling in loadIPAModuleInfo().\n> \n> s/Create/Use the File/\n\nOops. This patch started with an internal helper class than I then\ndecided to split out to a File class.\n\n> Wit this fixed,\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> I like some of the usage of tie{} and/or span<> in this patch, I think \n> it could be used in cam/qcam to make the mapping of FileDescriptor(s) \n> and their caching nicer.\n\nWe could even expose File in the public API, if it wasn't for the fear\nof growing surface of the public API and having to keep binary\ncompatibility across releases :-S\n\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/ipa_module.cpp | 58 +++++++++++++-----------------------\n> >  1 file changed, 21 insertions(+), 37 deletions(-)\n> > \n> > diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\n> > index a01d0757ff8f..d1c411e14ba9 100644\n> > --- a/src/libcamera/ipa_module.cpp\n> > +++ b/src/libcamera/ipa_module.cpp\n> > @@ -21,6 +21,7 @@\n> >  #include <tuple>\n> >  #include <unistd.h>\n> >  \n> > +#include \"file.h\"\n> >  #include \"log.h\"\n> >  #include \"pipeline_handler.h\"\n> >  #include \"utils.h\"\n> > @@ -283,55 +284,38 @@ IPAModule::~IPAModule()\n> >  \n> >  int IPAModule::loadIPAModuleInfo()\n> >  {\n> > -\tint fd = open(libPath_.c_str(), O_RDONLY);\n> > -\tif (fd < 0) {\n> > -\t\tint ret = -errno;\n> > +\tFile file{ libPath_ };\n> > +\tif (!file.open(File::ReadOnly)) {\n> >  \t\tLOG(IPAModule, Error) << \"Failed to open IPA library: \"\n> > -\t\t\t\t      << strerror(-ret);\n> > -\t\treturn ret;\n> > +\t\t\t\t      << strerror(-file.error());\n> > +\t\treturn file.error();\n> >  \t}\n> >  \n> > -\tvoid *data = nullptr;\n> > -\tsize_t dataSize;\n> > -\tvoid *map;\n> > -\tsize_t soSize;\n> > -\tstruct stat st;\n> > -\tint ret = fstat(fd, &st);\n> > -\tif (ret < 0)\n> > -\t\tgoto close;\n> > -\tsoSize = st.st_size;\n> > -\tmap = mmap(NULL, soSize, PROT_READ, MAP_PRIVATE, fd, 0);\n> > -\tif (map == MAP_FAILED) {\n> > -\t\tret = -errno;\n> > -\t\tgoto close;\n> > +\tSpan<uint8_t> data = file.map(0, -1, File::MapPrivate);\n> > +\tint ret = elfVerifyIdent(data.data(), data.size());\n> > +\tif (ret) {\n> > +\t\tLOG(IPAModule, Error) << \"IPA module is not an ELF file\";\n> > +\t\treturn ret;\n> >  \t}\n> >  \n> > -\tret = elfVerifyIdent(map, soSize);\n> > -\tif (ret)\n> > -\t\tgoto unmap;\n> > +\tvoid *info = nullptr;\n> > +\tsize_t infoSize;\n> >  \n> > -\tstd::tie(data, dataSize) = elfLoadSymbol(map, soSize, \"ipaModuleInfo\");\n> > -\n> > -\tif (data && dataSize == sizeof(info_))\n> > -\t\tmemcpy(&info_, data, dataSize);\n> > +\tstd::tie(info, infoSize) = elfLoadSymbol(data.data(), data.size(),\n> > +\t\t\t\t\t\t \"ipaModuleInfo\");\n> > +\tif (!info || infoSize != sizeof(info_)) {\n> > +\t\tLOG(IPAModule, Error) << \"IPA module has no valid info\";\n> > +\t\treturn -EINVAL;\n> > +\t}\n> >  \n> > -\tif (!data)\n> > -\t\tgoto unmap;\n> > +\tmemcpy(&info_, info, infoSize);\n> >  \n> >  \tif (info_.moduleAPIVersion != IPA_MODULE_API_VERSION) {\n> >  \t\tLOG(IPAModule, Error) << \"IPA module API version mismatch\";\n> > -\t\tret = -EINVAL;\n> > +\t\treturn -EINVAL;\n> >  \t}\n> >  \n> > -unmap:\n> > -\tmunmap(map, soSize);\n> > -close:\n> > -\tif (ret || !data)\n> > -\t\tLOG(IPAModule, Error)\n> > -\t\t\t<< \"Error loading IPA module info for \" << libPath_;\n> > -\n> > -\tclose(fd);\n> > -\treturn ret;\n> > +\treturn 0;\n> >  }\n> >  \n> >  /**","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2167D600F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2020 01:07:39 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 99D0959E;\n\tWed,  8 Apr 2020 01:07:38 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"wgEdnrlN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1586300858;\n\tbh=TGvIgUoE4iBTkGlC/VPwcX8yQBr84nd16ASMcEbnftI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=wgEdnrlNE/1kTYhO90V0gyiEgpYoacQwYrxOgeWQ633gMXV13UrISBPtvCRmyUTy6\n\tE72Y4c9Ofh6VOquqF4FPCVx/b1pRNJYcZASRC2KkUJDYR2NNzyrECEbPV4zTwYrMC/\n\tMqjx8VmaX0Md10zuXTDaW43V3wfbCR2VUwWtAIWo=","Date":"Wed, 8 Apr 2020 02:07:29 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407230729.GM4751@pendragon.ideasonboard.com>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-6-laurent.pinchart@ideasonboard.com>\n\t<20200407202735.GK1716317@oden.dyn.berto.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200407202735.GK1716317@oden.dyn.berto.se>","Subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","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>","X-List-Received-Date":"Tue, 07 Apr 2020 23:07:39 -0000"}},{"id":4410,"web_url":"https://patchwork.libcamera.org/comment/4410/","msgid":"<20200407231216.GA1716317@oden.dyn.berto.se>","date":"2020-04-07T23:12:16","subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nOn 2020-04-08 02:07:29 +0300, Laurent Pinchart wrote:\n> Hi Niklas,\n> \n> On Tue, Apr 07, 2020 at 10:27:35PM +0200, Niklas Söderlund wrote:\n> > On 2020-04-04 04:56:18 +0300, Laurent Pinchart wrote:\n> > > Create a helper class to handle cleanup of the mapped file to simplify\n> > > error handling in loadIPAModuleInfo().\n> > \n> > s/Create/Use the File/\n> \n> Oops. This patch started with an internal helper class than I then\n> decided to split out to a File class.\n> \n> > Wit this fixed,\n> > \n> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > \n> > I like some of the usage of tie{} and/or span<> in this patch, I think \n> > it could be used in cam/qcam to make the mapping of FileDescriptor(s) \n> > and their caching nicer.\n> \n> We could even expose File in the public API, if it wasn't for the fear\n> of growing surface of the public API and having to keep binary\n> compatibility across releases :-S\n\nI agree, I think we should only expose a surface related to cameras ;-) \nFor qcam maybe their is something similar in Qt that can be leveraged.\n\n> \n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  src/libcamera/ipa_module.cpp | 58 +++++++++++++-----------------------\n> > >  1 file changed, 21 insertions(+), 37 deletions(-)\n> > > \n> > > diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp\n> > > index a01d0757ff8f..d1c411e14ba9 100644\n> > > --- a/src/libcamera/ipa_module.cpp\n> > > +++ b/src/libcamera/ipa_module.cpp\n> > > @@ -21,6 +21,7 @@\n> > >  #include <tuple>\n> > >  #include <unistd.h>\n> > >  \n> > > +#include \"file.h\"\n> > >  #include \"log.h\"\n> > >  #include \"pipeline_handler.h\"\n> > >  #include \"utils.h\"\n> > > @@ -283,55 +284,38 @@ IPAModule::~IPAModule()\n> > >  \n> > >  int IPAModule::loadIPAModuleInfo()\n> > >  {\n> > > -\tint fd = open(libPath_.c_str(), O_RDONLY);\n> > > -\tif (fd < 0) {\n> > > -\t\tint ret = -errno;\n> > > +\tFile file{ libPath_ };\n> > > +\tif (!file.open(File::ReadOnly)) {\n> > >  \t\tLOG(IPAModule, Error) << \"Failed to open IPA library: \"\n> > > -\t\t\t\t      << strerror(-ret);\n> > > -\t\treturn ret;\n> > > +\t\t\t\t      << strerror(-file.error());\n> > > +\t\treturn file.error();\n> > >  \t}\n> > >  \n> > > -\tvoid *data = nullptr;\n> > > -\tsize_t dataSize;\n> > > -\tvoid *map;\n> > > -\tsize_t soSize;\n> > > -\tstruct stat st;\n> > > -\tint ret = fstat(fd, &st);\n> > > -\tif (ret < 0)\n> > > -\t\tgoto close;\n> > > -\tsoSize = st.st_size;\n> > > -\tmap = mmap(NULL, soSize, PROT_READ, MAP_PRIVATE, fd, 0);\n> > > -\tif (map == MAP_FAILED) {\n> > > -\t\tret = -errno;\n> > > -\t\tgoto close;\n> > > +\tSpan<uint8_t> data = file.map(0, -1, File::MapPrivate);\n> > > +\tint ret = elfVerifyIdent(data.data(), data.size());\n> > > +\tif (ret) {\n> > > +\t\tLOG(IPAModule, Error) << \"IPA module is not an ELF file\";\n> > > +\t\treturn ret;\n> > >  \t}\n> > >  \n> > > -\tret = elfVerifyIdent(map, soSize);\n> > > -\tif (ret)\n> > > -\t\tgoto unmap;\n> > > +\tvoid *info = nullptr;\n> > > +\tsize_t infoSize;\n> > >  \n> > > -\tstd::tie(data, dataSize) = elfLoadSymbol(map, soSize, \"ipaModuleInfo\");\n> > > -\n> > > -\tif (data && dataSize == sizeof(info_))\n> > > -\t\tmemcpy(&info_, data, dataSize);\n> > > +\tstd::tie(info, infoSize) = elfLoadSymbol(data.data(), data.size(),\n> > > +\t\t\t\t\t\t \"ipaModuleInfo\");\n> > > +\tif (!info || infoSize != sizeof(info_)) {\n> > > +\t\tLOG(IPAModule, Error) << \"IPA module has no valid info\";\n> > > +\t\treturn -EINVAL;\n> > > +\t}\n> > >  \n> > > -\tif (!data)\n> > > -\t\tgoto unmap;\n> > > +\tmemcpy(&info_, info, infoSize);\n> > >  \n> > >  \tif (info_.moduleAPIVersion != IPA_MODULE_API_VERSION) {\n> > >  \t\tLOG(IPAModule, Error) << \"IPA module API version mismatch\";\n> > > -\t\tret = -EINVAL;\n> > > +\t\treturn -EINVAL;\n> > >  \t}\n> > >  \n> > > -unmap:\n> > > -\tmunmap(map, soSize);\n> > > -close:\n> > > -\tif (ret || !data)\n> > > -\t\tLOG(IPAModule, Error)\n> > > -\t\t\t<< \"Error loading IPA module info for \" << libPath_;\n> > > -\n> > > -\tclose(fd);\n> > > -\treturn ret;\n> > > +\treturn 0;\n> > >  }\n> > >  \n> > >  /**\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x242.google.com (mail-lj1-x242.google.com\n\t[IPv6:2a00:1450:4864:20::242])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 66630600F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2020 01:12:18 +0200 (CEST)","by mail-lj1-x242.google.com with SMTP id p10so5638947ljn.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Apr 2020 16:12:18 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\ty29sm12497659ljd.26.2020.04.07.16.12.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Apr 2020 16:12:16 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"X6bOkrJa\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=ZrMh0Xx1NfZ0sarOyrDj5/2mj61LOeS19MQ3UrATRhg=;\n\tb=X6bOkrJayXe/JwS7LxMThZd3EQeuaT2nuoTZOALHZVYSlWbd745mf8ajTX3h7/AQTd\n\t7Sg64w7gP9wf8sbbbyQWoiLjvrdkw6jK2Hzdag8n2qD+AFBK6jctpEYfcIE7NHjTlsjk\n\tQNEoRcdV9I5z5lyfTIC1WZfphcjBxs58glICST1UUkLRjujoBa50VPh2LfC7NbzQAANM\n\txFAUjIFfH8NFzdJYyN8E7BDSP5ROG9EkVDcqYoomCLluCQaTLQ73ZS0WqahqZq0wz6hy\n\tS+CAA6oKuUU37/Z2gYuIRktiOcimOOSA7BhsukUIkCDOPm73p7XxSxhRM8cHZrjxI1hA\n\t05+g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=ZrMh0Xx1NfZ0sarOyrDj5/2mj61LOeS19MQ3UrATRhg=;\n\tb=eYXZEvUQgAYTJmV6WfZWy7pKDvoGLxVzP92eKd33K6ssklJuMSyrO/WEpf7/TmUkFI\n\trU2mQY5aTfkPVBgjZ4UFZJNodF7Uu6APMdixPgPuGAwcXhvfXrcguC5d1ejqp1VJVSEn\n\tGXl84UBRM3KSSFrhbc4cXx5ahJK0vhzPgSUUBLisCSkMWiet/zioEHwsXXmPJ7lb3lsb\n\tkco0Mo/2VUVvHdVndgp17OYQN3U+McOn9DWTKox5kCOLvPGEpXDkMCLZP1O11cFTVu8N\n\tX8yoG+SN++Cb52/BdWzECScpm5RodM1E1cOae54WPHKp6sw06tbf9lF00OhiSA7TtqrQ\n\tzXRg==","X-Gm-Message-State":"AGi0PuYWzffpEY5ErRNSAzjLAVmjN6EILaeGMtXjGOQum+gpxO/bdvja\n\thr1evF5mfTFvgMysf5/nv4/ZQSicOg8=","X-Google-Smtp-Source":"APiQypINFG/szesJNLw+4s92idZDCTuhb0fzXW9Ntz7O2yhySms3NaVxy9NgPYI28VxzC4ipxP+piA==","X-Received":"by 2002:a2e:2415:: with SMTP id k21mr3037011ljk.93.1586301137683;\n\tTue, 07 Apr 2020 16:12:17 -0700 (PDT)","Date":"Wed, 8 Apr 2020 01:12:16 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407231216.GA1716317@oden.dyn.berto.se>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-6-laurent.pinchart@ideasonboard.com>\n\t<20200407202735.GK1716317@oden.dyn.berto.se>\n\t<20200407230729.GM4751@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200407230729.GM4751@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 05/11] libcamera: ipa_module: Simplify\n\terror handling in loadIPAModuleInfo()","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>","X-List-Received-Date":"Tue, 07 Apr 2020 23:12:18 -0000"}}]