From patchwork Wed Jan 2 12:02:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 133 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C595A60B0C for ; Wed, 2 Jan 2019 13:02:56 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 5B21BC0007; Wed, 2 Jan 2019 12:02:56 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Jan 2019 13:02:55 +0100 Message-Id: <20190102120256.7769-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: media_device: Minor cleanup in findInterface() 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: Wed, 02 Jan 2019 12:02:56 -0000 Do not compare an usigned int with -1 to avoid going through cast. Also align function parameters and long assignement lines while at there. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/media_device.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 4ff9ffe..34206c8 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -379,13 +379,14 @@ void MediaDevice::clear() * \return A pointer to the interface if found, or nullptr otherwise */ struct media_v2_interface *MediaDevice::findInterface(const struct media_v2_topology &topology, - unsigned int entityId) + unsigned int entityId) { struct media_v2_link *links = reinterpret_cast - (topology.ptr_links); - unsigned int ifaceId = -1; + (topology.ptr_links); + unsigned int ifaceId; + unsigned int i; - for (unsigned int i = 0; i < topology.num_links; ++i) { + for (i = 0; i < topology.num_links; ++i) { /* Search for the interface to entity link. */ if (links[i].sink_id != entityId) continue; @@ -397,14 +398,12 @@ struct media_v2_interface *MediaDevice::findInterface(const struct media_v2_topo ifaceId = links[i].source_id; break; } - - if (ifaceId == static_cast(-1)) + if (i == topology.num_links) return nullptr; struct media_v2_interface *ifaces = reinterpret_cast - (topology.ptr_interfaces); - - for (unsigned int i = 0; i < topology.num_interfaces; ++i) { + (topology.ptr_interfaces); + for (i = 0; i < topology.num_interfaces; ++i) { if (ifaces[i].id == ifaceId) return &ifaces[i]; } From patchwork Wed Jan 2 12:02:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 134 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1248960B0C for ; Wed, 2 Jan 2019 13:02:58 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 9AFD9C000A; Wed, 2 Jan 2019 12:02:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Jan 2019 13:02:56 +0100 Message-Id: <20190102120256.7769-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190102120256.7769-1-jacopo@jmondi.org> References: <20190102120256.7769-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: Use 'struct' for structure types 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: Wed, 02 Jan 2019 12:02:58 -0000 Add back the 'struct' keyword for structure types. C++ allows omitting the 'struct' keywork. Add it back to make clear we're dealing with structures and not class types. While at there re-align lines to first open brace, or angular brace for casts, and re-sort lines to have the longest one first in populate() function. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/media_device.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) -- 2.20.1 diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 34206c8..715d971 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -205,10 +205,10 @@ void MediaDevice::close() int MediaDevice::populate() { struct media_v2_topology topology = { }; + struct media_v2_interface *interfaces = nullptr; struct media_v2_entity *ents = nullptr; struct media_v2_link *links = nullptr; struct media_v2_pad *pads = nullptr; - struct media_v2_interface *interfaces = nullptr; __u64 version = -1; int ret; @@ -219,10 +219,10 @@ int MediaDevice::populate() */ while (true) { topology.topology_version = 0; + topology.ptr_interfaces = reinterpret_cast<__u64>(interfaces); topology.ptr_entities = reinterpret_cast<__u64>(ents); topology.ptr_links = reinterpret_cast<__u64>(links); topology.ptr_pads = reinterpret_cast<__u64>(pads); - topology.ptr_interfaces = reinterpret_cast<__u64>(interfaces); ret = ioctl(fd_, MEDIA_IOC_G_TOPOLOGY, &topology); if (ret < 0) { @@ -235,15 +235,15 @@ int MediaDevice::populate() if (version == topology.topology_version) break; + delete[] interfaces; delete[] links; delete[] ents; delete[] pads; - delete[] interfaces; - ents = new media_v2_entity[topology.num_entities]; - links = new media_v2_link[topology.num_links]; - pads = new media_v2_pad[topology.num_pads]; - interfaces = new media_v2_interface[topology.num_interfaces]; + interfaces = new struct media_v2_interface[topology.num_interfaces]; + ents = new struct media_v2_entity[topology.num_entities]; + links = new struct media_v2_link[topology.num_links]; + pads = new struct media_v2_pad[topology.num_pads]; version = topology.topology_version; } @@ -254,10 +254,10 @@ int MediaDevice::populate() populateLinks(topology)) valid_ = true; + delete[] interfaces; delete[] links; delete[] ents; delete[] pads; - delete[] interfaces; if (!valid_) { clear(); @@ -417,17 +417,16 @@ struct media_v2_interface *MediaDevice::findInterface(const struct media_v2_topo */ bool MediaDevice::populateEntities(const struct media_v2_topology &topology) { - media_v2_entity *mediaEntities = reinterpret_cast - (topology.ptr_entities); + struct media_v2_entity *mediaEntities = reinterpret_cast + (topology.ptr_entities); for (unsigned int i = 0; i < topology.num_entities; ++i) { /* * Find the interface linked to this entity to get the device * node major and minor numbers. */ - struct media_v2_interface *iface = - findInterface(topology, mediaEntities[i].id); - + struct media_v2_interface *iface = findInterface(topology, + mediaEntities[i].id); MediaEntity *entity; if (iface) entity = new MediaEntity(&mediaEntities[i], @@ -449,8 +448,8 @@ bool MediaDevice::populateEntities(const struct media_v2_topology &topology) bool MediaDevice::populatePads(const struct media_v2_topology &topology) { - media_v2_pad *mediaPads = reinterpret_cast - (topology.ptr_pads); + struct media_v2_pad *mediaPads = reinterpret_cast + (topology.ptr_pads); for (unsigned int i = 0; i < topology.num_pads; ++i) { unsigned int entity_id = mediaPads[i].entity_id; @@ -478,8 +477,8 @@ bool MediaDevice::populatePads(const struct media_v2_topology &topology) bool MediaDevice::populateLinks(const struct media_v2_topology &topology) { - media_v2_link *mediaLinks = reinterpret_cast - (topology.ptr_links); + struct media_v2_link *mediaLinks = reinterpret_cast + (topology.ptr_links); for (unsigned int i = 0; i < topology.num_links; ++i) { /*