2015-04-15 19:11:00

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH] ufs: Reinstate NULL pointer checks for regulators

The cleanup during the introduction of regulator_set_load() was a too
optimistic and re-opened an issue with vreg being dereferenced while
being NULL.

So reinstate the NULL checks and add back the BUG_ON() to follow the
general coding convention of the implementation.

Fixes: 7b16a07c3293 ("ufs: Rename of regulator_set_optimum_mode")
Reported-by: Akinobu Mita <[email protected]>
Signed-off-by: Bjorn Andersson <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 648a44675880..540e00df6de1 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -4262,8 +4262,7 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
{
int ret;

- if (!vreg)
- return 0;
+ BUG_ON(!vreg);

ret = regulator_set_load(vreg->reg, ua);
if (ret < 0) {
@@ -4277,12 +4276,18 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
struct ufs_vreg *vreg)
{
+ if (!vreg)
+ return 0;
+
return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
}

static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
struct ufs_vreg *vreg)
{
+ if (!vreg)
+ return 0;
+
return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
}

--
1.8.2.2


2015-04-29 00:49:25

by Akinobu Mita

[permalink] [raw]
Subject: Re: [PATCH] ufs: Reinstate NULL pointer checks for regulators

2015-04-16 4:10 GMT+09:00 Bjorn Andersson <[email protected]>:
> The cleanup during the introduction of regulator_set_load() was a too
> optimistic and re-opened an issue with vreg being dereferenced while
> being NULL.
>
> So reinstate the NULL checks and add back the BUG_ON() to follow the
> general coding convention of the implementation.
>
> Fixes: 7b16a07c3293 ("ufs: Rename of regulator_set_optimum_mode")
> Reported-by: Akinobu Mita <[email protected]>
> Signed-off-by: Bjorn Andersson <[email protected]>

Tested-by: Akinobu Mita <[email protected]>

This patch still isn't picked up by scsi tree nor regulator tree.

James, Mark,
Could you consider taking care of this patch?

> ---
> drivers/scsi/ufs/ufshcd.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 648a44675880..540e00df6de1 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -4262,8 +4262,7 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
> {
> int ret;
>
> - if (!vreg)
> - return 0;
> + BUG_ON(!vreg);
>
> ret = regulator_set_load(vreg->reg, ua);
> if (ret < 0) {
> @@ -4277,12 +4276,18 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
> static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
> struct ufs_vreg *vreg)
> {
> + if (!vreg)
> + return 0;
> +
> return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
> }
>
> static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
> struct ufs_vreg *vreg)
> {
> + if (!vreg)
> + return 0;
> +
> return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
> }
>
> --
> 1.8.2.2
>