[17/18,media] dvbdev: move indirect links on dvr/demux to a separate function
diff mbox

Message ID 85b36c34704eeba890472e7973d2e01a69c4b87c.1441559233.git.mchehab@osg.samsung.com
State New
Headers show

Commit Message

Mauro Carvalho Chehab Sept. 6, 2015, 5:31 p.m. UTC
Cleanup the code a little bit by moving the routine that creates
links between DVR and demux to the I/O entitis into a separate
function.

While here, fix the code to use strncmp() instead of strcmp().

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Comments

Hans Verkuil Sept. 11, 2015, 3:38 p.m. UTC | #1
On 09/06/2015 07:31 PM, Mauro Carvalho Chehab wrote:
> Cleanup the code a little bit by moving the routine that creates
> links between DVR and demux to the I/O entitis into a separate
> function.
> 
> While here, fix the code to use strncmp() instead of strcmp().
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index 8527fc40e6a0..ea76fe54e0e4 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -522,6 +522,28 @@ EXPORT_SYMBOL(dvb_unregister_device);
>  
>  
>  #ifdef CONFIG_MEDIA_CONTROLLER_DVB
> +
> +static int dvb_create_io_intf_links(struct dvb_adapter *adap,
> +				    struct media_interface *intf,
> +				    char *name)
> +{
> +	struct media_device *mdev = adap->mdev;
> +	struct media_entity *entity;
> +	struct media_link *link;
> +
> +	media_device_for_each_entity(entity, mdev) {
> +		if (entity->function == MEDIA_ENT_F_IO) {
> +			if (strncmp(entity->name, name, strlen(name)))
> +				continue;
> +			link = media_create_intf_link(entity, intf,
> +						      MEDIA_LNK_FL_ENABLED);
> +			if (!link)
> +				return -ENOMEM;
> +		}
> +	}
> +	return 0;
> +}
> +
>  int dvb_create_media_graph(struct dvb_adapter *adap)
>  {
>  	struct media_device *mdev = adap->mdev;
> @@ -619,25 +641,15 @@ int dvb_create_media_graph(struct dvb_adapter *adap)
>  			if (!link)
>  				return -ENOMEM;
>  		}
> -
> -		media_device_for_each_entity(entity, mdev) {
> -			if (entity->function == MEDIA_ENT_F_IO) {
> -				if (!strcmp(entity->name, DVR_TSOUT)) {
> -					link = media_create_intf_link(entity,
> -							intf,
> -							MEDIA_LNK_FL_ENABLED);
> -					if (!link)
> -						return -ENOMEM;
> -				}
> -				if (!strcmp(entity->name, DEMUX_TSOUT)) {
> -					link = media_create_intf_link(entity,
> -							intf,
> -							MEDIA_LNK_FL_ENABLED);
> -					if (!link)
> -						return -ENOMEM;
> -				}
> -				break;
> -			}
> +		if (intf->type == MEDIA_INTF_T_DVB_DVR) {
> +			ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
> +			if (ret)
> +				return ret;
> +		}
> +		if (intf->type == MEDIA_INTF_T_DVB_DEMUX) {
> +			ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT);
> +			if (ret)
> +				return ret;
>  		}
>  	}
>  	return 0;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 8527fc40e6a0..ea76fe54e0e4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -522,6 +522,28 @@  EXPORT_SYMBOL(dvb_unregister_device);
 
 
 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
+
+static int dvb_create_io_intf_links(struct dvb_adapter *adap,
+				    struct media_interface *intf,
+				    char *name)
+{
+	struct media_device *mdev = adap->mdev;
+	struct media_entity *entity;
+	struct media_link *link;
+
+	media_device_for_each_entity(entity, mdev) {
+		if (entity->function == MEDIA_ENT_F_IO) {
+			if (strncmp(entity->name, name, strlen(name)))
+				continue;
+			link = media_create_intf_link(entity, intf,
+						      MEDIA_LNK_FL_ENABLED);
+			if (!link)
+				return -ENOMEM;
+		}
+	}
+	return 0;
+}
+
 int dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
@@ -619,25 +641,15 @@  int dvb_create_media_graph(struct dvb_adapter *adap)
 			if (!link)
 				return -ENOMEM;
 		}
-
-		media_device_for_each_entity(entity, mdev) {
-			if (entity->function == MEDIA_ENT_F_IO) {
-				if (!strcmp(entity->name, DVR_TSOUT)) {
-					link = media_create_intf_link(entity,
-							intf,
-							MEDIA_LNK_FL_ENABLED);
-					if (!link)
-						return -ENOMEM;
-				}
-				if (!strcmp(entity->name, DEMUX_TSOUT)) {
-					link = media_create_intf_link(entity,
-							intf,
-							MEDIA_LNK_FL_ENABLED);
-					if (!link)
-						return -ENOMEM;
-				}
-				break;
-			}
+		if (intf->type == MEDIA_INTF_T_DVB_DVR) {
+			ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
+			if (ret)
+				return ret;
+		}
+		if (intf->type == MEDIA_INTF_T_DVB_DEMUX) {
+			ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT);
+			if (ret)
+				return ret;
 		}
 	}
 	return 0;