Re: [PATCH v7 1/2] HID: haptic: reorder try_module_get/get_device before input_ff_create

From: Dmitry Torokhov

Date: Fri Oct 16 2026 - 14:17:03 EST


Hi Aldo,

On Fri, Oct 16, 2026 at 01:33:48PM -0300, Aldo Ariel Panzardo wrote:
> Move try_module_get() and get_device() before input_ff_create() in
> hid_haptic_init(). The original order placed them after
> input_ff_create(), and failures went to input_free which called
> input_ff_destroy() without ever setting ret. The caller saw ret == 0
> on failure and kept a dangling pointer to the haptic struct.

How about we simply stop pretending that these can fail? I.e. replace
try_module_get() with __module_get()

As far as get_device() it cannot fail and is redundant:

- get_device(&hdev->dev) only returns NULL if its argument is NULL,
which is impossible here since hdev was already dereferenced
throughout hid_haptic_init()

- In hidinput_allocate(), input_dev->dev.parent is set to &hdev->dev.
The driver core will already hold a reference to &hdev->dev
(dev->parent) that will only released in device_release() after
input_dev_release() -> input_ff_destroy() -> hid_haptic_destroy()
finishes.

Additionally I think we should simply fail probe if hid_haptic_init()
fails instead of trying to limp along without it.

Thanks.

--
Dmitry