haptic_hv: Prevent sysfs attrs from being destroyed

If the trigger is changed, there's a chance that the new trigger
will provide attributes that conflict with ones that already exist,
destroying them.

By setting the `trigger` attribute to read-only, any init script
that attempts to alter the trigger will fail to do so.

Change-Id: I64b33c375415326354e1fb2a11b04cd3626c6b00
Signed-off-by: Perry White <awhite6@motorola.com>
Reviewed-on: https://gerrit.mot.com/2386804
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Qing Chang <qing@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
Andy White 2022-09-19 15:16:10 -05:00
commit dfd72aa13f

View file

@ -3426,6 +3426,22 @@ static int vibrator_init(struct aw_haptic *aw_haptic)
aw_err("error creating sysfs attr files");
return ret;
}
/* Android has a habit of trying to set the vibrator trigger to "transient",
* which destroys our own "activate", "duration", and "state" attributes.
* Change the file permissions of the "trigger" attribute provided by
* leds_class to read-only so that no one can change the trigger of the
* vibrator LED device.
*
* Luckily, `sysfs_chmod_file` only uses the `name` field, so we can use a
* compound literal instead of having to find the proper attribute struct */
ret = sysfs_chmod_file(&aw_haptic->vib_dev.dev->kobj,
&((struct attribute){.name = "trigger"}),
S_IRUSR | S_IRGRP | S_IROTH);
if (ret < 0) {
aw_err("Unable to change trigger file permissions");
}
#endif
hrtimer_init(&aw_haptic->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
aw_haptic->timer.function = vibrator_timer_func;