From cd6f6c7ba3605a0192caaeab99a271b917d7164e Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 22 Dec 2021 12:24:26 +0800 Subject: [PATCH] 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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index 6ae671a6b73b..d61ddbb0f797 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -2105,11 +2105,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, @@ -2154,7 +2157,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); @@ -2347,7 +2350,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);