linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/regulator: fix a missing check of return value
@ 2018-12-19  5:04 Kangjie Lu
  2018-12-19 12:27 ` Mark Brown
  2018-12-19 17:11 ` [PATCH v2] regulator: palmas: " Kangjie Lu
  0 siblings, 2 replies; 4+ messages in thread
From: Kangjie Lu @ 2018-12-19  5:04 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Tony Lindgren, Liam Girdwood, Mark Brown, linux-omap,
	linux-kernel

If palmas_smps_read() fails, we should not use the read data in "reg"
which may contain random value. The fix inserts a check for the return
value of palmas_smps_read(): If it fails, we return the error code
upstream and stop using "reg".

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/regulator/palmas-regulator.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index bb5ab7d78895..c2cc392a27d4 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -443,13 +443,16 @@ static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 {
 	int id = rdev_get_id(dev);
+	int ret;
 	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
 	struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
 	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
 	unsigned int reg;
 	bool rail_enable = true;
 
-	palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
+	ret = palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
+	if (ret)
+		return ret;
 
 	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
-- 
2.17.2 (Apple Git-113)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drivers/regulator: fix a missing check of return value
  2018-12-19  5:04 [PATCH] drivers/regulator: fix a missing check of return value Kangjie Lu
@ 2018-12-19 12:27 ` Mark Brown
  2018-12-19 17:11 ` [PATCH v2] regulator: palmas: " Kangjie Lu
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2018-12-19 12:27 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Tony Lindgren, Liam Girdwood, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

On Tue, Dec 18, 2018 at 11:04:13PM -0600, Kangjie Lu wrote:
> If palmas_smps_read() fails, we should not use the read data in "reg"
> which may contain random value. The fix inserts a check for the return
> value of palmas_smps_read(): If it fails, we return the error code
> upstream and stop using "reg".

Please use subject lines matching the style for the subsystem.  This
makes it easier for people to identify relevant patches.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] regulator: palmas: fix a missing check of return value
  2018-12-19  5:04 [PATCH] drivers/regulator: fix a missing check of return value Kangjie Lu
  2018-12-19 12:27 ` Mark Brown
@ 2018-12-19 17:11 ` Kangjie Lu
  2018-12-19 17:51   ` Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2018-12-19 17:11 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Tony Lindgren, Liam Girdwood, Mark Brown, linux-omap,
	linux-kernel

If palmas_smps_read() fails, we should not use the read data in "reg"
which may contain random value. The fix inserts a check for the return
value of palmas_smps_read(): If it fails, we return the error code
upstream and stop using "reg".

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/regulator/palmas-regulator.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index bb5ab7d78895..c2cc392a27d4 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -443,13 +443,16 @@ static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
 {
 	int id = rdev_get_id(dev);
+	int ret;
 	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
 	struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata;
 	struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id];
 	unsigned int reg;
 	bool rail_enable = true;
 
-	palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
+	ret = palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, &reg);
+	if (ret)
+		return ret;
 
 	reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
 
-- 
2.17.2 (Apple Git-113)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] regulator: palmas: fix a missing check of return value
  2018-12-19 17:11 ` [PATCH v2] regulator: palmas: " Kangjie Lu
@ 2018-12-19 17:51   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2018-12-19 17:51 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Tony Lindgren, Liam Girdwood, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 371 bytes --]

On Wed, Dec 19, 2018 at 11:11:39AM -0600, Kangjie Lu wrote:
> If palmas_smps_read() fails, we should not use the read data in "reg"
> which may contain random value. The fix inserts a check for the return
> value of palmas_smps_read(): If it fails, we return the error code
> upstream and stop using "reg".

Ah, thanks - I'd actually already applied the earlier version!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-19 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-19  5:04 [PATCH] drivers/regulator: fix a missing check of return value Kangjie Lu
2018-12-19 12:27 ` Mark Brown
2018-12-19 17:11 ` [PATCH v2] regulator: palmas: " Kangjie Lu
2018-12-19 17:51   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).