From 50982ecf58a9d64beb9c1e535ab7f7e5b32fa88e Mon Sep 17 00:00:00 2001 From: Subbaraman Narayanamurthy Date: Fri, 12 Jun 2020 15:42:07 -0700 Subject: [PATCH] input: qcom-hv-haptics: Fix a possible NULL pointer dereference Use Vmax from play effect in haptics_set_gain() only if the effect is valid. Otherwise, use Vmax from the haptics configuration instead. Change-Id: I7ec0f8c869096bccb26f7fda0057e3db3a51225d Signed-off-by: Subbaraman Narayanamurthy --- drivers/input/misc/qcom-hv-haptics.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/qcom-hv-haptics.c b/drivers/input/misc/qcom-hv-haptics.c index d309b6cd7143..c30669fe12bb 100644 --- a/drivers/input/misc/qcom-hv-haptics.c +++ b/drivers/input/misc/qcom-hv-haptics.c @@ -1777,6 +1777,7 @@ static int haptics_erase(struct input_dev *dev, int effect_id) static void haptics_set_gain(struct input_dev *dev, u16 gain) { struct haptics_chip *chip = input_get_drvdata(dev); + struct haptics_hw_config *config = &chip->config; struct haptics_play_info *play = &chip->play; u32 vmax_mv; @@ -1786,7 +1787,10 @@ static void haptics_set_gain(struct input_dev *dev, u16 gain) if (gain > 0x7fff) gain = 0x7fff; - vmax_mv = play->effect->vmax_mv; + vmax_mv = config->vmax_mv; + if (play->effect) + vmax_mv = play->effect->vmax_mv; + if (chip->clamp_at_5v && (vmax_mv > CLAMPED_VMAX_MV)) vmax_mv = CLAMPED_VMAX_MV;