From: Jonathan Cameron <jic23@kernel.org>
To: Sanjay Chitroda via B4 Relay
<devnull+sanjayembeddedse.gmail.com@kernel.org>
Cc: sanjayembeddedse@gmail.com,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jiri Kosina" <jikos@kernel.org>,
"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
"Benjamin Tissoires" <bentiss@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org
Subject: Re: [PATCH v6 03/14] HID: hid-sensor-hub: introduce device managed API
Date: Sun, 20 Sep 2026 02:00:21 +0100 [thread overview]
Message-ID: <20260920020021.3c5f08f5@jic23-hlaptop> (raw)
In-Reply-To: <20260919-28-apr-iio-redundant-argument-v5-temp-v6-3-d577b2371b3c@gmail.com>
On Sat, 19 Sep 2026 16:06:26 +0530
Sanjay Chitroda via B4 Relay <devnull+sanjayembeddedse.gmail.com@kernel.org> wrote:
> From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
>
> sensor_hub_register_callback() is common API used for the HID IIO drivers,
> prepare devm API devm_sensor_hub_register_callback() to acquire resource
> during setup and release using device managed framework during drivers
> fail, unbind or remove path.
>
> Store the required callback removal context (hsdev and usage_id) in a
> dedicated struct sensor_hub_cb_devres, and register resources with
> devres framework and helper API.
>
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Sanjay Chitroda <sanjayembeddedse@gmail.com>
One thing in here. If it's all that comes up I might just tweak it
whilst applying. I do want to give a bit of time for others to look
at this series anyway before applying so won't do that immediately.
Thanks,
Jonathan
> ---
> Changes in v6:
> - Add kernel-doc for return statement for the new devm_*() API, as
> suggested by Andy.
> - Keep kernel-doc for new devm_*() API in public header file, along
> side where existing API documentation is available.
> - With suggestion/input from Jonathan, use devres and cleanup frameworks
> together to implement device managed API support with less complexity.
> ---
> drivers/hid/hid-sensor-hub.c | 35 +++++++++++++++++++++++++++++++++++
> include/linux/hid-sensor-hub.h | 26 ++++++++++++++++++++++++++
> 2 files changed, 61 insertions(+)
>
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> index 6470a290ebfc..de35e72b4d88 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -4,7 +4,9 @@
> * Copyright (c) 2012, Intel Corporation.
> */
>
> +#include <linux/cleanup.h>
> #include <linux/device.h>
> +#include <linux/device/devres.h>
> #include <linux/hid.h>
> #include <linux/module.h>
> #include <linux/slab.h>
> @@ -187,6 +189,39 @@ int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
> }
> EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
>
> +DEFINE_FREE(devres_free, struct sensor_hub_cb_devres *, if (_T) devres_free(_T))
> +
> +static void devm_sensor_hub_remove_callback(struct device *dev, void *res)
> +{
> + struct sensor_hub_cb_devres *dr = res;
> +
> + sensor_hub_remove_callback(dr->hsdev, dr->usage_id);
> +}
> +
> +int devm_sensor_hub_register_callback(struct device *dev,
> + struct hid_sensor_hub_device *hsdev,
> + u32 usage_id,
> + struct hid_sensor_hub_callbacks *usage_callback)
> +{
> + struct sensor_hub_cb_devres *dr __free(devres_free) = NULL;
This must be as tightly coupled as possible with the allocation.
int ret;
struct sensor_hb_cb_devres *dr __free(devres_free) =
devres_alloc(devm_sensor_hub_remove_callback, sizeof(*dr), GFP_KERNEL);
if (!dr)
return -ENOMEM;
No idea why we see so many folk doing the = NULL thing given the guidance in
cleanup.h that says never to do that! If you are bored, it is a fun saga of
weird things compilers can do and not warn you about + fragility of resulting
code and the desire to keep the code readable.
> + int ret;
> +
> + dr = devres_alloc(devm_sensor_hub_remove_callback, sizeof(*dr), GFP_KERNEL);
> + if (!dr)
> + return -ENOMEM;
> +
> + ret = sensor_hub_register_callback(hsdev, usage_id, usage_callback);
> + if (ret)
> + return ret;
> +
> + dr->hsdev = hsdev;
> + dr->usage_id = usage_id;
> + devres_add(dev, no_free_ptr(dr));
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(devm_sensor_hub_register_callback);
next prev parent reply other threads:[~2026-09-20 1:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 10:36 [PATCH v6 00/14] HID: iio: Introduce devm_ APIs for HID sensors Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 01/14] iio: hid-sensors: remove unused iio_dev argument Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 02/14] iio: hid-sensors: introduce device managed API Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 03/14] HID: hid-sensor-hub: " Sanjay Chitroda via B4 Relay
2026-09-20 1:00 ` Jonathan Cameron [this message]
2026-09-19 10:36 ` [PATCH v6 04/14] iio: gyro: hid-sensor-gyro-3d: convert probe and teardown to devm-managed resources Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 05/14] iio: accel: hid-sensor-accel-3d: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 06/14] iio: humidity: hid-sensor-humidity: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 07/14] iio: light: hid-sensor-prox: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 08/14] iio: light: hid-sensor-als: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 09/14] iio: magnetometer: hid-sensor-magn-3d: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 10/14] iio: orientation: hid-sensor-incl-3d: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 11/14] iio: orientation: hid-sensor-rotation: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 12/14] iio: position: hid-sensor-custom-intel-hinge: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 13/14] iio: pressure: hid-sensor-press: " Sanjay Chitroda via B4 Relay
2026-09-19 10:36 ` [PATCH v6 14/14] iio: temperature: hid-sensor-temperature: " Sanjay Chitroda via B4 Relay
2026-09-27 20:57 ` [PATCH v6 00/14] HID: iio: Introduce devm_ APIs for HID sensors Jonathan Cameron
2026-09-29 4:31 ` Zhang, Lixu
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=20260920020021.3c5f08f5@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=bentiss@kernel.org \
--cc=devnull+sanjayembeddedse.gmail.com@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=sanjayembeddedse@gmail.com \
--cc=srinivas.pandruvada@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
all inboxes | Powered by JetHome®