staging: media: atomisp: pci: Replace bytes macros with functions
Subsystems (4)
PATCH 1/1 staging: media: atomisp: pci: Replace bytes macros with functions
Replace the function-like macros FPNTBL_BYTES, SCTBL_BYTES, and MORPH_PLANE_BYTES with static inline functions to comply with Linux coding style standards.
--- .../staging/media/atomisp/pci/sh_css_params.c | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +19 -15
@@ -98,17 +98,23 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static inline size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return (sizeof (char ) * binary->in_frame_info.res.height * + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static inline size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return (sizeof (unsigned short ) * binary->sctbl_height * + binary->sctbl_aligned_width_per_color *IA_CSS_SC_NUM_COLORS ); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static inline size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return (SH_CSS_MORPH_TABLE_ELEM_BYTES * + binary->morph_tbl_aligned_width * binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3285,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3310,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3544,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3554,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Andy Shevchenko
maintainerQuoted 3 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES,SCTBL_BYTES, andMORPH_PLANE_BYTESwith static inline functions to comply with Linux coding style standards.
Thank you!
But I think what you need, besides dropping unneeded parentheses is to use some macros from overflow.h.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
maintainerQuoted 9 lines · Andy Shevchenko
Quoted 3 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES,SCTBL_BYTES, andMORPH_PLANE_BYTESwith static inline functions to comply with Linux coding style standards.Thank you!
But I think what you need, besides dropping unneeded parentheses, is to use some macros from
overflow.h.
And drop "staging:" prefix from the patch since media maintainer uses (dumb) script that adds "media:" if it doesn't lead the Subject.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 1/1 media: atomisp: pci: Replace bytes macros with functions
Thank you for the advice Andy.
I took a look in overflow.h and found the size_mul function, I assume this is what I should be using to prevent accidental overflow.
I also removed the inline keyword from the function definitions because Dan ([email protected]) recommended that I do so in reply to an earlier patch I submitted.
---
Changelog:
V1 -> V2: Use size_mul to perform size_t multiplication without risk of
overflow.
Remove the inline keyword from function definitions.
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (char ), +size_mul (binary->in_frame_info.res.height, + binary->in_frame_info.padded_width)); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +size_mul (binary->sctbl_height, +size_mul (binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS ))); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return size_mul (SH_CSS_MORPH_TABLE_ELEM_BYTES , +size_mul (binary->morph_tbl_aligned_width, + binary->morph_tbl_height)); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v2] media: atomisp: pci: Replace bytes macros with functions
Quoted 7 lines · Brent Pappas
Thank you for the advice Andy.
I took a look inoverflow.hand found thesize_mulfunction, I assume this is what I should be using to prevent accidental overflow.
I also removed the inline keyword from the function definitions because Dan ([email protected]) recommended that I do so in reply to an earlier patch I submitted.
Now you need to properly form a commit message. What you have done above is good for the comment (goes near to changelog).
...
drivers/staging/media/atomisp/pci/sh_css_params.c line 105
Quoted 5 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +5
-0+static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (char ), +size_mul (binary->in_frame_info.res.height, + binary->in_frame_info.padded_width));
I recommend using array_size() and array3_size() rather than open coding them.
Quoted 1 line
+}
...
drivers/staging/media/atomisp/pci/sh_css_params.c line 113
Quoted 5 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +4
-0+return size_mul (sizeof (unsigned short ), +size_mul (binary->sctbl_height, +size_mul (binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )));
array3_size()
and so on.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 1/1 media: atomisp: pci: Replace bytes macros with functions
Replace the function-like macros FPNTBL_BYTES, SCTBL_BYTES, and MORPH_PLANE_BYTES with static inline functions to comply with Linux coding style standards.
Replace multiplication with calls to size_mul to prevent accidental arithmetic overflow.
---
Changelog:
V1 -> V2: Use size_mul to perform size_t multiplication without risk of
overflow.
Remove the inline keyword from function definitions.
V2 -> V3: Add commit message.
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (char ), +size_mul (binary->in_frame_info.res.height, + binary->in_frame_info.padded_width)); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +size_mul (binary->sctbl_height, +size_mul (binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS ))); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return size_mul (SH_CSS_MORPH_TABLE_ELEM_BYTES , +size_mul (binary->morph_tbl_aligned_width, + binary->morph_tbl_height)); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v3] media: atomisp: pci: Replace bytes macros with functions
On Tue, Jan 17, 2023 at 01:31:52PM -0500, Brent Pappas wrote:
Read to the end this message, please!
Quoted 5 lines
Replace the function-like macros
FPNTBL_BYTES,SCTBL_BYTES, andMORPH_PLANE_BYTESwith static inline functions to comply with Linux coding style standards.
Replace multiplication with calls tosize_multo prevent accidental arithmetic overflow.
We refer to MACRO() and func() as depicted.
Otherwise looks good.
...
Quoted 6 lines
Changelog:
V1 -> V2: Usesize_multo performsize_tmultiplication without risk of
overflow.
Remove the inline keyword from function definitions.V2 -> V3: Add commit message.
You missed my other comments. Please, read reply in full and address all reviewer's comments.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 1/1 media: atomisp: pci: Replace bytes macros with functions
Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and MORPH_PLANE_BYTES() with functions to comply with Linux coding style standards.
Replace multiplication with calls to functions/macros from overflow.h to prevent accidental arithmetic overflow.
---
Changelog:
V1 -> V2: Use size_mul() to perform size_t multiplication without risk of
overflow.
Remove the inline keyword from function definitions.
V2 -> V3: Add commit message.
V3 -> V4: Use array_size() and array3_size() for multiplication.
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return array_size (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v4] media: atomisp: pci: Replace bytes macros with functions
Quoted 26 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES(),SCTBL_BYTES(), andMORPH_PLANE_BYTES()with functions to comply with Linux coding style standards.
Replace multiplication with calls to functions/macros fromoverflow.hto prevent accidental arithmetic overflow.Signed-off-by Brent Pappas <[email protected]>---
Changelog:
V1 -> V2: Usesize_mul()to performsize_tmultiplication without risk of
overflow.
Remove the inline keyword from function definitions.V2 -> V3: Add commit message.
V3 -> V4: Use
array_size()andarray3_size()for multiplication..../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)drivers/staging/media/atomisp/pci/sh_css_params.c +0
-0@@ -98,17 +98,27 @@#include "sh_css_frac.h"
drivers/staging/media/atomisp/pci/sh_css_params.c line 105
Quoted 10 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +5
-3#include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width);
This indenting is not correct. Do it the way that checkpatch.pl likes:
return array3_size(sizeof(char), binary->in_frame_info.res.height, binary->in_frame_info.padded_width);
[tab][tab][tab][space][space][space]binary->in_frame_info.res.height, [tab][tab][tab][space][space][space]binary->in_frame_info.padded_width);
(Same for the rest obviously)
regards,
dan carpenter
PATCH v5 1/1 media: atomisp: pci: Replace bytes macros with functions
Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and MORPH_PLANE_BYTES() with functions to comply with Linux coding style standards.
Replace multiplication with calls to array_size() and array3_size() to prevent accidental arithmetic overflow.
---
Changelog:
V1 -> V2: Use size_mul() to perform size_t multiplication without risk of
overflow.
Remove the inline keyword from function definitions.
V2 -> V3: Add commit message.
V3 -> V4: Use array_size() and array3_size() for multiplication.
V4 -> V5: Fix indentation.
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return array_size (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
Quoted 28 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES(),SCTBL_BYTES(), andMORPH_PLANE_BYTES()with functions to comply with Linux coding style standards.
Replace multiplication with calls toarray_size()andarray3_size()to prevent accidental arithmetic overflow.Signed-off-by Brent Pappas <[email protected]>---
Changelog:
V1 -> V2: Usesize_mul()to performsize_tmultiplication without risk of
overflow.
Remove the inline keyword from function definitions.V2 -> V3: Add commit message.
V3 -> V4: Use
array_size()andarray3_size()for multiplication.V4 -> V5: Fix indentation.
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)drivers/staging/media/atomisp/pci/sh_css_params.c +0
-0@@ -98,17 +98,27 @@#include "sh_css_frac.h"
drivers/staging/media/atomisp/pci/sh_css_params.c line 105
Quoted 10 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +5
-3#include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width);
Nope.
drivers/staging/media/atomisp/pci/sh_css_params.c line 113
Quoted 11 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +7
-3+} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return array_size (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS ));
Also nope.
drivers/staging/media/atomisp/pci/sh_css_params.c line 120
Quoted 10 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +6
-3+} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height);
Nope.
drivers/staging/media/atomisp/pci/sh_css_params.c line 121
Quoted 1 line
drivers/staging/media/atomisp/pci/sh_css_params.c +1
-0+}
regards,
dan carpenter
Re: [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
In reply to Brent PappasQuoted 6 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES(),SCTBL_BYTES(), andMORPH_PLANE_BYTES()with functions to comply with Linux coding style standards.
Replace multiplication with calls toarray_size()andarray3_size()to prevent accidental arithmetic overflow.
...
drivers/staging/media/atomisp/pci/sh_css_params.c line 110
Quoted 3 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +3
-0+static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ + return array_size(sizeof(unsigned short),
I would use size_mul() here, but either would work.
drivers/staging/media/atomisp/pci/sh_css_params.c line 114
Quoted 4 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +4
-0+array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, + IA_CSS_SC_NUM_COLORS)); +}
...
Please, fix indentations and patch will be good enough, thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v6 1/1 media: atomisp: pci: Replace bytes macros with functions
Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and MORPH_PLANE_BYTES() with functions to comply with Linux coding style standards.
Replace multiplication with calls to array_size() and array3_size() to prevent accidental arithmetic overflow.
---
Changelog:
V1 -> V2: Use size_mul() to perform size_t multiplication without risk of
overflow.
Remove the inline keyword from function definitions.
V2 -> V3: Add commit message.
V3 -> V4: Use array_size() and array3_size() for multiplication.
V4 -> V5: Fix indentation.
V5 -> V6: Try again to fix indentation (use tabs of size 8).
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.34.1
Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
Quoted 6 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES(),SCTBL_BYTES(), andMORPH_PLANE_BYTES()with functions to comply with Linux coding style standards.
Replace multiplication with calls toarray_size()andarray3_size()to prevent accidental arithmetic overflow.
In my MUA I don't clearly see if indentations are really being fixed, assuming that
Thank you and keep going!
Quoted 100 lines
Signed-off-by Brent Pappas <[email protected]>---
Changelog:
V1 -> V2: Usesize_mul()to performsize_tmultiplication without risk of
overflow.
Remove the inline keyword from function definitions.V2 -> V3: Add commit message.
V3 -> V4: Use
array_size()andarray3_size()for multiplication.V4 -> V5: Fix indentation.
V5 -> V6: Try again to fix indentation (use tabs of size 8).
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)drivers/staging/media/atomisp/pci/sh_css_params.c +23
-16@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */ @@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) { --2.34.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
Quoted 2 lines
In my MUA I don't clearly see if indentations are really being fixed, assuming that
The issue I was having was that my editor had tabs set to size 4. I switched them to size 8 and could see the issues that Dan was seeing. I've ran checkpatch.pl on the patch and it passes, but if you see an issue I will address it.
Quoted 1 line
Thank you and keep going!
Thank you for your patience.
Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
In reply to Brent PappasHi,
Quoted 7 lines · Brent Pappas
Replace the function-like macros
FPNTBL_BYTES(),SCTBL_BYTES(), andMORPH_PLANE_BYTES()with functions to comply with Linux coding style standards.
Replace multiplication with calls toarray_size()andarray3_size()to prevent accidental arithmetic overflow.Signed-off-by Brent Pappas <[email protected]>
Thank you.
I have added this to my personal git tree now and I will include this in the atomisp driver pull-req which I will send to the media-subsystem maintainer in a couple of weeks.
Regards,
Hans
Quoted 96 lines
---
Changelog:
V1 -> V2: Usesize_mul()to performsize_tmultiplication without risk of
overflow.
Remove the inline keyword from function definitions.V2 -> V3: Add commit message.
V3 -> V4: Use
array_size()andarray3_size()for multiplication.V4 -> V5: Fix indentation.
V5 -> V6: Try again to fix indentation (use tabs of size 8).
.../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)drivers/staging/media/atomisp/pci/sh_css_params.c +23
-15@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */ @@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {