Linux kernel staging patches
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Hans de Goede' <hdegoede@redhat.com>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>
Subject: RE: [PATCH] media: atomisp: Use clamp_t() in ia_css_eed1_8_vmem_encode()
Date: Fri, 6 Sep 2024 08:05:36 +0000	[thread overview]
Message-ID: <a9bc91f35f494fb1971229a2df419706@AcuMS.aculab.com> (raw)
In-Reply-To: <b37a0c60-55aa-44ec-b96c-68cdaabdc110@redhat.com>

From: Hans de Goede
> Sent: 06 September 2024 08:53
> 
> Hi Mauro,
> 
> On 9/6/24 8:15 AM, Mauro Carvalho Chehab wrote:
> > Em Sat, 27 Jul 2024 14:51:56 +0200
> > Christophe JAILLET <christophe.jaillet@wanadoo.fr> escreveu:
> >
> >> Using clamp_t() instead of min_t(max_t()) is easier to read.
> >>
> >> It also reduces the size of the preprocessed files by ~ 193 ko.
> >> (see [1] for a discussion about it)
> >>
> >> $ ls -l ia_css_eed1_8.host*.i
> >>  4829993 27 juil. 14:36 ia_css_eed1_8.host.old.i
> >>  4636649 27 juil. 14:42 ia_css_eed1_8.host.new.i
> >>
> >> [1]: https://lore.kernel.org/all/23bdb6fc8d884ceebeb6e8b8653b8cfe@AcuMS.aculab.com/
> >>
> >> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> >> ---
> >>  .../isp/kernels/eed1_8/ia_css_eed1_8.host.c   | 24 +++++++++----------
> >>  1 file changed, 12 insertions(+), 12 deletions(-)
> >>
> >> diff --git a/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> b/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> >> index e4fc90f88e24..96c13ebc4331 100644
> >> --- a/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> >> +++ b/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> >> @@ -172,25 +172,25 @@ ia_css_eed1_8_vmem_encode(
> >>  		base = shuffle_block * i;
> >>
> >>  		for (j = 0; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) {
> >> -			to->e_dew_enh_x[0][base + j] = min_t(int, max_t(int,
> >> -							     from->dew_enhance_seg_x[j], 0),
> >> -							     8191);
> >> -			to->e_dew_enh_y[0][base + j] = min_t(int, max_t(int,
> >> -							     from->dew_enhance_seg_y[j], -8192),
> >> -							     8191);
> >> +			to->e_dew_enh_x[0][base + j] = clamp_t(int,
> >> +							       from->dew_enhance_seg_x[j],
> >> +							       0, 8191);
> >> +			to->e_dew_enh_y[0][base + j] = clamp_t(int,
> >> +							       from->dew_enhance_seg_y[j],
> >> +							       -8192, 8191);
> >
> > Such change introduces two warnings on smatch:
> >
> > drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c:
> drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c:177
> ia_css_eed1_8_vmem_encode() warn: assigning (-8192) to unsigned variable 'to->e_dew_enh_y[0][base +
> j]'
> > drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c:
> drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c:182
> ia_css_eed1_8_vmem_encode() warn: assigning (-8192) to unsigned variable 'to->e_dew_enh_a[0][base +
> j]'
> >
> > Should dew_enhance_seg_x and dew_enhance_seg_y be converted to signed?
> 
> These already are s32, the problem is that e_dew_enh_a is of type t_vmem_elem which is:
> 
> typedef u16 t_vmem_elem;

Ugg... :-)

> 
> And that type is used in a lot of places, so we cannot
> just change that.
> 
> I guess we could add a t_signed_vmem_elem (s16) and use that for these vmem-arrays ?
> 
> I tried fixing it like this:
> 
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-t4ka3.c
> b/drivers/staging/media/atomisp/i2c/atomisp-t4ka3.c
> index 1e01d354152b..7c0195d15f53 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-t4ka3.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-t4ka3.c
> @@ -428,18 +428,13 @@ static int t4ka3_s_stream(struct v4l2_subdev *sd, int enable)
>  			goto error_unlock;
>  		}
> 
> -		ret = cci_multi_reg_write(sensor->regmap, t4ka3_init_config,
> -					  ARRAY_SIZE(t4ka3_init_config), NULL);
> -		if (ret)
> -			goto error_powerdown;
> -
> +		cci_multi_reg_write(sensor->regmap, t4ka3_init_config,
> +				    ARRAY_SIZE(t4ka3_init_config), &ret);
>  		/* enable group hold */
> -		ret = cci_multi_reg_write(sensor->regmap, t4ka3_param_hold,
> -					  ARRAY_SIZE(t4ka3_param_hold), NULL);
> -		if (ret)
> -			goto error_powerdown;
> -
> -		ret = cci_multi_reg_write(sensor->regmap, sensor->res->regs, sensor->res->regs_len, NULL);
> +		cci_multi_reg_write(sensor->regmap, t4ka3_param_hold,
> +				    ARRAY_SIZE(t4ka3_param_hold), &ret);
> +		cci_multi_reg_write(sensor->regmap, sensor->res->regs,
> +				    sensor->res->regs_len, &ret);
>  		if (ret)
>  			goto error_powerdown;

Isn't that unrelated?

> diff --git a/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> b/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> index b79d78e5b77f..c9043d516192 100644
> --- a/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> +++ b/drivers/staging/media/atomisp/pci/isp/kernels/eed1_8/ia_css_eed1_8.host.c
> @@ -172,21 +172,21 @@ ia_css_eed1_8_vmem_encode(
>  		base = shuffle_block * i;
> 
>  		for (j = 0; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) {
> -			to->e_dew_enh_x[0][base + j] = clamp(from->dew_enhance_seg_x[j],
> -							     0, 8191);
> -			to->e_dew_enh_y[0][base + j] = clamp(from->dew_enhance_seg_y[j],
> -							     -8192, 8191);
> +			to->e_dew_enh_x[0][base + j] = (u16)clamp(from->dew_enhance_seg_x[j],
> +								  0, 8191);
> +			to->e_dew_enh_y[0][base + j] = (u16)clamp(from->dew_enhance_seg_y[j],
> +								  -8192, 8191);

How about an explicit clamp(...) & 0xffffu?

> 
>  		for (j = 0; j < (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1); j++) {
> -			to->e_dew_enh_a[0][base + j] = clamp(from->dew_enhance_seg_slope[j],
> -							     -8192, 8191);
> +			to->e_dew_enh_a[0][base + j] = (u16)clamp(from->dew_enhance_seg_slope[j],
> +								  -8192, 8191);
>  			/* Convert dew_enhance_seg_exp to flag:
>  			 * 0 -> 0
>  			 * 1...13 -> 1
>  			 */
> -			to->e_dew_enh_f[0][base + j] = clamp(from->dew_enhance_seg_exp[j],
> -							     0, 13) > 0;
> +			to->e_dew_enh_f[0][base + j] = (u16)clamp(from->dew_enhance_seg_exp[j],
> +								  0, 13) > 0;

Isn't the RHS just from->dew_enhance_seg_exp[j] > 0 ?
That shouldn't be generating any kind of warning anyway.

	David

>  		}
> 
>  		/* Hard-coded to 0, in order to be able to handle out of
> 
> but smatch still complains after this...
> 
> Regards,
> 
> Hans
> 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2024-09-06  8:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-27 12:51 [PATCH] media: atomisp: Use clamp_t() in ia_css_eed1_8_vmem_encode() Christophe JAILLET
2024-07-28 11:09 ` David Laight
2024-09-02 10:02 ` Hans de Goede
2024-09-06  6:15 ` Mauro Carvalho Chehab
2024-09-06  7:53   ` Hans de Goede
2024-09-06  8:05     ` David Laight [this message]
2024-09-06 13:27       ` Hans de Goede
2024-09-06  7:56   ` David Laight
2024-09-06  8:01     ` Hans de Goede

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=a9bc91f35f494fb1971229a2df419706@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab+huawei@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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