[{"id":948,"web_url":"https://patchwork.libcamera.org/comment/948/","msgid":"<20190228163648.GD899@bigcity.dyn.berto.se>","date":"2019-02-28T16:36:49","subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: pipeline: Fix double\n\trelease of media devices","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 2019-02-28 18:29:04 +0200, Laurent Pinchart wrote:\n> Media devices are acquired in the match() function of pipeline handlers,\n> and explicitly released if no match is found. The pipeline handler is\n> then deleted, which causes a second release of the media device in the\n> destructor. Fix this by removing the explicit release in the match()\n> function.\n\nNice catch.\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 28 +++++++++++-----------------\n>  src/libcamera/pipeline/uvcvideo.cpp  |  1 -\n>  src/libcamera/pipeline/vimc.cpp      |  5 +----\n>  3 files changed, 12 insertions(+), 22 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 9694d0ce51ab..cf5c28577393 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -278,19 +278,20 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n>  \timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n>  \n> +\t/*\n> +\t * It is safe to acquire both media devices at this point as\n> +\t * DeviceEnumerator::search() skips the busy ones for us.\n> +\t */\n>  \tcio2_ = enumerator->search(cio2_dm);\n>  \tif (!cio2_)\n>  \t\treturn false;\n>  \n> +\tcio2_->acquire();\n> +\n>  \timgu_ = enumerator->search(imgu_dm);\n>  \tif (!imgu_)\n>  \t\treturn false;\n>  \n> -\t/*\n> -\t * It is safe to acquire both media devices at this point as\n> -\t * DeviceEnumerator::search() skips the busy ones for us.\n> -\t */\n> -\tcio2_->acquire();\n>  \timgu_->acquire();\n>  \n>  \t/*\n> @@ -301,25 +302,18 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \t * not need to be changed after.\n>  \t */\n>  \tif (cio2_->open())\n> -\t\tgoto error_release_mdev;\n> +\t\treturn false;\n>  \n> -\tif (cio2_->disableLinks())\n> -\t\tgoto error_close_cio2;\n> +\tif (cio2_->disableLinks()) {\n> +\t\tcio2_->close();\n> +\t\treturn false;\n> +\t}\n>  \n>  \tregisterCameras();\n>  \n>  \tcio2_->close();\n>  \n>  \treturn true;\n> -\n> -error_close_cio2:\n> -\tcio2_->close();\n> -\n> -error_release_mdev:\n> -\tcio2_->release();\n> -\timgu_->release();\n> -\n> -\treturn false;\n>  }\n>  \n>  /*\n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index b7b8ff109109..dd20bb085a29 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -167,7 +167,6 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n>  \t\tif (!video_)\n>  \t\t\tLOG(UVC, Error) << \"Could not find a default video device\";\n>  \n> -\t\tmedia_->release();\n>  \t\treturn false;\n>  \t}\n>  \n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 812777cffbb3..640fca5cb0e7 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -165,11 +165,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n>  \tmedia_->acquire();\n>  \n>  \tvideo_ = new V4L2Device(media_->getEntityByName(\"Raw Capture 1\"));\n> -\n> -\tif (video_->open()) {\n> -\t\tmedia_->release();\n> +\tif (video_->open())\n>  \t\treturn false;\n> -\t}\n>  \n>  \tstd::vector<Stream *> streams{ &stream_ };\n>  \tstd::shared_ptr<Camera> camera = Camera::create(this, \"VIMC Sensor B\",\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-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27BC2610B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Feb 2019 17:36:51 +0100 (CET)","by mail-lj1-x243.google.com with SMTP id a17so17695631ljd.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Feb 2019 08:36:51 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tz128sm1291040lfa.60.2019.02.28.08.36.49\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 28 Feb 2019 08:36:49 -0800 (PST)"],"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\t:user-agent; bh=K9wOP49nnetZfbLFY8iFwX+o8zqGgpW94NFUn1FK1C0=;\n\tb=ak2X8LyQBPPEA83p7K8lfMUD9BVrD4WK+jmauWIM2PF0BYTklYT+o5LBJphuA2sx3J\n\ty0x0QRum4BAeZ1qpqMcOzj+V6/nMsJBp+18j8QmHuT6Vxfl8Nv9FzZwRFsP5jFFPQ0KJ\n\tXc/5EeffICk3O6fhjZCm0D5KxrYgbvo0zdrqUiIL7ZAQadzAviNa/gJ7+NG/6yyVpwZi\n\t2ZYNTWDjMYg8jot/WuZyzdSm9OLFrA7/8NK62vbd+3urcwJpZIcQ9ikb5YCTuFMvzfqv\n\ttZmbU8U1cEffwCM4I8tj6GYakiUnzHIS4uCf5igkgnKzGK/C/3fxaXWUL9ailjNo7d04\n\tNLHA==","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:user-agent;\n\tbh=K9wOP49nnetZfbLFY8iFwX+o8zqGgpW94NFUn1FK1C0=;\n\tb=CsVHeuYt5D8fn9SBUZKMjbs/IlkaCCmB8QjWOo3i0VE1YaIMW79Fdel3iCg80j1OxW\n\tBMAM2UWmRyVUT4cw5F4d22W9/QUBH6JvmdcccYugNVb9u81guzejh0inTeR9qiL5G6c3\n\t2//TeJQ18cqrFfbjI/O4ZLXvWTbWGSwOK6HBrS72yBURZx9/Vr6ukBdw/7WkLEWyrVwe\n\tTWVgCIdbe/Hoz7nZDT/3nKoandl5LVR+n8xQpqVnyG/NewyThMV9wk5dmPRdsgwXz7VR\n\tBBBVupvqXoCgo3bJH2vtbCCqQOTlc7uxTfUWB18HxfkBcwG7s+bJCsK60WlVXyUceZ0y\n\tJ3sA==","X-Gm-Message-State":"AHQUAuZ2Gmwz3jwY+mjKMcMIb6i6Ds1MCPLP5TcouQ8GgShk4EV7jLAv\n\tZnHkqKY2PwCMpy8+n/085vPzZQ==","X-Google-Smtp-Source":"APXvYqyKBjwYxesbhix/0TMYEBxk2VC7wCPr3v9R80UHvj/8Rya4DyMPt2WlX9naWiczA+q0xY29gQ==","X-Received":"by 2002:a2e:680e:: with SMTP id c14mr2445390lja.51.1551371810383;\n\tThu, 28 Feb 2019 08:36:50 -0800 (PST)","Date":"Thu, 28 Feb 2019 17:36:49 +0100","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":"<20190228163648.GD899@bigcity.dyn.berto.se>","References":"<20190228162913.6508-1-laurent.pinchart@ideasonboard.com>\n\t<20190228162913.6508-2-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":"<20190228162913.6508-2-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: pipeline: Fix double\n\trelease of media devices","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 28 Feb 2019 16:36:51 -0000"}},{"id":995,"web_url":"https://patchwork.libcamera.org/comment/995/","msgid":"<20190301130221.t2emxptlp66mualo@uno.localdomain>","date":"2019-03-01T13:02:22","subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: pipeline: Fix double\n\trelease of media devices","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Thu, Feb 28, 2019 at 06:29:04PM +0200, Laurent Pinchart wrote:\n> Media devices are acquired in the match() function of pipeline handlers,\n> and explicitly released if no match is found. The pipeline handler is\n> then deleted, which causes a second release of the media device in the\n> destructor. Fix this by removing the explicit release in the match()\n> function.\n>\n\nNice! Thanks..\n\nAcked-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 28 +++++++++++-----------------\n>  src/libcamera/pipeline/uvcvideo.cpp  |  1 -\n>  src/libcamera/pipeline/vimc.cpp      |  5 +----\n>  3 files changed, 12 insertions(+), 22 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 9694d0ce51ab..cf5c28577393 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -278,19 +278,20 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n>  \timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n>\n> +\t/*\n> +\t * It is safe to acquire both media devices at this point as\n> +\t * DeviceEnumerator::search() skips the busy ones for us.\n> +\t */\n>  \tcio2_ = enumerator->search(cio2_dm);\n>  \tif (!cio2_)\n>  \t\treturn false;\n>\n> +\tcio2_->acquire();\n> +\n>  \timgu_ = enumerator->search(imgu_dm);\n>  \tif (!imgu_)\n>  \t\treturn false;\n>\n> -\t/*\n> -\t * It is safe to acquire both media devices at this point as\n> -\t * DeviceEnumerator::search() skips the busy ones for us.\n> -\t */\n> -\tcio2_->acquire();\n>  \timgu_->acquire();\n>\n>  \t/*\n> @@ -301,25 +302,18 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \t * not need to be changed after.\n>  \t */\n>  \tif (cio2_->open())\n> -\t\tgoto error_release_mdev;\n> +\t\treturn false;\n>\n> -\tif (cio2_->disableLinks())\n> -\t\tgoto error_close_cio2;\n> +\tif (cio2_->disableLinks()) {\n> +\t\tcio2_->close();\n> +\t\treturn false;\n> +\t}\n>\n>  \tregisterCameras();\n>\n>  \tcio2_->close();\n>\n>  \treturn true;\n> -\n> -error_close_cio2:\n> -\tcio2_->close();\n> -\n> -error_release_mdev:\n> -\tcio2_->release();\n> -\timgu_->release();\n> -\n> -\treturn false;\n>  }\n>\n>  /*\n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index b7b8ff109109..dd20bb085a29 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -167,7 +167,6 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n>  \t\tif (!video_)\n>  \t\t\tLOG(UVC, Error) << \"Could not find a default video device\";\n>\n> -\t\tmedia_->release();\n>  \t\treturn false;\n>  \t}\n>\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 812777cffbb3..640fca5cb0e7 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -165,11 +165,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n>  \tmedia_->acquire();\n>\n>  \tvideo_ = new V4L2Device(media_->getEntityByName(\"Raw Capture 1\"));\n> -\n> -\tif (video_->open()) {\n> -\t\tmedia_->release();\n> +\tif (video_->open())\n>  \t\treturn false;\n> -\t}\n>\n>  \tstd::vector<Stream *> streams{ &stream_ };\n>  \tstd::shared_ptr<Camera> camera = Camera::create(this, \"VIMC Sensor B\",\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":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D2B1610BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Mar 2019 14:01:52 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 19E48100007;\n\tFri,  1 Mar 2019 13:01:51 +0000 (UTC)"],"Date":"Fri, 1 Mar 2019 14:02:22 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190301130221.t2emxptlp66mualo@uno.localdomain>","References":"<20190228162913.6508-1-laurent.pinchart@ideasonboard.com>\n\t<20190228162913.6508-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"fciwp267ximtf5zf\"","Content-Disposition":"inline","In-Reply-To":"<20190228162913.6508-2-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: pipeline: Fix double\n\trelease of media devices","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Fri, 01 Mar 2019 13:01:52 -0000"}}]