All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration
Date: Sun, 15 Nov 2026 08:46:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-215304@kernel.org> (raw)
In-Reply-To: <20261115083741.62140-2-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] iio: light: ltr501: out-of-bounds write in ltr501_probe() gain
  table init
--

commit 738578de8560e9585a0ad5b6cdbf8ce32003ccdc
Author: Svyatoslav Ryhel <clamor95@gmail.com>

iio: light: ltr501: Switch to read_avail() op from manual attribute registration

This commit switches the ltr501 driver from manual sysfs attribute group
registration to the IIO read_avail() callback and consolidates the
per-chip iio_info structures.

> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 24733607d1b49..3662aed5225bc 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c

[ ... ]

> @@ -164,6 +178,8 @@ struct ltr501_data {
>  	struct regmap_field *reg_als_prst;
>  	struct regmap_field *reg_ps_prst;
>  	uint32_t near_level;
> +	struct ltr501_gain als_gain_tbl[ARRAY_SIZE(ltr559_als_gain_tbl)];
> +	u32 als_gain_tbl_len;
>  };

[ ... ]

> @@ -1548,7 +1500,16 @@ static int ltr501_probe(struct i2c_client *client)
>  				     &data->near_level))
>  		data->near_level = 0;
>  
> -	indio_dev->info = data->chip_info->info;
> +	for (int i = 0; i < data->chip_info->als_gain_tbl_size; i++) {
> +		if (data->chip_info->als_gain[i].scale == LTR501_RESERVED_GAIN)
> +			continue;
> +
> +		data->als_gain_tbl[j++].scale = data->chip_info->als_gain[i].scale;
> +		data->als_gain_tbl[j++].uscale = data->chip_info->als_gain[i].uscale;
> +	}
> +	data->als_gain_tbl_len = j;

[Severity: High]
Does post-incrementing j on both assignments overflow data->als_gain_tbl[]?

Because data->als_gain_tbl is an array of struct ltr501_gain rather than
int, incrementing j twice per iteration splits each gain entry across two
adjacent array elements (leaving the other field of each element zeroed)
and advances j to 12 for chips using ltr559_als_gain_tbl (6 non-reserved
entries).  That writes 4 elements past the 8-element als_gain_tbl array,
overwriting als_gain_tbl_len and past the end of struct ltr501_data, while
leaving corrupted scale values for ltr501_read_avail().

Assigning the struct in one step (data->als_gain_tbl[j++] =
data->chip_info->als_gain[i]) and setting data->als_gain_tbl_len = j * 2
would avoid the overflow and give ltr501_read_avail() the expected int
count.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115083741.62140-1-clamor95@gmail.com?part=1

  reply	other threads:[~2026-11-15  8:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  8:37 [PATCH v4 0/4] iio: light: ltr501: Add LTR-659PS-01 prox sensor support Svyatoslav Ryhel
2026-11-15  8:37 ` [PATCH v4 1/4] iio: light: ltr501: Switch to read_avail() op from manual attribute registration Svyatoslav Ryhel
2026-11-15  8:46   ` sashiko-bot [this message]
2026-11-15  8:37 ` [PATCH v4 2/4] iio: light: ltr501: Switch to modern match mechanism Svyatoslav Ryhel
2026-11-15  8:46   ` sashiko-bot
2026-11-15  8:37 ` [PATCH v4 3/4] dt-bindings: iio: light: ltr501: Document LTR659 proximity sensor Svyatoslav Ryhel
2026-11-15  8:37 ` [PATCH v4 4/4] iio: light: ltr501: Add support for the LTR-659PS-01 " Svyatoslav Ryhel
2026-11-15  8:50   ` sashiko-bot

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=sashiko-outbox-215304@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.