Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: Split v4l2_pipeline_pm_use into v4l2_pipeline_pm_{get, put}

Currently, v4l2_pipeline_pm_use() prototype is:

int v4l2_pipeline_pm_use(struct media_entity *entity, int use)

Where the 'use' argument shall only be set to '1' for enable/power-on,
or to '0' for disable/power-off. The integer return is specified
as only meaningful when 'use' is set to '1'.

Let's enforce this semantic by splitting the function in two:
v4l2_pipeline_pm_get and v4l2_pipeline_pm_put. This is done
for several reasons.

It makes the API easier to use (or harder to misuse).
It removes the constraint on the values the 'use' argument
shall take. Also, it removes the need to constraint
the return value, by making v4l2_pipeline_pm_put void return.

And last, it's more consistent with other kernel APIs, such
as the runtime pm APIs, which makes the code more symmetric.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
8fd390b8 8fb12ce2

+60 -41
+1 -1
Documentation/media/kapi/csi2.rst
··· 74 74 the :c:type:`v4l2_subdev_video_ops`->s_stream(), it must have powered 75 75 the transmitter up by using the 76 76 :c:type:`v4l2_subdev_core_ops`->s_power() callback. This may take 77 - place either indirectly by using :c:func:`v4l2_pipeline_pm_use` or 77 + place either indirectly by using :c:func:`v4l2_pipeline_pm_get` or 78 78 directly. 79 79 80 80 Formats
+2 -2
drivers/media/platform/omap3isp/ispvideo.c
··· 1311 1311 goto done; 1312 1312 } 1313 1313 1314 - ret = v4l2_pipeline_pm_use(&video->video.entity, 1); 1314 + ret = v4l2_pipeline_pm_get(&video->video.entity); 1315 1315 if (ret < 0) { 1316 1316 omap3isp_put(video->isp); 1317 1317 goto done; ··· 1363 1363 vb2_queue_release(&handle->queue); 1364 1364 mutex_unlock(&video->queue_lock); 1365 1365 1366 - v4l2_pipeline_pm_use(&video->video.entity, 0); 1366 + v4l2_pipeline_pm_put(&video->video.entity); 1367 1367 1368 1368 /* Release the file handle. */ 1369 1369 v4l2_fh_del(vfh);
+2 -2
drivers/media/platform/qcom/camss/camss-video.c
··· 745 745 746 746 file->private_data = vfh; 747 747 748 - ret = v4l2_pipeline_pm_use(&vdev->entity, 1); 748 + ret = v4l2_pipeline_pm_get(&vdev->entity); 749 749 if (ret < 0) { 750 750 dev_err(video->camss->dev, "Failed to power up pipeline: %d\n", 751 751 ret); ··· 771 771 772 772 vb2_fop_release(file); 773 773 774 - v4l2_pipeline_pm_use(&vdev->entity, 0); 774 + v4l2_pipeline_pm_put(&vdev->entity); 775 775 776 776 file->private_data = NULL; 777 777
+3 -3
drivers/media/platform/rcar-vin/rcar-v4l2.c
··· 842 842 goto err_unlock; 843 843 844 844 if (vin->info->use_mc) 845 - ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1); 845 + ret = v4l2_pipeline_pm_get(&vin->vdev.entity); 846 846 else if (v4l2_fh_is_singular_file(file)) 847 847 ret = rvin_power_parallel(vin, true); 848 848 ··· 858 858 return 0; 859 859 err_power: 860 860 if (vin->info->use_mc) 861 - v4l2_pipeline_pm_use(&vin->vdev.entity, 0); 861 + v4l2_pipeline_pm_put(&vin->vdev.entity); 862 862 else if (v4l2_fh_is_singular_file(file)) 863 863 rvin_power_parallel(vin, false); 864 864 err_open: ··· 886 886 ret = _vb2_fop_release(file, NULL); 887 887 888 888 if (vin->info->use_mc) { 889 - v4l2_pipeline_pm_use(&vin->vdev.entity, 0); 889 + v4l2_pipeline_pm_put(&vin->vdev.entity); 890 890 } else { 891 891 if (fh_singular) 892 892 rvin_power_parallel(vin, false);
+3 -3
drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
··· 214 214 if (ret < 0) 215 215 goto err_pm_put; 216 216 217 - ret = v4l2_pipeline_pm_use(&csi->vdev.entity, 1); 217 + ret = v4l2_pipeline_pm_get(&csi->vdev.entity); 218 218 if (ret) 219 219 goto err_pm_put; 220 220 ··· 227 227 return 0; 228 228 229 229 err_pipeline_pm_put: 230 - v4l2_pipeline_pm_use(&csi->vdev.entity, 0); 230 + v4l2_pipeline_pm_put(&csi->vdev.entity); 231 231 232 232 err_pm_put: 233 233 pm_runtime_put(csi->dev); ··· 243 243 mutex_lock(&csi->lock); 244 244 245 245 v4l2_fh_release(file); 246 - v4l2_pipeline_pm_use(&csi->vdev.entity, 0); 246 + v4l2_pipeline_pm_put(&csi->vdev.entity); 247 247 pm_runtime_put(csi->dev); 248 248 249 249 mutex_unlock(&csi->lock);
+2 -2
drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
··· 474 474 if (ret < 0) 475 475 goto unlock; 476 476 477 - ret = v4l2_pipeline_pm_use(&video->vdev.entity, 1); 477 + ret = v4l2_pipeline_pm_get(&video->vdev.entity); 478 478 if (ret < 0) 479 479 goto fh_release; 480 480 ··· 507 507 508 508 _vb2_fop_release(file, NULL); 509 509 510 - v4l2_pipeline_pm_use(&video->vdev.entity, 0); 510 + v4l2_pipeline_pm_put(&video->vdev.entity); 511 511 512 512 if (last_fh) 513 513 sun6i_csi_set_power(video->csi, false);
+15 -3
drivers/media/v4l2-core/v4l2-mc.c
··· 321 321 * use_count field stores the total number of users of all video device nodes 322 322 * in the pipeline. 323 323 * 324 - * The v4l2_pipeline_pm_use() function must be called in the open() and 324 + * The v4l2_pipeline_pm_{get, put}() functions must be called in the open() and 325 325 * close() handlers of video device nodes. It increments or decrements the use 326 326 * count of all subdev entities in the pipeline. 327 327 * ··· 423 423 return ret; 424 424 } 425 425 426 - int v4l2_pipeline_pm_use(struct media_entity *entity, int use) 426 + static int v4l2_pipeline_pm_use(struct media_entity *entity, unsigned int use) 427 427 { 428 428 struct media_device *mdev = entity->graph_obj.mdev; 429 429 int change = use ? 1 : -1; ··· 444 444 445 445 return ret; 446 446 } 447 - EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_use); 447 + 448 + int v4l2_pipeline_pm_get(struct media_entity *entity) 449 + { 450 + return v4l2_pipeline_pm_use(entity, 1); 451 + } 452 + EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_get); 453 + 454 + void v4l2_pipeline_pm_put(struct media_entity *entity) 455 + { 456 + /* Powering off entities shouldn't fail. */ 457 + WARN_ON(v4l2_pipeline_pm_use(entity, 0)); 458 + } 459 + EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_put); 448 460 449 461 int v4l2_pipeline_link_notify(struct media_link *link, u32 flags, 450 462 unsigned int notification)
+2 -2
drivers/staging/media/imx/imx-media-capture.c
··· 643 643 if (ret) 644 644 v4l2_err(priv->src_sd, "v4l2_fh_open failed\n"); 645 645 646 - ret = v4l2_pipeline_pm_use(&vfd->entity, 1); 646 + ret = v4l2_pipeline_pm_get(&vfd->entity); 647 647 if (ret) 648 648 v4l2_fh_release(file); 649 649 ··· 664 664 vq->owner = NULL; 665 665 } 666 666 667 - v4l2_pipeline_pm_use(&vfd->entity, 0); 667 + v4l2_pipeline_pm_put(&vfd->entity); 668 668 669 669 v4l2_fh_release(file); 670 670 mutex_unlock(&priv->mutex);
+2 -2
drivers/staging/media/omap4iss/iss_video.c
··· 1111 1111 goto done; 1112 1112 } 1113 1113 1114 - ret = v4l2_pipeline_pm_use(&video->video.entity, 1); 1114 + ret = v4l2_pipeline_pm_get(&video->video.entity); 1115 1115 if (ret < 0) { 1116 1116 omap4iss_put(video->iss); 1117 1117 goto done; ··· 1160 1160 /* Disable streaming and free the buffers queue resources. */ 1161 1161 iss_video_streamoff(file, vfh, video->type); 1162 1162 1163 - v4l2_pipeline_pm_use(&video->video.entity, 0); 1163 + v4l2_pipeline_pm_put(&video->video.entity); 1164 1164 1165 1165 /* Release the videobuf2 queue */ 1166 1166 vb2_queue_release(&handle->queue);
+3 -6
drivers/staging/media/rkisp1/rkisp1-capture.c
··· 937 937 938 938 rkisp1_return_all_buffers(cap, VB2_BUF_STATE_ERROR); 939 939 940 - ret = v4l2_pipeline_pm_use(&node->vdev.entity, 0); 941 - if (ret) 942 - dev_err(rkisp1->dev, "pipeline close failed error:%d\n", ret); 943 - 940 + v4l2_pipeline_pm_put(&node->vdev.entity); 944 941 ret = pm_runtime_put(rkisp1->dev); 945 942 if (ret) 946 943 dev_err(rkisp1->dev, "power down failed error:%d\n", ret); ··· 996 999 dev_err(cap->rkisp1->dev, "power up failed %d\n", ret); 997 1000 goto err_destroy_dummy; 998 1001 } 999 - ret = v4l2_pipeline_pm_use(entity, 1); 1002 + ret = v4l2_pipeline_pm_get(entity); 1000 1003 if (ret) { 1001 1004 dev_err(cap->rkisp1->dev, "open cif pipeline failed %d\n", ret); 1002 1005 goto err_pipe_pm_put; ··· 1022 1025 rkisp1_pipeline_sink_walk(entity, NULL, rkisp1_pipeline_disable_cb); 1023 1026 err_stop_stream: 1024 1027 rkisp1_stream_stop(cap); 1025 - v4l2_pipeline_pm_use(entity, 0); 1028 + v4l2_pipeline_pm_put(entity); 1026 1029 err_pipe_pm_put: 1027 1030 pm_runtime_put(cap->rkisp1->dev); 1028 1031 err_destroy_dummy:
+25 -15
include/media/v4l2-mc.h
··· 86 86 87 87 88 88 /** 89 - * v4l2_pipeline_pm_use - Update the use count of an entity 90 - * @entity: The entity 91 - * @use: Use (1) or stop using (0) the entity 89 + * v4l2_pipeline_pm_get - Increase the use count of a pipeline 90 + * @entity: The root entity of a pipeline 92 91 * 93 - * Update the use count of all entities in the pipeline and power entities on or 94 - * off accordingly. 92 + * Update the use count of all entities in the pipeline and power entities on. 95 93 * 96 - * This function is intended to be called in video node open (use == 97 - * 1) and release (use == 0). It uses struct media_entity.use_count to 98 - * track the power status. The use of this function should be paired 99 - * with v4l2_pipeline_link_notify(). 94 + * This function is intended to be called in video node open. It uses 95 + * struct media_entity.use_count to track the power status. The use 96 + * of this function should be paired with v4l2_pipeline_link_notify(). 100 97 * 101 - * Return 0 on success or a negative error code on failure. Powering entities 102 - * off is assumed to never fail. No failure can occur when the use parameter is 103 - * set to 0. 98 + * Return 0 on success or a negative error code on failure. 104 99 */ 105 - int v4l2_pipeline_pm_use(struct media_entity *entity, int use); 100 + int v4l2_pipeline_pm_get(struct media_entity *entity); 101 + 102 + /** 103 + * v4l2_pipeline_pm_put - Decrease the use count of a pipeline 104 + * @entity: The root entity of a pipeline 105 + * 106 + * Update the use count of all entities in the pipeline and power entities off. 107 + * 108 + * This function is intended to be called in video node release. It uses 109 + * struct media_entity.use_count to track the power status. The use 110 + * of this function should be paired with v4l2_pipeline_link_notify(). 111 + */ 112 + void v4l2_pipeline_pm_put(struct media_entity *entity); 106 113 107 114 108 115 /** ··· 121 114 * React to link management on powered pipelines by updating the use count of 122 115 * all entities in the source and sink sides of the link. Entities are powered 123 116 * on or off accordingly. The use of this function should be paired 124 - * with v4l2_pipeline_pm_use(). 117 + * with v4l2_pipeline_pm_{get,put}(). 125 118 * 126 119 * Return 0 on success or a negative error code on failure. Powering entities 127 120 * off is assumed to never fail. This function will not fail for disconnection ··· 151 144 return 0; 152 145 } 153 146 154 - static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use) 147 + static inline int v4l2_pipeline_pm_get(struct media_entity *entity) 155 148 { 156 149 return 0; 157 150 } 151 + 152 + static inline void v4l2_pipeline_pm_put(struct media_entity *entity) 153 + {} 158 154 159 155 static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags, 160 156 unsigned int notification)