diff mbox series

[v11,41/56] media: cedrus: Stop direct calls to queue num_buffers field

Message ID 20231012114642.19040-42-benjamin.gaignard@collabora.com
State Superseded
Headers show
Series Add DELETE_BUF ioctl | expand

Commit Message

Benjamin Gaignard Oct. 12, 2023, 11:46 a.m. UTC
Use vb2_get_num_buffers() and queue max_num_buffers field
to avoid using queue num_buffer field directly.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
CC: Maxime Ripard <mripard@kernel.org>
CC: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 8 ++++++--
 drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 9 +++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

Comments

Paul Kocialkowski Oct. 17, 2023, 8:54 a.m. UTC | #1
Hi Benjamin,

On Thu 12 Oct 23, 13:46, Benjamin Gaignard wrote:
> Use vb2_get_num_buffers() and queue max_num_buffers field
> to avoid using queue num_buffer field directly.

Thanks for the patch, this is indeed a nice cleanup and safer usage.
Maybe the commit message needs to reflect why this change is welcome,
not just what is being changed.

> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> CC: Maxime Ripard <mripard@kernel.org>
> CC: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 8 ++++++--
>  drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 9 +++++++--
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
> index dfb401df138a..95e490532a87 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
> @@ -653,8 +653,12 @@ static void cedrus_h264_stop(struct cedrus_ctx *ctx)
>  
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
>  
> -	for (i = 0; i < vq->num_buffers; i++) {
> -		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
> +	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
> +		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
> +
> +		if (!vb)
> +			continue;

Please add a newline here to be consistent with the other block being changed.

With this change and the commit log reworked, you can consider this:
Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

Thanks!

Paul

> +		buf = vb2_to_cedrus_buffer(vb);
>  
>  		if (buf->codec.h264.mv_col_buf_size > 0) {
>  			dma_free_attrs(dev->dev,
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
> index fc9297232456..52e94c8f2f01 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
> @@ -869,8 +869,13 @@ static void cedrus_h265_stop(struct cedrus_ctx *ctx)
>  
>  	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
>  
> -	for (i = 0; i < vq->num_buffers; i++) {
> -		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
> +	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
> +		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
> +
> +		if (!vb)
> +			continue;
> +
> +		buf = vb2_to_cedrus_buffer(vb);
>  
>  		if (buf->codec.h265.mv_col_buf_size > 0) {
>  			dma_free_attrs(dev->dev,
> -- 
> 2.39.2
>
Benjamin Gaignard Oct. 17, 2023, 9:59 a.m. UTC | #2
Le 17/10/2023 à 10:54, Paul Kocialkowski a écrit :
> Hi Benjamin,
>
> On Thu 12 Oct 23, 13:46, Benjamin Gaignard wrote:
>> Use vb2_get_num_buffers() and queue max_num_buffers field
>> to avoid using queue num_buffer field directly.
> Thanks for the patch, this is indeed a nice cleanup and safer usage.
> Maybe the commit message needs to reflect why this change is welcome,
> not just what is being changed.

I will add this comment in the commit message:
This allows us to change how the number of buffers is computed in the futur.

>
>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
>> CC: Maxime Ripard <mripard@kernel.org>
>> CC: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
>> ---
>>   drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 8 ++++++--
>>   drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 9 +++++++--
>>   2 files changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
>> index dfb401df138a..95e490532a87 100644
>> --- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
>> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
>> @@ -653,8 +653,12 @@ static void cedrus_h264_stop(struct cedrus_ctx *ctx)
>>   
>>   	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
>>   
>> -	for (i = 0; i < vq->num_buffers; i++) {
>> -		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
>> +	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
>> +		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
>> +
>> +		if (!vb)
>> +			continue;
> Please add a newline here to be consistent with the other block being changed.
>
> With this change and the commit log reworked, you can consider this:
> Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

That will be done for the next version.

Thanks,

Benjamin

>
> Thanks!
>
> Paul
>
>> +		buf = vb2_to_cedrus_buffer(vb);
>>   
>>   		if (buf->codec.h264.mv_col_buf_size > 0) {
>>   			dma_free_attrs(dev->dev,
>> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
>> index fc9297232456..52e94c8f2f01 100644
>> --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
>> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
>> @@ -869,8 +869,13 @@ static void cedrus_h265_stop(struct cedrus_ctx *ctx)
>>   
>>   	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
>>   
>> -	for (i = 0; i < vq->num_buffers; i++) {
>> -		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
>> +	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
>> +		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
>> +
>> +		if (!vb)
>> +			continue;
>> +
>> +		buf = vb2_to_cedrus_buffer(vb);
>>   
>>   		if (buf->codec.h265.mv_col_buf_size > 0) {
>>   			dma_free_attrs(dev->dev,
>> -- 
>> 2.39.2
>>
diff mbox series

Patch

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
index dfb401df138a..95e490532a87 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c
@@ -653,8 +653,12 @@  static void cedrus_h264_stop(struct cedrus_ctx *ctx)
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
-	for (i = 0; i < vq->num_buffers; i++) {
-		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
+	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
+		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
+
+		if (!vb)
+			continue;
+		buf = vb2_to_cedrus_buffer(vb);
 
 		if (buf->codec.h264.mv_col_buf_size > 0) {
 			dma_free_attrs(dev->dev,
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
index fc9297232456..52e94c8f2f01 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
@@ -869,8 +869,13 @@  static void cedrus_h265_stop(struct cedrus_ctx *ctx)
 
 	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
-	for (i = 0; i < vq->num_buffers; i++) {
-		buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i));
+	for (i = 0; i < vb2_get_num_buffers(vq); i++) {
+		struct vb2_buffer *vb = vb2_get_buffer(vq, i);
+
+		if (!vb)
+			continue;
+
+		buf = vb2_to_cedrus_buffer(vb);
 
 		if (buf->codec.h265.mv_col_buf_size > 0) {
 			dma_free_attrs(dev->dev,