diff mbox series

[1/4] phy: qcom-ufs: Don't kfree devres resource

Message ID 20170119104739.4376-1-bjorn.andersson@linaro.org
State New
Headers show
Series [1/4] phy: qcom-ufs: Don't kfree devres resource | expand

Commit Message

Bjorn Andersson Jan. 19, 2017, 10:47 a.m. UTC
Upon failing to acquire regulator supplies the qcom-ufs driver calls
kfree() on the devm allocated memory used to store the name of the
regulator, leading to devres corruption.

Rather than switching to using the appropriate free function the patch
acknowledge the fact that "name" is always a constant string and we
don't actually need to create a local copy of it, but rather just
reference the constant string.

Cc: Subhash Jadavani <subhashj@codeaurora.org>
Cc: Vivek Gautam <vivek.gautam@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

---
 drivers/phy/phy-qcom-ufs.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

-- 
2.11.0

Comments

Subhash Jadavani Jan. 20, 2017, 10:54 p.m. UTC | #1
On 2017-01-19 02:47, Bjorn Andersson wrote:
> The error paths of the common qcom-ufs functions for registering the

> phy, acquiring clocks and acquiring regulators all print specific error

> messages before returning an error, so there is no value in printing 

> yet

> another - more generic - message when this occur.

> 

> Cc: Subhash Jadavani <subhashj@codeaurora.org>

> Cc: Vivek Gautam <vivek.gautam@codeaurora.org>

> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---

>  drivers/phy/phy-qcom-ufs-qmp-14nm.c | 15 +++------------

>  drivers/phy/phy-qcom-ufs-qmp-20nm.c | 12 ++----------

>  2 files changed, 5 insertions(+), 22 deletions(-)

> 

> diff --git a/drivers/phy/phy-qcom-ufs-qmp-14nm.c

> b/drivers/phy/phy-qcom-ufs-qmp-14nm.c

> index c71c84734916..12a1b498dc4b 100644

> --- a/drivers/phy/phy-qcom-ufs-qmp-14nm.c

> +++ b/drivers/phy/phy-qcom-ufs-qmp-14nm.c

> @@ -132,27 +132,18 @@ static int ufs_qcom_phy_qmp_14nm_probe(struct

> platform_device *pdev)

>  				&ufs_qcom_phy_qmp_14nm_phy_ops, &phy_14nm_ops);

> 

>  	if (!generic_phy) {

> -		dev_err(dev, "%s: ufs_qcom_phy_generic_probe() failed\n",

> -			__func__);

>  		err = -EIO;

>  		goto out;

>  	}

> 

>  	err = ufs_qcom_phy_init_clks(phy_common);

> -	if (err) {

> -		dev_err(phy_common->dev,

> -			"%s: ufs_qcom_phy_init_clks() failed %d\n",

> -			__func__, err);

> +	if (err)

>  		goto out;

> -	}

> 

>  	err = ufs_qcom_phy_init_vregulators(phy_common);

> -	if (err) {

> -		dev_err(phy_common->dev,

> -			"%s: ufs_qcom_phy_init_vregulators() failed %d\n",

> -			__func__, err);

> +	if (err)

>  		goto out;

> -	}

> +

>  	phy_common->vdda_phy.max_uV = UFS_PHY_VDDA_PHY_UV;

>  	phy_common->vdda_phy.min_uV = UFS_PHY_VDDA_PHY_UV;

> 

> diff --git a/drivers/phy/phy-qcom-ufs-qmp-20nm.c

> b/drivers/phy/phy-qcom-ufs-qmp-20nm.c

> index 1a26a64e06d3..4f68acb58b73 100644

> --- a/drivers/phy/phy-qcom-ufs-qmp-20nm.c

> +++ b/drivers/phy/phy-qcom-ufs-qmp-20nm.c

> @@ -190,25 +190,17 @@ static int ufs_qcom_phy_qmp_20nm_probe(struct

> platform_device *pdev)

>  				&ufs_qcom_phy_qmp_20nm_phy_ops, &phy_20nm_ops);

> 

>  	if (!generic_phy) {

> -		dev_err(dev, "%s: ufs_qcom_phy_generic_probe() failed\n",

> -			__func__);

>  		err = -EIO;

>  		goto out;

>  	}

> 

>  	err = ufs_qcom_phy_init_clks(phy_common);

> -	if (err) {

> -		dev_err(phy_common->dev, "%s: ufs_qcom_phy_init_clks() failed %d\n",

> -			__func__, err);

> +	if (err)

>  		goto out;

> -	}

> 

>  	err = ufs_qcom_phy_init_vregulators(phy_common);

> -	if (err) {

> -		dev_err(phy_common->dev, "%s: ufs_qcom_phy_init_vregulators() failed 

> %d\n",

> -			__func__, err);

> +	if (err)

>  		goto out;

> -	}

> 

>  	ufs_qcom_phy_qmp_20nm_advertise_quirks(phy_common);


Looks good to me.
Reviewed-by: Subhash Jadavani <subhashj@codeaurora.org>


-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
diff mbox series

Patch

diff --git a/drivers/phy/phy-qcom-ufs.c b/drivers/phy/phy-qcom-ufs.c
index c69568b8543d..4d7f3c018223 100644
--- a/drivers/phy/phy-qcom-ufs.c
+++ b/drivers/phy/phy-qcom-ufs.c
@@ -217,12 +217,7 @@  static int __ufs_qcom_phy_init_vreg(struct device *dev,
 
 	char prop_name[MAX_PROP_NAME];
 
-	vreg->name = devm_kstrdup(dev, name, GFP_KERNEL);
-	if (!vreg->name) {
-		err = -ENOMEM;
-		goto out;
-	}
-
+	vreg->name = name;
 	vreg->reg = devm_regulator_get(dev, name);
 	if (IS_ERR(vreg->reg)) {
 		err = PTR_ERR(vreg->reg);
@@ -265,8 +260,6 @@  static int __ufs_qcom_phy_init_vreg(struct device *dev,
 	}
 
 out:
-	if (err)
-		kfree(vreg->name);
 	return err;
 }