lkml.org 
[lkml]   [2023]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5] media: atomisp: pci: Replace bytes macros with functions
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

\
 
 \ /
  Last update: 2023-03-26 23:46    [W:0.077 / U:0.940 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site