Skip to content

Commit

Permalink
hwmon: (nct6775) Fix platform driver suspend regression
Browse files Browse the repository at this point in the history
Commit c3963bc ("hwmon: (nct6775) Split core and platform
driver") introduced a slight change in nct6775_suspend() in order to
avoid an otherwise-needless symbol export for nct6775_update_device(),
replacing a call to that function with a simple dev_get_drvdata()
instead.

As it turns out, there is no guarantee that nct6775_update_device()
is ever called prior to suspend. If this happens, the resume function
ends up writing bad data into the various chip registers, which results
in a crash shortly after resume.

To fix the problem, just add the symbol export and return to using
nct6775_update_device() as was employed previously.

Reported-by: Zoltán Kővágó <dirty.ice.hu@gmail.com>
Tested-by: Zoltán Kővágó <dirty.ice.hu@gmail.com>
Fixes: c3963bc ("hwmon: (nct6775) Split core and platform driver")
Cc: stable@kernel.org
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20220810052646.13825-1-zev@bewilderbeest.net
[groeck: Updated description]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Zev Weiss authored and Guenter Roeck committed Aug 10, 2022
1 parent 7aeef15 commit f4e6960
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion drivers/hwmon/nct6775-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ static int nct6775_update_pwm_limits(struct device *dev)
return 0;
}

static struct nct6775_data *nct6775_update_device(struct device *dev)
struct nct6775_data *nct6775_update_device(struct device *dev)
{
struct nct6775_data *data = dev_get_drvdata(dev);
int i, j, err = 0;
Expand Down Expand Up @@ -1615,6 +1615,7 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
mutex_unlock(&data->update_lock);
return err ? ERR_PTR(err) : data;
}
EXPORT_SYMBOL_GPL(nct6775_update_device);

/*
* Sysfs callback functions
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/nct6775-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static int __maybe_unused nct6775_suspend(struct device *dev)
{
int err;
u16 tmp;
struct nct6775_data *data = dev_get_drvdata(dev);
struct nct6775_data *data = nct6775_update_device(dev);

if (IS_ERR(data))
return PTR_ERR(data);
Expand Down
2 changes: 2 additions & 0 deletions drivers/hwmon/nct6775.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ static inline int nct6775_write_value(struct nct6775_data *data, u16 reg, u16 va
return regmap_write(data->regmap, reg, value);
}

struct nct6775_data *nct6775_update_device(struct device *dev);

bool nct6775_reg_is_word_sized(struct nct6775_data *data, u16 reg);
int nct6775_probe(struct device *dev, struct nct6775_data *data,
const struct regmap_config *regmapcfg);
Expand Down

0 comments on commit f4e6960

Please sign in to comment.