[PATCH 1/5] drm/solomon: Move calls to drm_gem_fb_end_cpu*()

Iker Pedrosa posted 5 patches 2 weeks, 6 days ago
[PATCH 1/5] drm/solomon: Move calls to drm_gem_fb_end_cpu*()
Posted by Iker Pedrosa 2 weeks, 6 days ago
Calls to drm_gem_fb_end_cpu*() should be between the calls to
drm_dev*(), and not hidden inside some other function. This way the
critical section code is visible at a glance, keeping it short and
improving maintainability.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
---
 drivers/gpu/drm/solomon/ssd130x.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c
index dd2006d51c7a2fc8501904565da806aa47333ad6..297593c7fd20a5a5da81f1e1fcfda9092b19cf90 100644
--- a/drivers/gpu/drm/solomon/ssd130x.c
+++ b/drivers/gpu/drm/solomon/ssd130x.c
@@ -1016,15 +1016,9 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb,
 
 	dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), 8);
 
-	ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
-	if (ret)
-		return ret;
-
 	iosys_map_set_vaddr(&dst, buf);
 	drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect, fmtcnv_state);
 
-	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
-
 	ssd130x_update_rect(ssd130x, rect, buf, data_array);
 
 	return ret;
@@ -1048,15 +1042,9 @@ static int ssd132x_fb_blit_rect(struct drm_framebuffer *fb,
 
 	dst_pitch = drm_rect_width(rect);
 
-	ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
-	if (ret)
-		return ret;
-
 	iosys_map_set_vaddr(&dst, buf);
 	drm_fb_xrgb8888_to_gray8(&dst, &dst_pitch, vmap, fb, rect, fmtcnv_state);
 
-	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
-
 	ssd132x_update_rect(ssd130x, rect, buf, data_array);
 
 	return ret;
@@ -1078,15 +1066,9 @@ static int ssd133x_fb_blit_rect(struct drm_framebuffer *fb,
 
 	dst_pitch = drm_format_info_min_pitch(fi, 0, drm_rect_width(rect));
 
-	ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
-	if (ret)
-		return ret;
-
 	iosys_map_set_vaddr(&dst, data_array);
 	drm_fb_xrgb8888_to_rgb332(&dst, &dst_pitch, vmap, fb, rect, fmtcnv_state);
 
-	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
-
 	ssd133x_update_rect(ssd130x, rect, data_array, dst_pitch);
 
 	return ret;
@@ -1232,6 +1214,9 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
 	if (!drm_dev_enter(drm, &idx))
 		return;
 
+	if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
+		return;
+
 	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
 	drm_atomic_for_each_plane_damage(&iter, &damage) {
 		dst_clip = plane_state->dst;
@@ -1245,6 +1230,8 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
 				     &shadow_plane_state->fmtcnv_state);
 	}
 
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+
 	drm_dev_exit(idx);
 }
 
@@ -1267,6 +1254,9 @@ static void ssd132x_primary_plane_atomic_update(struct drm_plane *plane,
 	if (!drm_dev_enter(drm, &idx))
 		return;
 
+	if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
+		return;
+
 	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
 	drm_atomic_for_each_plane_damage(&iter, &damage) {
 		dst_clip = plane_state->dst;
@@ -1280,6 +1270,8 @@ static void ssd132x_primary_plane_atomic_update(struct drm_plane *plane,
 				     &shadow_plane_state->fmtcnv_state);
 	}
 
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+
 	drm_dev_exit(idx);
 }
 
@@ -1301,6 +1293,9 @@ static void ssd133x_primary_plane_atomic_update(struct drm_plane *plane,
 	if (!drm_dev_enter(drm, &idx))
 		return;
 
+	if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
+		return;
+
 	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
 	drm_atomic_for_each_plane_damage(&iter, &damage) {
 		dst_clip = plane_state->dst;
@@ -1313,6 +1308,8 @@ static void ssd133x_primary_plane_atomic_update(struct drm_plane *plane,
 				     &shadow_plane_state->fmtcnv_state);
 	}
 
+	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
+
 	drm_dev_exit(idx);
 }
 

-- 
2.51.0
Re: [PATCH 1/5] drm/solomon: Move calls to drm_gem_fb_end_cpu*()
Posted by Javier Martinez Canillas 2 weeks, 1 day ago
Iker Pedrosa <ikerpedrosam@gmail.com> writes:

Hello Iker,

Thanks for your patch.

> Calls to drm_gem_fb_end_cpu*() should be between the calls to
> drm_dev*(), and not hidden inside some other function. This way the
> critical section code is visible at a glance, keeping it short and
> improving maintainability.
>
> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
> ---
>  drivers/gpu/drm/solomon/ssd130x.c | 33 +++++++++++++++------------------
>  1 file changed, 15 insertions(+), 18 deletions(-)
>

[...]

> @@ -1232,6 +1214,9 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
>  	if (!drm_dev_enter(drm, &idx))
>  		return;
>  
> +	if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
> +		return;
> +

In this error path you should call drm_dev_exit(). The convention in the
kernel usually is to have a goto label for this, e.g.:

       if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
              goto out_drm_dev_exit;

>  	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
>  	drm_atomic_for_each_plane_damage(&iter, &damage) {
>  		dst_clip = plane_state->dst;
> @@ -1245,6 +1230,8 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
>  				     &shadow_plane_state->fmtcnv_state);
>  	}
>  
> +	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
> +

and then here before the call you could have the label.

out_drm_dev_exit:

>  	drm_dev_exit(idx);

Same comments for the other places where you are adding the
drm_gem_fb_end_cpu*() calls next to the drm_dev*() ones.

After the mentioned changes:

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
Re: [PATCH 1/5] drm/solomon: Move calls to drm_gem_fb_end_cpu*()
Posted by Thomas Zimmermann 2 weeks, 1 day ago
grr, I should have noticed that before giving the r-b

Am 17.09.25 um 11:06 schrieb Javier Martinez Canillas:
> Iker Pedrosa <ikerpedrosam@gmail.com> writes:
>
> Hello Iker,
>
> Thanks for your patch.
>
>> Calls to drm_gem_fb_end_cpu*() should be between the calls to
>> drm_dev*(), and not hidden inside some other function. This way the
>> critical section code is visible at a glance, keeping it short and
>> improving maintainability.
>>
>> Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
>> ---
>>   drivers/gpu/drm/solomon/ssd130x.c | 33 +++++++++++++++------------------
>>   1 file changed, 15 insertions(+), 18 deletions(-)
>>
> [...]
>
>> @@ -1232,6 +1214,9 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
>>   	if (!drm_dev_enter(drm, &idx))
>>   		return;
>>   
>> +	if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
>> +		return;
>> +
> In this error path you should call drm_dev_exit(). The convention in the
> kernel usually is to have a goto label for this, e.g.:
>
>         if (drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE))
>                goto out_drm_dev_exit;
>
>>   	drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
>>   	drm_atomic_for_each_plane_damage(&iter, &damage) {
>>   		dst_clip = plane_state->dst;
>> @@ -1245,6 +1230,8 @@ static void ssd130x_primary_plane_atomic_update(struct drm_plane *plane,
>>   				     &shadow_plane_state->fmtcnv_state);
>>   	}
>>   
>> +	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
>> +
> and then here before the call you could have the label.
>
> out_drm_dev_exit:
>
>>   	drm_dev_exit(idx);
> Same comments for the other places where you are adding the
> drm_gem_fb_end_cpu*() calls next to the drm_dev*() ones.
>
> After the mentioned changes:
>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)