Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sanjay Chitroda" <sanjayembeddedse@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 01/10] iio: humidity: hid-sensor-humidity: use local struct device
Date: Mon, 20 Jul 2026 09:49:03 +0000	[thread overview]
Message-ID: <20260720094904.333371F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-hid-iio-local-struct-device-v1-1-74496fee6327@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver shares a single, global static `struct hid_sensor_hub_callbacks humidity_callbacks` across all device instances, leading to cross-device data corruption and potential Use-After-Free if multiple devices are probed.
--

--- Patch [1]: [PATCH 01/10] iio: humidity: hid-sensor-humidity: use local struct device ---
commit e9be49bc2265ade3aeb3c548b989cbea2029fdd4
Author: Sanjay Chitroda <sanjayembeddedse@gmail.com>

iio: humidity: hid-sensor-humidity: use local struct device

This commit introduces a local struct device pointer derived from pdev->dev
in hid_humidity_probe() to avoid repeated usage and improve readability.

> diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c
> index 7cec81ff56856..1b254d3aeee90 100644
> --- a/drivers/iio/humidity/hid-sensor-humidity.c
> +++ b/drivers/iio/humidity/hid-sensor-humidity.c
> @@ -196,10 +196,11 @@ static int hid_humidity_probe(struct platform_device *pdev)

[Severity: High]
This is a pre-existing issue, but does sharing a single global static
humidity_callbacks structure across all device instances lead to cross-device
data corruption?

Looking at hid_humidity_probe(), it unconditionally overwrites the shared
static callback structure with the pdev of the most recently probed instance:

hid_humidity_probe(struct platform_device *pdev)
{
        ...
        humidity_callbacks.pdev = pdev;
        ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY,
                                           &humidity_callbacks);
        ...
}

If multiple HID humidity sensors are probed, the static humidity_callbacks
struct is overwritten. If an earlier probed device generates an event, the
callback functions will receive the wrong pdev.

Additionally, if the most recently probed device is disconnected, its pdev is
freed. If the remaining connected device generates an event, could the driver
dereference a dangling pointer?

Should the callbacks struct be allocated per-device inside the dynamically
allocated state structure instead of being defined globally as a static
variable?

>  	struct iio_dev *indio_dev;
>  	struct hid_humidity_state *humid_st;
>  	struct iio_chan_spec *humid_chans;
> -	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
> +	struct device *dev = &pdev->dev;
> +	struct hid_sensor_hub_device *hsdev = dev_get_platdata(dev);
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*humid_st));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*humid_st));
>  	if (!indio_dev)
>  		return -ENOMEM;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-hid-iio-local-struct-device-v1-0-74496fee6327@gmail.com?part=1

  reply	other threads:[~2026-07-20  9:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  9:40 [PATCH 00/10] HID: iio: use local struct device Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 01/10] iio: humidity: hid-sensor-humidity: " Sanjay Chitroda via B4 Relay
2026-07-20  9:49   ` sashiko-bot [this message]
2026-07-20  9:40 ` [PATCH 02/10] iio: gyro: hid-sensor-gyro-3d: " Sanjay Chitroda via B4 Relay
2026-07-20 11:54   ` Andy Shevchenko
2026-07-20 16:50     ` Sanjay Chitroda
2026-07-20 19:35       ` Andy Shevchenko
2026-07-20  9:40 ` [PATCH 03/10] iio: accel: hid-sensor-accel-3d: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 04/10] iio: light: hid-sensor-als: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 05/10] iio: light: hid-sensor-prox: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 06/10] iio: magnetometer: hid-sensor-magn-3d: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 07/10] iio: orientation: hid-sensor-incl-3d: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 08/10] iio: orientation: hid-sensor-rotation: " Sanjay Chitroda via B4 Relay
2026-07-20  9:40 ` [PATCH 09/10] iio: position: hid-sensor-custom-intel-hinge: " Sanjay Chitroda via B4 Relay
2026-07-20  9:59   ` sashiko-bot
2026-07-20  9:40 ` [PATCH 10/10] iio: pressure: hid-sensor-press: " Sanjay Chitroda via B4 Relay

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=20260720094904.333371F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sanjayembeddedse@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox