All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Robert Ijtsma" <robertijtsma@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver
Date: Tue, 24 Nov 2026 22:56:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-232177@kernel.org> (raw)
In-Reply-To: <20261124-iio-tcs3430-v1-2-0f2a38a6a4c1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] iio: light: tcs3430: unscoped guard(mutex) in
  tcs3430_read_raw() switch cases
--

commit 9716c3f00abb68b36cb419ee8d2edca1a86defb1
Author: Robert Ijtsma <robertijtsma@gmail.com>

iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver

This commit adds an IIO driver for the ams OSRAM TCS3430 ambient light and
CIE 1931 XYZ tristimulus color sensor.

> diff --git a/drivers/iio/light/tcs3430.c b/drivers/iio/light/tcs3430.c
> new file mode 100644
> index 0000000000000..138c8ab649c4f
> --- /dev/null
> +++ b/drivers/iio/light/tcs3430.c

[ ... ]

> +static int tcs3430_read_raw(struct iio_dev *indio_dev,
> +			    const struct iio_chan_spec *chan,
> +			    int *val, int *val2, long mask)
> +{
> +	struct tcs3430_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		guard(mutex)(&data->lock);
> +		ret = i2c_smbus_read_word_data(data->client, chan->address);
> +		if (ret < 0)
> +			return ret;
> +		*val = ret;
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_SCALE: {
> +		u32 itime_us = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
> +		u64 scale_nano;
> +		u32 rem;
> +		int gain;
> +
> +		scoped_guard(mutex, &data->lock)
> +			gain = tcs3430_gains[data->gain_idx];
> +
> +		scale_nano = div_u64(TCS3430_LUX_FACTOR * NSEC_PER_SEC * USEC_PER_MSEC,
> +				     (u32)gain * itime_us);
> +		*val = div_u64_rem(scale_nano, NSEC_PER_SEC, &rem);
> +		*val2 = rem;
> +		return IIO_VAL_INT_PLUS_NANO;
> +	}
> +
> +	case IIO_CHAN_INFO_HARDWAREGAIN:
> +		guard(mutex)(&data->lock);
> +		*val = tcs3430_gains[data->gain_idx];
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_INT_TIME:
> +		*val = 0;
> +		*val2 = TCS3430_DEFAULT_ATIME_CYCLES * TCS3430_ATIME_STEP_US;
> +		return IIO_VAL_INT_PLUS_MICRO;
> +
> +	default:
> +		return -EINVAL;
> +	}
> +}

[Severity: High]
Do the guard(mutex)(&data->lock) declarations in case IIO_CHAN_INFO_RAW and
case IIO_CHAN_INFO_HARDWAREGAIN need enclosing braces or scoped_guard()?

Without braces, both __cleanup(class_mutex_destructor) guard variables are
scoped to the entire switch (mask) block.  This fails to build with Clang
because the following case labels jump into the scope of a cleanup variable
past its initialization, and on GCC builds reading sysfs attributes such as
in_illuminance_scale jumps past the guard initialization and runs
class_mutex_destructor() on an uninitialized lock pointer upon return.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-iio-tcs3430-v1-0-0f2a38a6a4c1@gmail.com?part=2

  reply	other threads:[~2026-11-24 22:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 22:46 [PATCH 0/2] iio: light: add support for ams OSRAM TCS3430 Robert Ijtsma
2026-11-24 22:46 ` Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 1/2] dt-bindings: iio: light: add " Robert Ijtsma
2026-11-24 22:46   ` Robert Ijtsma via B4 Relay
2026-11-25  7:43   ` Krzysztof Kozlowski
2026-11-25  8:02   ` Joshua Crofts
2026-11-24 22:46 ` [PATCH 2/2] iio: light: add ams OSRAM TCS3430 XYZ and ambient light sensor driver Robert Ijtsma
2026-11-24 22:46   ` Robert Ijtsma via B4 Relay
2026-11-24 22:56   ` sashiko-bot [this message]
2026-11-25  6:28   ` kernel test robot
2026-11-25  8:31   ` Joshua Crofts
2026-11-26  2:35   ` Jonathan Cameron

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-232177@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robertijtsma@gmail.com \
    --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.