* [PATCH] ufs: qcom: Properly clear hba priv on failure
@ 2016-11-18 20:55 Bjorn Andersson
2016-11-19 20:30 ` Subhash Jadavani
0 siblings, 1 reply; 4+ messages in thread
From: Bjorn Andersson @ 2016-11-18 20:55 UTC (permalink / raw)
To: Vinayak Holikatti, James E.J. Bottomley, Martin K. Petersen
Cc: Yaniv Gardi, Vivek Gautam, linux-scsi, linux-kernel, linux-arm-msm
In the case where we fail to acquire the phy the hba priv will be set
already, so during cleanup ufs_qcom_setup_clocks() will dereference the
now free, but still "valid looking" pointer "host".
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
drivers/scsi/ufs/ufs-qcom.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index d345434b084f..7bd88ffee47a 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -1197,7 +1197,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
if (IS_ERR(host->generic_phy)) {
err = PTR_ERR(host->generic_phy);
dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
- goto out;
+ goto out_host_free;
}
err = ufs_qcom_bus_register(host);
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ufs: qcom: Properly clear hba priv on failure
2016-11-18 20:55 [PATCH] ufs: qcom: Properly clear hba priv on failure Bjorn Andersson
@ 2016-11-19 20:30 ` Subhash Jadavani
2016-11-20 6:15 ` Bjorn Andersson
0 siblings, 1 reply; 4+ messages in thread
From: Subhash Jadavani @ 2016-11-19 20:30 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Vinayak Holikatti, James E.J. Bottomley, Martin K. Petersen,
Yaniv Gardi, Vivek Gautam, linux-scsi, linux-kernel,
linux-arm-msm, linux-scsi-owner
On 2016-11-18 12:55, Bjorn Andersson wrote:
> In the case where we fail to acquire the phy the hba priv will be set
> already, so during cleanup ufs_qcom_setup_clocks() will dereference the
> now free, but still "valid looking" pointer "host".
host (ufs_qcom_host) was allocated with devm_kzalloc() so i am not sure
why it would be freed up before probe() returns failure.
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
> drivers/scsi/ufs/ufs-qcom.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> index d345434b084f..7bd88ffee47a 100644
> --- a/drivers/scsi/ufs/ufs-qcom.c
> +++ b/drivers/scsi/ufs/ufs-qcom.c
> @@ -1197,7 +1197,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
> if (IS_ERR(host->generic_phy)) {
> err = PTR_ERR(host->generic_phy);
> dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
> - goto out;
> + goto out_host_free;
> }
>
> err = ufs_qcom_bus_register(host);
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ufs: qcom: Properly clear hba priv on failure
2016-11-19 20:30 ` Subhash Jadavani
@ 2016-11-20 6:15 ` Bjorn Andersson
2016-11-21 18:32 ` Subhash Jadavani
0 siblings, 1 reply; 4+ messages in thread
From: Bjorn Andersson @ 2016-11-20 6:15 UTC (permalink / raw)
To: Subhash Jadavani
Cc: Vinayak Holikatti, James E.J. Bottomley, Martin K. Petersen,
Yaniv Gardi, Vivek Gautam, linux-scsi, linux-kernel,
linux-arm-msm, linux-scsi-owner
On Sat 19 Nov 12:30 PST 2016, Subhash Jadavani wrote:
> On 2016-11-18 12:55, Bjorn Andersson wrote:
> >In the case where we fail to acquire the phy the hba priv will be set
> >already, so during cleanup ufs_qcom_setup_clocks() will dereference the
> >now free, but still "valid looking" pointer "host".
>
> host (ufs_qcom_host) was allocated with devm_kzalloc() so i am not sure why
> it would be freed up before probe() returns failure.
>
Sorry, I missed the fact that the devm_kfree() was dropped, the actual
problem still remains, although it no longer results in a panic.
As ufs_qcom_init() returns from not having found the phy it the variant
data will be a zero-initialized object. The error path of
ufshcd_hba_init() will then take us through ufs_qcom_setup_clocks(),
which will pass the check for a NULL variant data and use the
uninitialized host object.
I can update the commit message to reflect the new state of things.
Regards,
Bjorn
> >Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> >---
> > drivers/scsi/ufs/ufs-qcom.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
> >index d345434b084f..7bd88ffee47a 100644
> >--- a/drivers/scsi/ufs/ufs-qcom.c
> >+++ b/drivers/scsi/ufs/ufs-qcom.c
> >@@ -1197,7 +1197,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
> > if (IS_ERR(host->generic_phy)) {
> > err = PTR_ERR(host->generic_phy);
> > dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
> >- goto out;
> >+ goto out_host_free;
> > }
> >
> > err = ufs_qcom_bus_register(host);
>
> --
> The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ufs: qcom: Properly clear hba priv on failure
2016-11-20 6:15 ` Bjorn Andersson
@ 2016-11-21 18:32 ` Subhash Jadavani
0 siblings, 0 replies; 4+ messages in thread
From: Subhash Jadavani @ 2016-11-21 18:32 UTC (permalink / raw)
To: Bjorn Andersson
Cc: Vinayak Holikatti, James E.J. Bottomley, Martin K. Petersen,
Yaniv Gardi, Vivek Gautam, linux-scsi, linux-kernel,
linux-arm-msm, linux-scsi-owner
On 2016-11-19 22:15, Bjorn Andersson wrote:
> On Sat 19 Nov 12:30 PST 2016, Subhash Jadavani wrote:
>
>> On 2016-11-18 12:55, Bjorn Andersson wrote:
>> >In the case where we fail to acquire the phy the hba priv will be set
>> >already, so during cleanup ufs_qcom_setup_clocks() will dereference the
>> >now free, but still "valid looking" pointer "host".
>>
>> host (ufs_qcom_host) was allocated with devm_kzalloc() so i am not
>> sure why
>> it would be freed up before probe() returns failure.
>>
>
> Sorry, I missed the fact that the devm_kfree() was dropped, the actual
> problem still remains, although it no longer results in a panic.
Agreed.
>
> As ufs_qcom_init() returns from not having found the phy it the variant
> data will be a zero-initialized object. The error path of
> ufshcd_hba_init() will then take us through ufs_qcom_setup_clocks(),
> which will pass the check for a NULL variant data and use the
> uninitialized host object.
Yes, Make sense.
>
> I can update the commit message to reflect the new state of things.
Your new patch set looks good, will add my ack.
>
> Regards,
> Bjorn
>
>> >Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
>> >---
>> > drivers/scsi/ufs/ufs-qcom.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> >diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
>> >index d345434b084f..7bd88ffee47a 100644
>> >--- a/drivers/scsi/ufs/ufs-qcom.c
>> >+++ b/drivers/scsi/ufs/ufs-qcom.c
>> >@@ -1197,7 +1197,7 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>> > if (IS_ERR(host->generic_phy)) {
>> > err = PTR_ERR(host->generic_phy);
>> > dev_err(dev, "%s: PHY get failed %d\n", __func__, err);
>> >- goto out;
>> >+ goto out_host_free;
>> > }
>> >
>> > err = ufs_qcom_bus_register(host);
>>
>> --
>> The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>> a Linux Foundation Collaborative Project
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-21 18:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-18 20:55 [PATCH] ufs: qcom: Properly clear hba priv on failure Bjorn Andersson
2016-11-19 20:30 ` Subhash Jadavani
2016-11-20 6:15 ` Bjorn Andersson
2016-11-21 18:32 ` Subhash Jadavani
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.