Skip to contentSkip to conversation

drm/vc4: fix a bounds check

PATCH In review Dan Carpenter 3 participants 4 messages Jan 13, 2017 – Jan 17, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vc4: fix a bounds check

We accidentally return success even if vc4_full_res_bounds_check() fails.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")

---
Not tested.

drivers/gpu/drm/vc4/vc4_render_cl.c +1 -1
index 08886a3..5cdd003 100644
@@ -461,7 +461,7 @@ static int vc4_rcl_surface_setup(struct vc4_exec_info *exec,
 		}
 
 		ret = vc4_full_res_bounds_check(exec, *obj, surf);
-		if (!ret)
+		if (ret)
 			return ret;
 
 		return 0;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

We accidentally return success even if vc4_full_res_bounds_check() fails.

Fixes d5b1a78a772f ("drm/vc4: Add support for drawing 3D frames.")

---
Not tested.

It would be good to test it, but the previous code would always return 0, and from a quick look the callers expect non-zero values on error, so this makes more sense at least.

Quoted 6 lines
drivers/gpu/drm/vc4/vc4_render_cl.c +0 -0
index 08886a3..5cdd003 100644

drivers/gpu/drm/vc4/vc4_render_cl.c static int vc4_rcl_surface_setup(struct vc4_exec_info *exec, · line 467

Quoted 8 lines
drivers/gpu/drm/vc4/vc4_render_cl.c +1 -1
@@ -461,7 +461,7 @@ static int vc4_rcl_surface_setup(struct vc4_exec_info *exec,
 		}
 
 		ret = vc4_full_res_bounds_check(exec, *obj, surf);
-		if (!ret)
+		if (ret)
 			return ret;
 
 		return 0;

This now boils down to return vc4_full_res_bounds_check(...);, so you could get rid of the ret variable completely :)

#2 lore raw
Quoted 12 lines · Eric Engestrom
Quoted 12 lines
drivers/gpu/drm/vc4/vc4_render_cl.c +1 -1
index 08886a3..5cdd003 100644
@@ -461,7 +461,7 @@ static int vc4_rcl_surface_setup(struct vc4_exec_info *exec,
 		}
 
 		ret = vc4_full_res_bounds_check(exec, *obj, surf);
-		if (!ret)
+		if (ret)
 			return ret;
 
Quoted 4 lines

drivers/gpu/drm/vc4/vc4_render_cl.c static int vc4_rcl_surface_setup(struct vc4_exec_info *exec, · line 467

Quoted 1 line
drivers/gpu/drm/vc4/vc4_render_cl.c +0 -0
 		return 0;

This now boils down to return vc4_full_res_bounds_check(...);, so you could get rid of the ret variable completely :)

I tried to leave it the original style which the author intended. That's also my prefered style. I like big chunky "return 0;". I actually found this bug by looking at places where people return a variable where a literal would work:

	if (!ret)
		return ret;

It's ambiguos if they intended to return a negative, or if they condition is reversed. The other reason why I slightly prefer his style is because people get so "clever" with the last condition in a function and it drives me nuts. They'll do a series of checks like this:

	if (fail)
		goto;
	if (fail)
		goto;
	if (fail)
		goto;
	if (success)
		return;

label:

We should be testing for failure generally, but this particular kind of success check is like nails on a chalk board for me. My younger self is guilty of this cleverness as well....

Of course, the other way: "return vc4_full_res_bounds_check();" is fine too. It's not something that bothers me. I guess I just would do whatever the original author prefers.

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html