linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: media: atomisp: pci: Replace bytes macros with functions
@ 2023-01-17 15:08 Brent Pappas
  2023-01-17 15:34 ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Brent Pappas @ 2023-01-17 15:08 UTC (permalink / raw)
  To: hdegoede
  Cc: mchehab, ailus, gregkh, andy, error27, linux-media,
	linux-staging, linux-kernel, Brent Pappas

Replace the function-like macros FPNTBL_BYTES, SCTBL_BYTES, and
MORPH_PLANE_BYTES with static inline functions to comply with Linux coding
style standards.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
 .../staging/media/atomisp/pci/sh_css_params.c | 34 +++++++++++--------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..fe28d75a62a4 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] staging: media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 15:08 [PATCH] staging: media: atomisp: pci: Replace bytes macros with functions Brent Pappas
@ 2023-01-17 15:34 ` Andy Shevchenko
  2023-01-17 15:35   ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-17 15:34 UTC (permalink / raw)
  To: Brent Pappas
  Cc: hdegoede, mchehab, ailus, gregkh, error27, linux-media,
	linux-staging, linux-kernel

On Tue, Jan 17, 2023 at 10:08:41AM -0500, Brent Pappas wrote:
> Replace the function-like macros FPNTBL_BYTES, SCTBL_BYTES, and
> MORPH_PLANE_BYTES with 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.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] staging: media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 15:34 ` Andy Shevchenko
@ 2023-01-17 15:35   ` Andy Shevchenko
  2023-01-17 16:16     ` [PATCH v2] " Brent Pappas
  0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-17 15:35 UTC (permalink / raw)
  To: Brent Pappas
  Cc: hdegoede, mchehab, ailus, gregkh, error27, linux-media,
	linux-staging, linux-kernel

On Tue, Jan 17, 2023 at 05:34:12PM +0200, Andy Shevchenko wrote:
> On Tue, Jan 17, 2023 at 10:08:41AM -0500, Brent Pappas wrote:
> > Replace the function-like macros FPNTBL_BYTES, SCTBL_BYTES, and
> > MORPH_PLANE_BYTES with 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.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2] media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 15:35   ` Andy Shevchenko
@ 2023-01-17 16:16     ` Brent Pappas
  2023-01-17 18:08       ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Brent Pappas @ 2023-01-17 16:16 UTC (permalink / raw)
  To: andy
  Cc: ailus, bpappas, error27, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

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 (error27@gmail.com) recommended that I do so in reply to an earlier
patch I submitted.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
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(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..7e111df5c09d 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 16:16     ` [PATCH v2] " Brent Pappas
@ 2023-01-17 18:08       ` Andy Shevchenko
  2023-01-17 18:31         ` [PATCH v3] " Brent Pappas
  0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-17 18:08 UTC (permalink / raw)
  To: Brent Pappas
  Cc: andy, ailus, error27, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

On Tue, Jan 17, 2023 at 6:17 PM Brent Pappas <bpappas@pappasbrent.com> wrote:
>
> 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 (error27@gmail.com) 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).

...

> +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.

> +}

...

> +       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.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3] media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 18:08       ` Andy Shevchenko
@ 2023-01-17 18:31         ` Brent Pappas
  2023-01-17 18:37           ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Brent Pappas @ 2023-01-17 18:31 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: ailus, andy, bpappas, error27, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

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.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
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(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..7e111df5c09d 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 18:31         ` [PATCH v3] " Brent Pappas
@ 2023-01-17 18:37           ` Andy Shevchenko
  2023-01-18 14:42             ` [PATCH v4] " Brent Pappas
  0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-17 18:37 UTC (permalink / raw)
  To: Brent Pappas
  Cc: ailus, error27, gregkh, hdegoede, linux-kernel, linux-media,
	linux-staging, mchehab

On Tue, Jan 17, 2023 at 01:31:52PM -0500, Brent Pappas wrote:

Read to the end this message, please!

> 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.

We refer to MACRO() and func() as depicted.
Otherwise looks good.

...

> 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.

You missed my other comments. Please, read reply in full and address all
reviewer's comments.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v4] media: atomisp: pci: Replace bytes macros with functions
  2023-01-17 18:37           ` Andy Shevchenko
@ 2023-01-18 14:42             ` Brent Pappas
  2023-01-18 14:56               ` Dan Carpenter
  0 siblings, 1 reply; 16+ messages in thread
From: Brent Pappas @ 2023-01-18 14:42 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: ailus, bpappas, error27, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

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.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
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(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..7e111df5c09d 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 14:42             ` [PATCH v4] " Brent Pappas
@ 2023-01-18 14:56               ` Dan Carpenter
  2023-01-18 15:16                 ` [PATCH v5] " Brent Pappas
  0 siblings, 1 reply; 16+ messages in thread
From: Dan Carpenter @ 2023-01-18 14:56 UTC (permalink / raw)
  To: Brent Pappas
  Cc: andy.shevchenko, ailus, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

On Wed, Jan 18, 2023 at 09:42:26AM -0500, Brent Pappas wrote:
> 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.
> 
> Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
> ---
> 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(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
> index f08564f58242..7e111df5c09d 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
> @@ -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);

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



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 14:56               ` Dan Carpenter
@ 2023-01-18 15:16                 ` Brent Pappas
  2023-01-18 15:26                   ` Dan Carpenter
  2023-01-18 15:53                   ` Andy Shevchenko
  0 siblings, 2 replies; 16+ messages in thread
From: Brent Pappas @ 2023-01-18 15:16 UTC (permalink / raw)
  To: error27
  Cc: ailus, andy.shevchenko, bpappas, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

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.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
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(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..7e111df5c09d 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 15:16                 ` [PATCH v5] " Brent Pappas
@ 2023-01-18 15:26                   ` Dan Carpenter
  2023-01-18 15:53                   ` Andy Shevchenko
  1 sibling, 0 replies; 16+ messages in thread
From: Dan Carpenter @ 2023-01-18 15:26 UTC (permalink / raw)
  To: Brent Pappas
  Cc: ailus, andy.shevchenko, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

On Wed, Jan 18, 2023 at 10:16:56AM -0500, Brent Pappas wrote:
> 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.
> 
> Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
> ---
> 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(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
> index f08564f58242..7e111df5c09d 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
> @@ -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);

Nope.

> +}
>  
> -#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.

> +}
>  
> -#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.

> +}

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 15:16                 ` [PATCH v5] " Brent Pappas
  2023-01-18 15:26                   ` Dan Carpenter
@ 2023-01-18 15:53                   ` Andy Shevchenko
  2023-01-18 16:07                     ` [PATCH v6] " Brent Pappas
  1 sibling, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-18 15:53 UTC (permalink / raw)
  To: Brent Pappas
  Cc: error27, ailus, gregkh, hdegoede, linux-kernel, linux-media,
	linux-staging, mchehab

On Wed, Jan 18, 2023 at 5:17 PM Brent Pappas <bpappas@pappasbrent.com> wrote:
>
> 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.

...

> +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.

> +                                         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!

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 15:53                   ` Andy Shevchenko
@ 2023-01-18 16:07                     ` Brent Pappas
  2023-01-18 16:17                       ` Andy Shevchenko
  2023-01-23 12:27                       ` Hans de Goede
  0 siblings, 2 replies; 16+ messages in thread
From: Brent Pappas @ 2023-01-18 16:07 UTC (permalink / raw)
  To: andy.shevchenko
  Cc: ailus, bpappas, error27, gregkh, hdegoede, linux-kernel,
	linux-media, linux-staging, mchehab

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.

Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
---
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(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index f08564f58242..7e111df5c09d 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 16:07                     ` [PATCH v6] " Brent Pappas
@ 2023-01-18 16:17                       ` Andy Shevchenko
  2023-01-18 17:41                         ` Brent Pappas
  2023-01-23 12:27                       ` Hans de Goede
  1 sibling, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2023-01-18 16:17 UTC (permalink / raw)
  To: Brent Pappas
  Cc: ailus, error27, gregkh, hdegoede, linux-kernel, linux-media,
	linux-staging, mchehab

On Wed, Jan 18, 2023 at 6:08 PM Brent Pappas <bpappas@pappasbrent.com> wrote:
>
> 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.

In my MUA I don't clearly see if indentations are really being fixed,
assuming that
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Thank you and keep going!

> Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
> ---
> 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(-)
>
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
> index f08564f58242..7e111df5c09d 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
> @@ -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
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 16:17                       ` Andy Shevchenko
@ 2023-01-18 17:41                         ` Brent Pappas
  0 siblings, 0 replies; 16+ messages in thread
From: Brent Pappas @ 2023-01-18 17:41 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: ailus, error27, gregkh, hdegoede, linux-kernel, linux-media,
	linux-staging, mchehab

> 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.

> Thank you and keep going!

Thank you for your patience.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
  2023-01-18 16:07                     ` [PATCH v6] " Brent Pappas
  2023-01-18 16:17                       ` Andy Shevchenko
@ 2023-01-23 12:27                       ` Hans de Goede
  1 sibling, 0 replies; 16+ messages in thread
From: Hans de Goede @ 2023-01-23 12:27 UTC (permalink / raw)
  To: Brent Pappas, andy.shevchenko
  Cc: ailus, error27, gregkh, linux-kernel, linux-media, linux-staging,
	mchehab

Hi,

On 1/18/23 17:07, Brent Pappas wrote:
> 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.
> 
> Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>

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




> ---
> 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(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
> index f08564f58242..7e111df5c09d 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
> @@ -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) {


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-01-23 12:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 15:08 [PATCH] staging: media: atomisp: pci: Replace bytes macros with functions Brent Pappas
2023-01-17 15:34 ` Andy Shevchenko
2023-01-17 15:35   ` Andy Shevchenko
2023-01-17 16:16     ` [PATCH v2] " Brent Pappas
2023-01-17 18:08       ` Andy Shevchenko
2023-01-17 18:31         ` [PATCH v3] " Brent Pappas
2023-01-17 18:37           ` Andy Shevchenko
2023-01-18 14:42             ` [PATCH v4] " Brent Pappas
2023-01-18 14:56               ` Dan Carpenter
2023-01-18 15:16                 ` [PATCH v5] " Brent Pappas
2023-01-18 15:26                   ` Dan Carpenter
2023-01-18 15:53                   ` Andy Shevchenko
2023-01-18 16:07                     ` [PATCH v6] " Brent Pappas
2023-01-18 16:17                       ` Andy Shevchenko
2023-01-18 17:41                         ` Brent Pappas
2023-01-23 12:27                       ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).