From patchwork Sun Apr 14 01:34:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 972 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C23E60DC0 for ; Sun, 14 Apr 2019 03:35:16 +0200 (CEST) X-Halon-ID: 8dc58b34-5e55-11e9-8e2c-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 8dc58b34-5e55-11e9-8e2c-005056917f90; Sun, 14 Apr 2019 03:35:15 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 14 Apr 2019 03:34:58 +0200 Message-Id: <20190414013506.10515-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414013506.10515-1-niklas.soderlund@ragnatech.se> References: <20190414013506.10515-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 03/11] libcamera: media_device: Only read device information in populate() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Apr 2019 01:35:17 -0000 There is no reason to reread the MEDIA_IOC_DEVICE_INFO information every time the media device is opened. Move it populate() where it will be read once together the other information about the media device. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/media_device.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index ecb00a1d5abffe80..54706bb73a7591d5 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -131,9 +131,6 @@ bool MediaDevice::acquire() * with the device node associated with the media device, the device node must * be opened. * - * This function also retrieves media device information from the device node, - * which can be queried through driver(). - * * If the device is already open the function returns -EBUSY. * * \return 0 on success or a negative error code otherwise @@ -155,20 +152,6 @@ int MediaDevice::open() } fd_ = ret; - struct media_device_info info = { }; - ret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info); - if (ret) { - ret = -errno; - LOG(MediaDevice, Error) - << "Failed to get media device info " - << ": " << strerror(-ret); - return ret; - } - - driver_ = info.driver; - model_ = info.model; - version_ = info.media_version; - return 0; } @@ -224,6 +207,20 @@ int MediaDevice::populate() if (ret) return ret; + struct media_device_info info = {}; + ret = ioctl(fd_, MEDIA_IOC_DEVICE_INFO, &info); + if (ret) { + ret = -errno; + LOG(MediaDevice, Error) + << "Failed to get media device info " + << ": " << strerror(-ret); + goto err_out; + } + + driver_ = info.driver; + model_ = info.model; + version_ = info.media_version; + /* * Keep calling G_TOPOLOGY until the version number stays stable. */