Re: [PATCH v2 6/7] HID: sensor: custom: Register enable attribute after misc device

From: Jonathan Cameron

Date: Sat Nov 07 2026 - 15:22:25 EST


On Wed, 4 Nov 2026 12:14:02 -0800
Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx> wrote:

> Register the enable_sensor sysfs group only after misc-device setup
> succeeds. This prevents userspace from opening the sensor hub while
> probe can still fail, which would otherwise leave the hub open reference
> unbalanced on unwind.
>
> Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor support")
> Reported-by: Семён Марьясин <simeon@xxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/CAM2dg7ewfVJSP4rFyhkCB1Rmd1+X56sAg=eUdbPthG2xrLqwQQ@xxxxxxxxxxxxxx/
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
You probably already saw it, but sashiko had more feedback.
https://sashiko.dev/#/patchset/20261104201403.2039921-1-srinivas.pandruvada%40linux.intel.com

I haven't looked closely at it though so might be either wrong
or material for a future patch.

One rather odd looking thing in here though.


> ---
> drivers/hid/hid-sensor-custom.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
> index 4f824cadd370..990e653995e1 100644
> --- a/drivers/hid/hid-sensor-custom.c
> +++ b/drivers/hid/hid-sensor-custom.c
> @@ -1059,20 +1059,21 @@ static int hid_sensor_custom_probe(struct platform_device *pdev)
> if (ret)
> goto err_remove_callback;
>
> - ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
> - &enable_sensor_attr_group);
> + ret = hid_sensor_custom_dev_if_add(sensor_inst);
> if (ret)
> goto err_remove_attributes;
>
> - ret = hid_sensor_custom_dev_if_add(sensor_inst);
> + ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
> + &enable_sensor_attr_group);
> if (ret)
> - goto err_remove_group;
> + goto err_remove_dev_if;
>
> return 0;
>
> -err_remove_group:
> - sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
> - &enable_sensor_attr_group);
> +err_remove_dev_if:
> + sensor_hub_remove_callback(hsdev, hsdev->usage);
> + hid_sensor_custom_dev_if_remove(sensor_inst);
> + goto err_remove_attributes;

If my eyes are tricking me, isn't this going to the next line?

> err_remove_attributes:
> hid_sensor_custom_remove_attributes(sensor_inst);
> err_remove_callback: