From dfd72aa13f2cc89fd632ca15c107270b0a43e103 Mon Sep 17 00:00:00 2001 From: Andy White Date: Mon, 19 Sep 2022 15:16:10 -0500 Subject: [PATCH] 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 Reviewed-on: https://gerrit.mot.com/2386804 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Qing Chang Submit-Approved: Jira Key --- drivers/misc/awinic/haptic_hv/haptic_hv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/misc/awinic/haptic_hv/haptic_hv.c b/drivers/misc/awinic/haptic_hv/haptic_hv.c index b767cbc3b2b2..52a9fee8bace 100644 --- a/drivers/misc/awinic/haptic_hv/haptic_hv.c +++ b/drivers/misc/awinic/haptic_hv/haptic_hv.c @@ -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;