* [PATCH] drm/amd/display: Use 2-factor allocator calls
@ 2018-07-04 17:27 Kees Cook
2018-07-04 17:53 ` Harry Wentland
2018-07-05 13:37 ` Michel Dänzer
0 siblings, 2 replies; 7+ messages in thread
From: Kees Cook @ 2018-07-04 17:27 UTC (permalink / raw)
To: Alex Deucher
Cc: Vitaly Prosyak, Tony Cheng, Harry Wentland, amd-gfx, dri-devel,
linux-kernel
As already done treewide, switch from open-coded multiplication to
2-factor allocation helper.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
index 98edaefa2b47..ee69c949bfbf 100644
--- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
+++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
@@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
kvfree(rgb_regamma);
} else if (trans == TRANSFER_FUNCTION_HLG ||
trans == TRANSFER_FUNCTION_HLG12) {
- rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
- (MAX_HW_POINTS + _EXTRA_POINTS),
+ rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
+ sizeof(*rgb_regamma),
GFP_KERNEL);
if (!rgb_regamma)
goto rgb_regamma_alloc_fail;
@@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
kvfree(rgb_degamma);
} else if (trans == TRANSFER_FUNCTION_HLG ||
trans == TRANSFER_FUNCTION_HLG12) {
- rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
- (MAX_HW_POINTS + _EXTRA_POINTS),
+ rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
+ sizeof(*rgb_degamma),
GFP_KERNEL);
if (!rgb_degamma)
goto rgb_degamma_alloc_fail;
--
2.17.1
--
Kees Cook
Pixel Security
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
2018-07-04 17:27 [PATCH] drm/amd/display: Use 2-factor allocator calls Kees Cook
@ 2018-07-04 17:53 ` Harry Wentland
2018-07-05 13:37 ` Michel Dänzer
1 sibling, 0 replies; 7+ messages in thread
From: Harry Wentland @ 2018-07-04 17:53 UTC (permalink / raw)
To: Kees Cook, Alex Deucher
Cc: Vitaly Prosyak, Tony Cheng, amd-gfx, dri-devel, linux-kernel
On 2018-07-04 01:27 PM, Kees Cook wrote:
> As already done treewide, switch from open-coded multiplication to
> 2-factor allocation helper.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Harry
> ---
> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> index 98edaefa2b47..ee69c949bfbf 100644
> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_regamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_regamma),
> GFP_KERNEL);
> if (!rgb_regamma)
> goto rgb_regamma_alloc_fail;
> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_degamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_degamma),
> GFP_KERNEL);
> if (!rgb_degamma)
> goto rgb_degamma_alloc_fail;
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
@ 2018-07-04 17:53 ` Harry Wentland
0 siblings, 0 replies; 7+ messages in thread
From: Harry Wentland @ 2018-07-04 17:53 UTC (permalink / raw)
To: Kees Cook, Alex Deucher
Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Tony Cheng,
Vitaly Prosyak, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On 2018-07-04 01:27 PM, Kees Cook wrote:
> As already done treewide, switch from open-coded multiplication to
> 2-factor allocation helper.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Harry
> ---
> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> index 98edaefa2b47..ee69c949bfbf 100644
> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_regamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_regamma),
> GFP_KERNEL);
> if (!rgb_regamma)
> goto rgb_regamma_alloc_fail;
> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_degamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_degamma),
> GFP_KERNEL);
> if (!rgb_degamma)
> goto rgb_degamma_alloc_fail;
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
2018-07-04 17:27 [PATCH] drm/amd/display: Use 2-factor allocator calls Kees Cook
@ 2018-07-05 13:37 ` Michel Dänzer
2018-07-05 13:37 ` Michel Dänzer
1 sibling, 0 replies; 7+ messages in thread
From: Michel Dänzer @ 2018-07-05 13:37 UTC (permalink / raw)
To: Kees Cook, Alex Deucher
Cc: amd-gfx, Tony Cheng, linux-kernel, dri-devel, Vitaly Prosyak,
Harry Wentland
On 2018-07-04 07:27 PM, Kees Cook wrote:
> As already done treewide, switch from open-coded multiplication to
> 2-factor allocation helper.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> index 98edaefa2b47..ee69c949bfbf 100644
> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_regamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_regamma),
> GFP_KERNEL);
> if (!rgb_regamma)
> goto rgb_regamma_alloc_fail;
> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_degamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_degamma),
> GFP_KERNEL);
> if (!rgb_degamma)
> goto rgb_degamma_alloc_fail;
>
Since the values are constant, kvcalloc incurs the overflow checking
overhead for no gain.
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
@ 2018-07-05 13:37 ` Michel Dänzer
0 siblings, 0 replies; 7+ messages in thread
From: Michel Dänzer @ 2018-07-05 13:37 UTC (permalink / raw)
To: Kees Cook, Alex Deucher
Cc: Tony Cheng, linux-kernel, dri-devel, amd-gfx, Vitaly Prosyak
On 2018-07-04 07:27 PM, Kees Cook wrote:
> As already done treewide, switch from open-coded multiplication to
> 2-factor allocation helper.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> index 98edaefa2b47..ee69c949bfbf 100644
> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_regamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_regamma),
> GFP_KERNEL);
> if (!rgb_regamma)
> goto rgb_regamma_alloc_fail;
> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
> kvfree(rgb_degamma);
> } else if (trans == TRANSFER_FUNCTION_HLG ||
> trans == TRANSFER_FUNCTION_HLG12) {
> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
> - (MAX_HW_POINTS + _EXTRA_POINTS),
> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
> + sizeof(*rgb_degamma),
> GFP_KERNEL);
> if (!rgb_degamma)
> goto rgb_degamma_alloc_fail;
>
Since the values are constant, kvcalloc incurs the overflow checking
overhead for no gain.
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
2018-07-05 13:37 ` Michel Dänzer
@ 2018-07-05 15:55 ` Kees Cook
-1 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2018-07-05 15:55 UTC (permalink / raw)
To: Michel Dänzer
Cc: Alex Deucher, amd-gfx list, Tony Cheng, LKML,
Maling list - DRI developers, Vitaly Prosyak, Harry Wentland
On Thu, Jul 5, 2018 at 6:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> On 2018-07-04 07:27 PM, Kees Cook wrote:
>> As already done treewide, switch from open-coded multiplication to
>> 2-factor allocation helper.
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> index 98edaefa2b47..ee69c949bfbf 100644
>> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
>> kvfree(rgb_regamma);
>> } else if (trans == TRANSFER_FUNCTION_HLG ||
>> trans == TRANSFER_FUNCTION_HLG12) {
>> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
>> - (MAX_HW_POINTS + _EXTRA_POINTS),
>> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
>> + sizeof(*rgb_regamma),
>> GFP_KERNEL);
>> if (!rgb_regamma)
>> goto rgb_regamma_alloc_fail;
>> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
>> kvfree(rgb_degamma);
>> } else if (trans == TRANSFER_FUNCTION_HLG ||
>> trans == TRANSFER_FUNCTION_HLG12) {
>> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
>> - (MAX_HW_POINTS + _EXTRA_POINTS),
>> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
>> + sizeof(*rgb_degamma),
>> GFP_KERNEL);
>> if (!rgb_degamma)
>> goto rgb_degamma_alloc_fail;
>>
>
> Since the values are constant, kvcalloc incurs the overflow checking
> overhead for no gain.
The way the macros are designed, they'll get entirely optimized away
in that case:
http://lkml.kernel.org/r/CAGXu5jLw9kMZRkzL_Q7JdyyprntHF6bdVSE_vjyzect3CenDng@mail.gmail.com
Using this patch means if the code ever changes away from constants,
it'll still be safe. And static checkers won't yell about the
open-coded multiplication here. So it's only up-sides. :)
-Kees
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] drm/amd/display: Use 2-factor allocator calls
@ 2018-07-05 15:55 ` Kees Cook
0 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2018-07-05 15:55 UTC (permalink / raw)
To: Michel Dänzer
Cc: Alex Deucher, amd-gfx list, Tony Cheng, LKML,
Maling list - DRI developers, Vitaly Prosyak, Harry Wentland
On Thu, Jul 5, 2018 at 6:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> On 2018-07-04 07:27 PM, Kees Cook wrote:
>> As already done treewide, switch from open-coded multiplication to
>> 2-factor allocation helper.
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> index 98edaefa2b47..ee69c949bfbf 100644
>> --- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> +++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
>> @@ -1723,8 +1723,8 @@ bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
>> kvfree(rgb_regamma);
>> } else if (trans == TRANSFER_FUNCTION_HLG ||
>> trans == TRANSFER_FUNCTION_HLG12) {
>> - rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
>> - (MAX_HW_POINTS + _EXTRA_POINTS),
>> + rgb_regamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
>> + sizeof(*rgb_regamma),
>> GFP_KERNEL);
>> if (!rgb_regamma)
>> goto rgb_regamma_alloc_fail;
>> @@ -1802,8 +1802,8 @@ bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
>> kvfree(rgb_degamma);
>> } else if (trans == TRANSFER_FUNCTION_HLG ||
>> trans == TRANSFER_FUNCTION_HLG12) {
>> - rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
>> - (MAX_HW_POINTS + _EXTRA_POINTS),
>> + rgb_degamma = kvcalloc(MAX_HW_POINTS + _EXTRA_POINTS,
>> + sizeof(*rgb_degamma),
>> GFP_KERNEL);
>> if (!rgb_degamma)
>> goto rgb_degamma_alloc_fail;
>>
>
> Since the values are constant, kvcalloc incurs the overflow checking
> overhead for no gain.
The way the macros are designed, they'll get entirely optimized away
in that case:
http://lkml.kernel.org/r/CAGXu5jLw9kMZRkzL_Q7JdyyprntHF6bdVSE_vjyzect3CenDng@mail.gmail.com
Using this patch means if the code ever changes away from constants,
it'll still be safe. And static checkers won't yell about the
open-coded multiplication here. So it's only up-sides. :)
-Kees
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-07-05 15:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-04 17:27 [PATCH] drm/amd/display: Use 2-factor allocator calls Kees Cook
2018-07-04 17:53 ` Harry Wentland
2018-07-04 17:53 ` Harry Wentland
2018-07-05 13:37 ` Michel Dänzer
2018-07-05 13:37 ` Michel Dänzer
2018-07-05 15:55 ` Kees Cook
2018-07-05 15:55 ` Kees Cook
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.