mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Satyam Gupta <sgsatyam@google.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Benson Leung" <bleung@chromium.org>,
	"Guenter Roeck" <groeck@chromium.org>,
	"Tzung-Bi Shih" <tzungbi@kernel.org>,
	"Gwendal Grignou" <gwendal@chromium.org>,
	linux-iio@vger.kernel.org, chrome-platform@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: cros_ec: Use platform sensor_num to unregister FIFO callback
Date: Thu, 5 Nov 2026 12:00:00 +0200	[thread overview]
Message-ID: <auxToA8qgIa7vR7k@ashevche-desk.local> (raw)
In-Reply-To: <20261105073107.172121-1-sgsatyam@google.com>

On Thu, Nov 05, 2026 at 07:31:07AM +0000, Satyam Gupta wrote:
> cros_ec_sensors_core_register() registers the FIFO callback for the
> sensor number found in the platform data. The matching cleanup action,
> cros_ec_sensors_core_clean(), reads the number back from
> st->param.info.sensor_num instead.
> 
> st->param is the EC host command buffer. Drivers fill it in under
> cmd_lock before each command, while the cleanup action reads it without
> that lock. It is also set only for physical sensors. If the field holds
> another value when the device is unbound, the cleanup clears the wrong
> slot and leaves the callback in place, still pointing to the iio_dev
> that is about to be freed.
> 
> Use the platform data in the cleanup action too, so it always
> unregisters the slot that cros_ec_sensors_core_register() registered.

Sounds like a Fixes tag is good to have.

> Signed-off-by: Satyam Gupta <sgsatyam@google.com>
> ---
> Tested on an Android desktop device (6.18, Intel) with two
> accelerometers and a lid angle sensor: each sensor was unbound and
> bound 20 times while a reader kept EC commands in flight, then FIFO
> samples were streamed. Also tested on a ChromeOS device (6.6) with an
> RGB light sensor, together with downstream changes to that driver.
> 
>  drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 8 ++++----
> @@ -216,11 +216,11 @@ static void cros_ec_sensors_core_clean(void *arg)
>  	struct platform_device *pdev = (struct platform_device *)arg;
>  	struct cros_ec_sensorhub *sensor_hub =
>  		dev_get_drvdata(pdev->dev.parent);
> -	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> -	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> -	u8 sensor_num = st->param.info.sensor_num;
> +	struct cros_ec_sensor_platform *sensor_platform =
> +		dev_get_platdata(&pdev->dev);

With context I see it would be better written in the following form:

	struct platform_device *pdev = (struct platform_device *)arg;
	struct device *dev = &pdev->dev;
	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
	struct cros_ec_sensor_platform *pdata = dev_get_platdata(dev);

> -	cros_ec_sensorhub_unregister_push_data(sensor_hub, sensor_num);
> +	cros_ec_sensorhub_unregister_push_data(sensor_hub,
> +					       sensor_pdata->sensor_num);

	cros_ec_sensorhub_unregister_push_data(sensor_hub, pdata->sensor_num);

>  }

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-11-05 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  7:31 Satyam Gupta
2026-11-05 10:00 ` Andy Shevchenko [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=auxToA8qgIa7vR7k@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dlechner@baylibre.com \
    --cc=groeck@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sgsatyam@google.com \
    --cc=tzungbi@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

all inboxes | Powered by JetHome®