[libcamera-devel,1/2] libcamera: media_device: Minor cleanup in findInterface()

Message ID 20190102120256.7769-1-jacopo@jmondi.org
State Accepted
Headers show
Series
  • [libcamera-devel,1/2] libcamera: media_device: Minor cleanup in findInterface()
Related show

Commit Message

Jacopo Mondi Jan. 2, 2019, 12:02 p.m. UTC
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 <jacopo@jmondi.org>
---
 src/libcamera/media_device.cpp | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

--
2.20.1

Comments

Niklas Söderlund Jan. 2, 2019, 10:48 p.m. UTC | #1
Hi Jacopo,

Thanks for your patch.

On 2019-01-02 13:02:55 +0100, Jacopo Mondi wrote:
> 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 <jacopo@jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/media_device.cpp | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> 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<struct media_v2_link *>
> -						(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<unsigned int>(-1))
> +	if (i == topology.num_links)
>  		return nullptr;
> 
>  	struct media_v2_interface *ifaces = reinterpret_cast<struct media_v2_interface *>
> -						(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];
>  	}
> --
> 2.20.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

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<struct media_v2_link *>
-						(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<unsigned int>(-1))
+	if (i == topology.num_links)
 		return nullptr;

 	struct media_v2_interface *ifaces = reinterpret_cast<struct media_v2_interface *>
-						(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];
 	}