From: Hans de Goede <hdegoede@redhat.com>
To: Brent Pappas <bpappas@pappasbrent.com>, andy.shevchenko@gmail.com
Cc: ailus@linux.intel.com, error27@gmail.com,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
mchehab@kernel.org
Subject: Re: [PATCH v6] media: atomisp: pci: Replace bytes macros with functions
Date: Mon, 23 Jan 2023 13:27:53 +0100 [thread overview]
Message-ID: <cba8bfbf-187d-3ba2-3d2d-cdac88fa9362@redhat.com> (raw)
In-Reply-To: <20230118160739.26059-1-bpappas@pappasbrent.com>
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) {
prev parent reply other threads:[~2023-01-23 12:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cba8bfbf-187d-3ba2-3d2d-cdac88fa9362@redhat.com \
--to=hdegoede@redhat.com \
--cc=ailus@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=bpappas@pappasbrent.com \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).