From e51738b0a85a2ec0d602bc855232aa78f522313d Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Tue, 26 Oct 2021 14:57:41 +0800 Subject: [PATCH 1/2] input: qcom-hv-haptics: try with vmalloc() if allocate custom data failed Reallocate memory using vmalloc() for custom FIFO data if the memory allocation using kcalloc() is failed. This may happen if the vibrator HAL is passing down a vibration effect with a very big chunk of FIFO data and system is running out of memory. Change-Id: I3612208df42e46a44ca0fd43ec9b4c6ca862620e Signed-off-by: Fenglin Wu --- drivers/input/misc/qcom-hv-haptics.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index f7ee575f6a73..873aa2a0cbe8 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -2196,11 +2197,14 @@ static int haptics_load_custom_effect(struct haptics_chip *chip, * Before allocating samples buffer, free the old sample * buffer first if it's not been freed. */ - kfree(fifo->samples); + kvfree(fifo->samples); fifo->samples = kcalloc(custom_data.length, sizeof(u8), GFP_KERNEL); if (!fifo->samples) { - rc = -ENOMEM; - goto unlock; + fifo->samples = vmalloc(custom_data.length); + if (!fifo->samples) { + rc = -ENOMEM; + goto unlock; + } } if (copy_from_user(fifo->samples, @@ -2245,7 +2249,7 @@ static int haptics_load_custom_effect(struct haptics_chip *chip, mutex_unlock(&chip->play.lock); return 0; cleanup: - kfree(fifo->samples); + kvfree(fifo->samples); fifo->samples = NULL; unlock: mutex_unlock(&chip->play.lock); @@ -2438,7 +2442,7 @@ static int haptics_stop_fifo_play(struct haptics_chip *chip) return rc; haptics_fifo_empty_irq_config(chip, false); - kfree(chip->custom_effect->fifo->samples); + kvfree(chip->custom_effect->fifo->samples); chip->custom_effect->fifo->samples = NULL; atomic_set(&chip->play.fifo_status.is_busy, 0); From b09f20aa364e6800454bc253909eef407c60ef06 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 27 Oct 2021 11:18:38 +0800 Subject: [PATCH 2/2] input: qcom-hv-haptics: use OL_TLRA if getting CL_TLRA failed If getting close-loop TLRA failed in driver probe, such as if there is no valid value in SDAM register for CAL_TLRA_CL_STS because of the bootloader had not run the frequency calibration successfully. Use open-loop TLRA to program the hardware so the vibrator can still be functional but just lose some efficiency because of unadjusted frequency. Change-Id: I8b8dd0906aa6b3fa882e2044cdbe579c746714a3 Signed-off-by: Fenglin Wu --- drivers/input/misc/qcom-hv-haptics.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index 873aa2a0cbe8..4c8a8ca6a147 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -2721,15 +2721,15 @@ static int haptics_hw_init(struct haptics_chip *chip) return rc; /* get calibrated close loop period */ + t_lra_us = chip->config.t_lra_us; rc = haptics_get_closeloop_lra_period(chip, true); - if (rc < 0) - return rc; + if (!rc && chip->config.cl_t_lra_us != 0) + t_lra_us = chip->config.cl_t_lra_us; + else + dev_warn(chip->dev, "get closeloop LRA period failed, rc=%d\n", + rc); /* Config T_LRA */ - t_lra_us = chip->config.t_lra_us; - if (chip->config.cl_t_lra_us != 0) - t_lra_us = chip->config.cl_t_lra_us; - rc = haptics_config_openloop_lra_period(chip, t_lra_us); if (rc < 0) return rc;