Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 6/7] HID: sensor: custom: Register enable attribute after misc device
Date: Wed, 04 Nov 2026 20:25:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-198009@kernel.org> (raw)
In-Reply-To: <20261104201403.2039921-7-srinivas.pandruvada@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] HID: sensor: custom: duplicate callback removal in hid_sensor_custom_probe()
--

commit 3c6fa7005fd38bc50c4da9b69a1182ec5457915f
Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

HID: sensor: custom: Register enable attribute after misc device

This commit reorders hid_sensor_custom_probe() so enable_sensor_attr_group is
registered after hid_sensor_custom_dev_if_add() succeeds, preventing userspace
from enabling the sensor hub while probe can still fail.

> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
> index 4f824cadd370a..990e653995e15 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;
>  err_remove_attributes:
>  	hid_sensor_custom_remove_attributes(sensor_inst);
>  err_remove_callback:

[Severity: Low]
In hid_sensor_custom_probe() in drivers/hid/hid-sensor-custom.c, when
sysfs_create_group() for enable_sensor_attr_group fails and jumps to
err_remove_dev_if, sensor_hub_remove_callback(hsdev, hsdev->usage) is called
before hid_sensor_custom_remove_attributes(sensor_inst), followed by a goto to
the immediately following err_remove_attributes label and a fallthrough to
err_remove_callback:

err_remove_dev_if:
	sensor_hub_remove_callback(hsdev, hsdev->usage);
	hid_sensor_custom_dev_if_remove(sensor_inst);
	goto err_remove_attributes;
err_remove_attributes:
	hid_sensor_custom_remove_attributes(sensor_inst);
err_remove_callback:
	sensor_hub_remove_callback(hsdev, hsdev->usage);

Because hid_sensor_custom_probe() still holds the initial reference on
sensor_inst until err_free (where kref_put() calls hid_sensor_custom_free() to
free sensor_inst->data_fifo and sensor_inst), removing the callback at
err_remove_dev_if unregisters the callback while the field sysfs attributes are
still exposed, and then calls sensor_hub_remove_callback() a second time at
err_remove_callback.

Should err_remove_dev_if just call hid_sensor_custom_dev_if_remove(sensor_inst)
and fall through to err_remove_attributes and err_remove_callback?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104201403.2039921-1-srinivas.pandruvada@linux.intel.com?part=6

  reply	other threads:[~2026-11-04 20:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 20:13 [PATCH v2 0/7] HID: sensor: custom: use-after-freec after remove Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 1/7] HID: sensor: hub: Synchronize callback removal with raw events Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 2/7] HID: sensor: custom: Set owner for misc device Srinivas Pandruvada
2026-11-04 20:13 ` [PATCH v2 3/7] HID: sensor: custom: Disable sensor before hub close on removal Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 4/7] HID: sensor: custom: Fix state lifetime during removal Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 5/7] HID: sensor: custom: Serialize misc device reads Srinivas Pandruvada
2026-11-04 20:14 ` [PATCH v2 6/7] HID: sensor: custom: Register enable attribute after misc device Srinivas Pandruvada
2026-11-04 20:25   ` sashiko-bot [this message]
2026-11-04 20:14 ` [PATCH v2 7/7] HID: sensor: hub: Remove clients before stopping hardware Srinivas Pandruvada

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=sashiko-outbox-198009@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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