diff mbox series

[-next] phy: samsung-ufs: fix NULL pointer dereference

Message ID 20220610070547.71193-1-alim.akhtar@samsung.com
State Changes Requested
Headers show
Series [-next] phy: samsung-ufs: fix NULL pointer dereference | expand

Commit Message

Alim Akhtar June 10, 2022, 7:05 a.m. UTC
commit f86c1d0a58b1f63a ("phy: samsung: ufs: remove drvdata from struct
samsung_ufs_phy")

removes _drvdata_ initialization which resulting in NULL pointer
dereferencing in samsung_ufs_phy_wait_for_lock_acq(). Fix this by
initializing drvdata.

The said commit also duplicate "has_symbol_clk" both in drvdata struct
and in samsung_ufs_phy struct, let's go back and use only one
"has_symbol_clk".

Fixes: f86c1d0a58b1 phy: samsung: ufs: remove drvdata from struct samsung_ufs_phy
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
---
 drivers/phy/samsung/phy-samsung-ufs.c | 6 +++---
 drivers/phy/samsung/phy-samsung-ufs.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)


base-commit: ff539ac73ea559a8c146d99ab14bfcaddd30547a

Comments

Chanho Park June 10, 2022, 8:15 a.m. UTC | #1
> Subject: [PATCH -next] phy: samsung-ufs: fix NULL pointer dereference
> 
> commit f86c1d0a58b1f63a ("phy: samsung: ufs: remove drvdata from struct
> samsung_ufs_phy")
> 
> removes _drvdata_ initialization which resulting in NULL pointer
> dereferencing in samsung_ufs_phy_wait_for_lock_acq(). Fix this by
> initializing drvdata.
> 
> The said commit also duplicate "has_symbol_clk" both in drvdata struct and
> in samsung_ufs_phy struct, let's go back and use only one "has_symbol_clk".
> 
> Fixes: f86c1d0a58b1 phy: samsung: ufs: remove drvdata from struct
> samsung_ufs_phy

This might be conflicted when you apply your patch.
https://lore.kernel.org/linux-phy/20220610072924.12362-3-alim.akhtar@samsung.com/T/#u

When I created my patch, it was not existing so my previous patch make sense.
If you get back drvdata for your patch, please drop this "fixes tag + patch" and put this in your patchset.

Best Regards,
Chanho Park
Alim Akhtar June 10, 2022, 9:15 a.m. UTC | #2
Sorry for the noise.

Please ignore this patch

>-----Original Message-----
>From: Alim Akhtar [mailto:alim.akhtar@samsung.com]
>Sent: Friday, June 10, 2022 12:36 PM
>To: linux-kernel@vger.kernel.org; linux-phy@lists.infradead.org
>Cc: krzysztof.kozlowski+dt@linaro.org; vkoul@kernel.org;
>chanho61.park@samsung.com; pankaj.dubey@samsung.com; Alim Akhtar
><alim.akhtar@samsung.com>
>Subject: [PATCH -next] phy: samsung-ufs: fix NULL pointer dereference
>
>commit f86c1d0a58b1f63a ("phy: samsung: ufs: remove drvdata from struct
>samsung_ufs_phy")
>
>removes _drvdata_ initialization which resulting in NULL pointer
>dereferencing in samsung_ufs_phy_wait_for_lock_acq(). Fix this by initializing
>drvdata.
>
>The said commit also duplicate "has_symbol_clk" both in drvdata struct and in
>samsung_ufs_phy struct, let's go back and use only one "has_symbol_clk".
>
>Fixes: f86c1d0a58b1 phy: samsung: ufs: remove drvdata from struct
>samsung_ufs_phy
>Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
>---
> drivers/phy/samsung/phy-samsung-ufs.c | 6 +++---
>drivers/phy/samsung/phy-samsung-ufs.h | 1 -
> 2 files changed, 3 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/phy/samsung/phy-samsung-ufs.c
>b/drivers/phy/samsung/phy-samsung-ufs.c
>index 206a79c69a6c..6708877b20d7 100644
>--- a/drivers/phy/samsung/phy-samsung-ufs.c
>+++ b/drivers/phy/samsung/phy-samsung-ufs.c
>@@ -207,7 +207,7 @@ static int samsung_ufs_phy_init(struct phy *phy)
> 	ss_phy->lane_cnt = phy->attrs.bus_width;
> 	ss_phy->ufs_phy_state = CFG_PRE_INIT;
>
>-	if (ss_phy->has_symbol_clk) {
>+	if (ss_phy->drvdata->has_symbol_clk) {
> 		ret = samsung_ufs_phy_symbol_clk_init(ss_phy);
> 		if (ret)
> 			dev_err(ss_phy->dev, "failed to set ufs phy symbol
>clocks\n"); @@ -259,7 +259,7 @@ static int samsung_ufs_phy_exit(struct phy
>*phy)
>
> 	clk_disable_unprepare(ss_phy->ref_clk);
>
>-	if (ss_phy->has_symbol_clk) {
>+	if (ss_phy->drvdata->has_symbol_clk) {
> 		clk_disable_unprepare(ss_phy->tx0_symbol_clk);
> 		clk_disable_unprepare(ss_phy->rx0_symbol_clk);
> 		clk_disable_unprepare(ss_phy->rx1_symbol_clk);
>@@ -327,8 +327,8 @@ static int samsung_ufs_phy_probe(struct
>platform_device *pdev)
>
> 	drvdata = match->data;
> 	phy->dev = dev;
>+	phy->drvdata = drvdata;
> 	phy->cfgs = drvdata->cfgs;
>-	phy->has_symbol_clk = drvdata->has_symbol_clk;
> 	memcpy(&phy->isol, &drvdata->isol, sizeof(phy->isol));
>
> 	if (!of_property_read_u32_index(dev->of_node, "samsung,pmu-
>syscon", 1, diff --git a/drivers/phy/samsung/phy-samsung-ufs.h
>b/drivers/phy/samsung/phy-samsung-ufs.h
>index 854b53bdf347..b9144586daf5 100644
>--- a/drivers/phy/samsung/phy-samsung-ufs.h
>+++ b/drivers/phy/samsung/phy-samsung-ufs.h
>@@ -125,7 +125,6 @@ struct samsung_ufs_phy {
> 	const struct samsung_ufs_phy_drvdata *drvdata;
> 	const struct samsung_ufs_phy_cfg * const *cfgs;
> 	struct samsung_ufs_phy_pmu_isol isol;
>-	bool has_symbol_clk;
> 	u8 lane_cnt;
> 	int ufs_phy_state;
> 	enum phy_mode mode;
>
>base-commit: ff539ac73ea559a8c146d99ab14bfcaddd30547a
>--
>2.25.1
Alim Akhtar June 10, 2022, 9:16 a.m. UTC | #3
>-----Original Message-----
>From: Chanho Park [mailto:chanho61.park@samsung.com]
>Sent: Friday, June 10, 2022 1:45 PM
>To: 'Alim Akhtar' <alim.akhtar@samsung.com>; linux-kernel@vger.kernel.org;
>linux-phy@lists.infradead.org
>Cc: krzysztof.kozlowski+dt@linaro.org; vkoul@kernel.org;
>pankaj.dubey@samsung.com
>Subject: RE: [PATCH -next] phy: samsung-ufs: fix NULL pointer dereference
>
>> Subject: [PATCH -next] phy: samsung-ufs: fix NULL pointer dereference
>>
>> commit f86c1d0a58b1f63a ("phy: samsung: ufs: remove drvdata from
>> struct
>> samsung_ufs_phy")
>>
>> removes _drvdata_ initialization which resulting in NULL pointer
>> dereferencing in samsung_ufs_phy_wait_for_lock_acq(). Fix this by
>> initializing drvdata.
>>
>> The said commit also duplicate "has_symbol_clk" both in drvdata struct
>> and in samsung_ufs_phy struct, let's go back and use only one
>"has_symbol_clk".
>>
>> Fixes: f86c1d0a58b1 phy: samsung: ufs: remove drvdata from struct
>> samsung_ufs_phy
>
>This might be conflicted when you apply your patch.
>https://lore.kernel.org/linux-phy/20220610072924.12362-3-
>alim.akhtar@samsung.com/T/#u
>
>When I created my patch, it was not existing so my previous patch make
>sense.
>If you get back drvdata for your patch, please drop this "fixes tag + patch" and
>put this in your patchset.
>
Thanks Chanho
Because of the merged conflict this got messed up. Will correct it.

>Best Regards,
>Chanho Park
diff mbox series

Patch

diff --git a/drivers/phy/samsung/phy-samsung-ufs.c b/drivers/phy/samsung/phy-samsung-ufs.c
index 206a79c69a6c..6708877b20d7 100644
--- a/drivers/phy/samsung/phy-samsung-ufs.c
+++ b/drivers/phy/samsung/phy-samsung-ufs.c
@@ -207,7 +207,7 @@  static int samsung_ufs_phy_init(struct phy *phy)
 	ss_phy->lane_cnt = phy->attrs.bus_width;
 	ss_phy->ufs_phy_state = CFG_PRE_INIT;
 
-	if (ss_phy->has_symbol_clk) {
+	if (ss_phy->drvdata->has_symbol_clk) {
 		ret = samsung_ufs_phy_symbol_clk_init(ss_phy);
 		if (ret)
 			dev_err(ss_phy->dev, "failed to set ufs phy symbol clocks\n");
@@ -259,7 +259,7 @@  static int samsung_ufs_phy_exit(struct phy *phy)
 
 	clk_disable_unprepare(ss_phy->ref_clk);
 
-	if (ss_phy->has_symbol_clk) {
+	if (ss_phy->drvdata->has_symbol_clk) {
 		clk_disable_unprepare(ss_phy->tx0_symbol_clk);
 		clk_disable_unprepare(ss_phy->rx0_symbol_clk);
 		clk_disable_unprepare(ss_phy->rx1_symbol_clk);
@@ -327,8 +327,8 @@  static int samsung_ufs_phy_probe(struct platform_device *pdev)
 
 	drvdata = match->data;
 	phy->dev = dev;
+	phy->drvdata = drvdata;
 	phy->cfgs = drvdata->cfgs;
-	phy->has_symbol_clk = drvdata->has_symbol_clk;
 	memcpy(&phy->isol, &drvdata->isol, sizeof(phy->isol));
 
 	if (!of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1,
diff --git a/drivers/phy/samsung/phy-samsung-ufs.h b/drivers/phy/samsung/phy-samsung-ufs.h
index 854b53bdf347..b9144586daf5 100644
--- a/drivers/phy/samsung/phy-samsung-ufs.h
+++ b/drivers/phy/samsung/phy-samsung-ufs.h
@@ -125,7 +125,6 @@  struct samsung_ufs_phy {
 	const struct samsung_ufs_phy_drvdata *drvdata;
 	const struct samsung_ufs_phy_cfg * const *cfgs;
 	struct samsung_ufs_phy_pmu_isol isol;
-	bool has_symbol_clk;
 	u8 lane_cnt;
 	int ufs_phy_state;
 	enum phy_mode mode;