Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1546249 > unrolled thread

[PATCH] phy: core: check whether ops callback function is assigned

Started byJaehoon Chung <jh80.chung@samsung.com>
First post2016-12-22 11:00 +0100
Last post2016-12-27 09:40 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] phy: core: check whether ops callback function is assigned Jaehoon Chung <jh80.chung@samsung.com> - 2016-12-22 11:00 +0100
    Re: [PATCH] phy: core: check whether ops callback function is  assigned Kishon Vijay Abraham I <kishon@ti.com> - 2016-12-27 09:40 +0100
      Re: [PATCH] phy: core: check whether ops callback function is assigned Jaehoon Chung <jh80.chung@samsung.com> - 2016-12-27 09:40 +0100

#1546249 — [PATCH] phy: core: check whether ops callback function is assigned

FromJaehoon Chung <jh80.chung@samsung.com>
Date2016-12-22 11:00 +0100
Subject[PATCH] phy: core: check whether ops callback function is assigned
Message-ID<sR8kh-7Pe-1@gated-at.bofh.it>
If some ops-> callback function are not assigend, then it should do the
unexpect behavior.
To prevent the potential NULL pointer dereference, check the each
callback functions before doing operation.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
---
 drivers/phy/phy-core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a268f4d6f3e9..e4eb4431c8a4 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -219,7 +219,7 @@ int phy_init(struct phy *phy)
 {
 	int ret;
 
-	if (!phy)
+	if (!phy || !phy->ops->init)
 		return 0;
 
 	ret = phy_pm_runtime_get_sync(phy);
@@ -248,7 +248,7 @@ int phy_exit(struct phy *phy)
 {
 	int ret;
 
-	if (!phy)
+	if (!phy || !phy->ops->exit)
 		return 0;
 
 	ret = phy_pm_runtime_get_sync(phy);
@@ -277,7 +277,7 @@ int phy_power_on(struct phy *phy)
 {
 	int ret = 0;
 
-	if (!phy)
+	if (!phy || !phy->ops->power_on)
 		goto out;
 
 	if (phy->pwr) {
@@ -319,7 +319,7 @@ int phy_power_off(struct phy *phy)
 {
 	int ret;
 
-	if (!phy)
+	if (!phy || !phy->ops->power_off)
 		return 0;
 
 	mutex_lock(&phy->mutex);
-- 
2.11.0

[toc] | [next] | [standalone]


#1547520 — Re: [PATCH] phy: core: check whether ops callback function is assigned

FromKishon Vijay Abraham I <kishon@ti.com>
Date2016-12-27 09:40 +0100
SubjectRe: [PATCH] phy: core: check whether ops callback function is assigned
Message-ID<sSVsB-89a-5@gated-at.bofh.it>
In reply to#1546249
Hi,

On Thursday 22 December 2016 03:12 PM, Jaehoon Chung wrote:
> If some ops-> callback function are not assigend, then it should do the
> unexpect behavior.
> To prevent the potential NULL pointer dereference, check the each
> callback functions before doing operation.

The call backs checks are done after the mutex. Moreover even if the call backs
are not assigned, the user can call the phy ops for doing pm_runtime.

Thanks
Kishon

> 
> Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
> ---
>  drivers/phy/phy-core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index a268f4d6f3e9..e4eb4431c8a4 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -219,7 +219,7 @@ int phy_init(struct phy *phy)
>  {
>  	int ret;
>  
> -	if (!phy)
> +	if (!phy || !phy->ops->init)
>  		return 0;
>  
>  	ret = phy_pm_runtime_get_sync(phy);
> @@ -248,7 +248,7 @@ int phy_exit(struct phy *phy)
>  {
>  	int ret;
>  
> -	if (!phy)
> +	if (!phy || !phy->ops->exit)
>  		return 0;
>  
>  	ret = phy_pm_runtime_get_sync(phy);
> @@ -277,7 +277,7 @@ int phy_power_on(struct phy *phy)
>  {
>  	int ret = 0;
>  
> -	if (!phy)
> +	if (!phy || !phy->ops->power_on)
>  		goto out;
>  
>  	if (phy->pwr) {
> @@ -319,7 +319,7 @@ int phy_power_off(struct phy *phy)
>  {
>  	int ret;
>  
> -	if (!phy)
> +	if (!phy || !phy->ops->power_off)
>  		return 0;
>  
>  	mutex_lock(&phy->mutex);
> 

[toc] | [prev] | [next] | [standalone]


#1547521

FromJaehoon Chung <jh80.chung@samsung.com>
Date2016-12-27 09:40 +0100
Message-ID<sSVsB-89a-3@gated-at.bofh.it>
In reply to#1547520
On 12/27/2016 05:31 PM, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Thursday 22 December 2016 03:12 PM, Jaehoon Chung wrote:
>> If some ops-> callback function are not assigend, then it should do the
>> unexpect behavior.
>> To prevent the potential NULL pointer dereference, check the each
>> callback functions before doing operation.
> 
> The call backs checks are done after the mutex. Moreover even if the call backs
> are not assigned, the user can call the phy ops for doing pm_runtime.

Yes. I found this patch also is wrong. Thanks for pointing out.

Best Regards,
Jaehoon Chung

> 
> Thanks
> Kishon
> 
>>
>> Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
>> ---
>>  drivers/phy/phy-core.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
>> index a268f4d6f3e9..e4eb4431c8a4 100644
>> --- a/drivers/phy/phy-core.c
>> +++ b/drivers/phy/phy-core.c
>> @@ -219,7 +219,7 @@ int phy_init(struct phy *phy)
>>  {
>>  	int ret;
>>  
>> -	if (!phy)
>> +	if (!phy || !phy->ops->init)
>>  		return 0;
>>  
>>  	ret = phy_pm_runtime_get_sync(phy);
>> @@ -248,7 +248,7 @@ int phy_exit(struct phy *phy)
>>  {
>>  	int ret;
>>  
>> -	if (!phy)
>> +	if (!phy || !phy->ops->exit)
>>  		return 0;
>>  
>>  	ret = phy_pm_runtime_get_sync(phy);
>> @@ -277,7 +277,7 @@ int phy_power_on(struct phy *phy)
>>  {
>>  	int ret = 0;
>>  
>> -	if (!phy)
>> +	if (!phy || !phy->ops->power_on)
>>  		goto out;
>>  
>>  	if (phy->pwr) {
>> @@ -319,7 +319,7 @@ int phy_power_off(struct phy *phy)
>>  {
>>  	int ret;
>>  
>> -	if (!phy)
>> +	if (!phy || !phy->ops->power_off)
>>  		return 0;
>>  
>>  	mutex_lock(&phy->mutex);
>>
> 
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web