From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
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 v5 03/13] HID: hid-sensor-hub: introduce device managed API
Date: Sun, 16 Aug 2026 02:32:10 +0100 [thread overview]
Message-ID: <20260816023210.3205ae5c@jic23-huawei> (raw)
In-Reply-To: <aneNIxxRVuJDFgh0@ashevche-desk.local>
On Sat, 8 Aug 2026 23:10:11 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Thu, Aug 06, 2026 at 05:55:49PM +0530, Sanjay Chitroda via B4 Relay wrote:
>
> > 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
>
> Store
>
> > dedicated struct sensor_hub_cb_devres, and register a devres action to
> > handle to release resource with devres framework and helper API.
>
> ...
>
> > +static void sensor_hub_remove_callback_helper(void *ptr)
> > +{
> > + struct sensor_hub_cb_devres *res = ptr;
> > +
> > + sensor_hub_remove_callback(res->hsdev, res->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 *res;
> > + int ret;
> > +
> > + ret = sensor_hub_register_callback(hsdev, usage_id, usage_callback);
> > + if (ret)
> > + return ret;
> > +
> > + res = devm_kmalloc(dev, sizeof(*res), GFP_KERNEL);
> > + if (!res) {
> > + sensor_hub_remove_callback(hsdev, usage_id);
> > + return -ENOMEM;
> > + }
>
> Why is this order? What's wrong with the memory allocation first?
Why do we have a devm_kmalloc() in here at all rather than devres_alloc()
/devres_add() When there is an allocation needed that tends to
end up at a similar level of complexity but with one fewer allocation and
similar unwind. Fun thought, maybe we can have a DEFINE_FREE() to do
the cleanup (devres_free) on error in sensor_hub_register_callback()
with devres_add(no_free_ptr(devres)) to hand over ownership.
>
> > + res->hsdev = hsdev;
> > + res->usage_id = usage_id;
> > +
> > + return devm_add_action_or_reset(dev, sensor_hub_remove_callback_helper, res);
> > +}
>
> ...
>
> > +/**
> > + * devm_sensor_hub_register_callback() - Managed register client callbacks
> > + * @dev: Device for resource management
> > + * @hsdev: Hub device instance
> > + * @usage_id: Usage id of the client (e.g. 0x200076 for Gyro)
> > + * @usage_callback: Callback function storage
> > + *
> > + * This is the devres (managed) version of sensor_hub_register_callback().
> > + * The callback will be automatically unregistered when the device is detached.
>
> Here, and everywhere else, validate kernel-doc. Here you introduced a new warning
> (missing return section).
>
> > + */
>
> Also, why kernel-doc is here?! It should accompany the implementation, here is
> a declaration.
>
> > +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);
>
next prev parent reply other threads:[~2026-08-16 1:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 12:25 [PATCH v5 00/13] HID: iio: Introduce devm_ APIs for HID sensors Sanjay Chitroda via B4 Relay
2026-08-06 12:25 ` [PATCH v5 01/13] iio: hid-sensors: remove unused iio_dev argument Sanjay Chitroda via B4 Relay
2026-08-06 12:37 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 02/13] iio: hid-sensors: introduce device managed API Sanjay Chitroda via B4 Relay
2026-08-06 12:25 ` [PATCH v5 03/13] HID: hid-sensor-hub: " Sanjay Chitroda via B4 Relay
2026-08-06 12:40 ` sashiko-bot
2026-08-08 20:10 ` Andy Shevchenko
2026-08-16 1:32 ` Jonathan Cameron [this message]
2026-08-06 12:25 ` [PATCH v5 04/13] iio: gyro: hid-sensor-gyro-3d: convert probe and teardown to devm-managed resources Sanjay Chitroda via B4 Relay
2026-08-06 12:40 ` sashiko-bot
2026-08-16 1:36 ` Jonathan Cameron
2026-08-06 12:25 ` [PATCH v5 05/13] iio: accel: hid-sensor-accel-3d: " Sanjay Chitroda via B4 Relay
2026-08-06 12:39 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 06/13] iio: humidity: hid-sensor-humidity: " Sanjay Chitroda via B4 Relay
2026-08-06 12:36 ` sashiko-bot
2026-08-16 1:39 ` Jonathan Cameron
2026-08-06 12:25 ` [PATCH v5 07/13] iio: light: hid-sensor-prox: " Sanjay Chitroda via B4 Relay
2026-08-06 12:39 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 08/13] iio: light: hid-sensor-als: " Sanjay Chitroda via B4 Relay
2026-08-06 12:40 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 09/13] iio: magnetometer: hid-sensor-magn-3d: " Sanjay Chitroda via B4 Relay
2026-08-06 12:25 ` [PATCH v5 10/13] iio: orientation: hid-sensor-incl-3d: " Sanjay Chitroda via B4 Relay
2026-08-06 12:25 ` [PATCH v5 11/13] iio: orientation: hid-sensor-rotation: " Sanjay Chitroda via B4 Relay
2026-08-06 12:40 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 12/13] iio: position: hid-sensor-custom-intel-hinge: " Sanjay Chitroda via B4 Relay
2026-08-06 12:48 ` sashiko-bot
2026-08-06 12:25 ` [PATCH v5 13/13] iio: pressure: hid-sensor-press: " Sanjay Chitroda via B4 Relay
2026-08-06 12:44 ` 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=20260816023210.3205ae5c@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=bentiss@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