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


Groups > linux.kernel > #1664285 > unrolled thread

Re: [PATCH] char: tmp: fix potential null pointer dereference

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-06-13 01:00 +0200
Last post2017-06-19 02:40 +0200
Articles 5 — 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

  Re: [PATCH] char: tmp: fix potential null pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-06-13 01:00 +0200
    Re: [PATCH] char: tmp: fix potential null pointer dereference Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-06-13 20:10 +0200
      [PATCH] char: tpm: remove unnecessary NULL check "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-06-13 22:00 +0200
        Re: [PATCH] char: tpm: remove unnecessary NULL check Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-06-14 11:50 +0200
        Re: [PATCH] char: tpm: remove unnecessary NULL check Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-06-19 02:40 +0200

#1664285 — Re: [PATCH] char: tmp: fix potential null pointer dereference

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-06-13 01:00 +0200
SubjectRe: [PATCH] char: tmp: fix potential null pointer dereference
Message-ID<tRGtr-8hX-1@gated-at.bofh.it>
Hi Jarkko,

Please, see my comments below

Quoting Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>:

> On Tue, May 30, 2017 at 04:51:23PM -0500, Gustavo A. R. Silva wrote:
>> NULL check at line 147: if (chip) {, implies chip might be NULL.
>> Function dev_get_drvdata() dereference pointer chip.
>> Move pointer priv assignment inside the IF block that checks
>> pointer chip.
>>
>> Addresses-Coverity-ID: 1397646
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>
> It cannot be.
>

I got it.

> /Jarkko
>
>> ---
>>  drivers/char/tpm/tpm_atmel.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
>> index 0d322ab..0826efd 100644
>> --- a/drivers/char/tpm/tpm_atmel.c
>> +++ b/drivers/char/tpm/tpm_atmel.c
>> @@ -142,9 +142,10 @@ static struct platform_device *pdev;
>>  static void atml_plat_remove(void)
>>  {
>>  	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
>> -	struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
>> +	struct tpm_atmel_priv *priv;
>>
>>  	if (chip) {

So, this NULL check could be removed?

>> +		priv = dev_get_drvdata(&chip->dev);
>>  		tpm_chip_unregister(chip);
>>  		if (priv->have_region)
>>  			atmel_release_region(priv->base, priv->region_size);
>> --
>> 2.5.0
>>

Thank you
--
Gustavo A. R. Silva

[toc] | [next] | [standalone]


#1665090

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-06-13 20:10 +0200
Message-ID<tRYqm-2Pr-19@gated-at.bofh.it>
In reply to#1664285
On Mon, Jun 12, 2017 at 05:25:44PM -0500, Gustavo A. R. Silva wrote:
> Hi Jarkko,
> 
> Please, see my comments below
> 
> Quoting Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>:
> 
> > On Tue, May 30, 2017 at 04:51:23PM -0500, Gustavo A. R. Silva wrote:
> > > NULL check at line 147: if (chip) {, implies chip might be NULL.
> > > Function dev_get_drvdata() dereference pointer chip.
> > > Move pointer priv assignment inside the IF block that checks
> > > pointer chip.
> > > 
> > > Addresses-Coverity-ID: 1397646
> > > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> > 
> > It cannot be.
> > 
> 
> I got it.
> 
> > /Jarkko
> > 
> > > ---
> > >  drivers/char/tpm/tpm_atmel.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
> > > index 0d322ab..0826efd 100644
> > > --- a/drivers/char/tpm/tpm_atmel.c
> > > +++ b/drivers/char/tpm/tpm_atmel.c
> > > @@ -142,9 +142,10 @@ static struct platform_device *pdev;
> > >  static void atml_plat_remove(void)
> > >  {
> > >  	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
> > > -	struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
> > > +	struct tpm_atmel_priv *priv;
> > > 
> > >  	if (chip) {
> 
> So, this NULL check could be removed?

Yes, this would be right way to fix it.

/Jarkko

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


#1665143 — [PATCH] char: tpm: remove unnecessary NULL check

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-06-13 22:00 +0200
Subject[PATCH] char: tpm: remove unnecessary NULL check
Message-ID<tS08N-3Ip-1@gated-at.bofh.it>
In reply to#1665090
Remove unnecessary NULL check.
Pointer _chip_ cannot be NULL in this instance.

Addresses-Coverity-ID: 1397646
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/char/tpm/tpm_atmel.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 0d322ab..66a1452 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -144,13 +144,11 @@ static void atml_plat_remove(void)
 	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
 	struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
 
-	if (chip) {
-		tpm_chip_unregister(chip);
-		if (priv->have_region)
-			atmel_release_region(priv->base, priv->region_size);
-		atmel_put_base_addr(priv->iobase);
-		platform_device_unregister(pdev);
-	}
+	tpm_chip_unregister(chip);
+	if (priv->have_region)
+		atmel_release_region(priv->base, priv->region_size);
+	atmel_put_base_addr(priv->iobase);
+	platform_device_unregister(pdev);
 }
 
 static SIMPLE_DEV_PM_OPS(tpm_atml_pm, tpm_pm_suspend, tpm_pm_resume);
-- 
2.5.0

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


#1665643 — Re: [PATCH] char: tpm: remove unnecessary NULL check

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-06-14 11:50 +0200
SubjectRe: [PATCH] char: tpm: remove unnecessary NULL check
Message-ID<tSd62-3uV-5@gated-at.bofh.it>
In reply to#1665143
On Tue, Jun 13, 2017 at 02:55:42PM -0500, Gustavo A. R. Silva wrote:
> Remove unnecessary NULL check.
> Pointer _chip_ cannot be NULL in this instance.
> 
> Addresses-Coverity-ID: 1397646
> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/char/tpm/tpm_atmel.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
> index 0d322ab..66a1452 100644
> --- a/drivers/char/tpm/tpm_atmel.c
> +++ b/drivers/char/tpm/tpm_atmel.c
> @@ -144,13 +144,11 @@ static void atml_plat_remove(void)
>  	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
>  	struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev);
>  
> -	if (chip) {
> -		tpm_chip_unregister(chip);
> -		if (priv->have_region)
> -			atmel_release_region(priv->base, priv->region_size);
> -		atmel_put_base_addr(priv->iobase);
> -		platform_device_unregister(pdev);
> -	}
> +	tpm_chip_unregister(chip);
> +	if (priv->have_region)
> +		atmel_release_region(priv->base, priv->region_size);
> +	atmel_put_base_addr(priv->iobase);
> +	platform_device_unregister(pdev);
>  }
>  
>  static SIMPLE_DEV_PM_OPS(tpm_atml_pm, tpm_pm_suspend, tpm_pm_resume);
> -- 
> 2.5.0
> 

Thank you.

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

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


#1668689 — Re: [PATCH] char: tpm: remove unnecessary NULL check

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-06-19 02:40 +0200
SubjectRe: [PATCH] char: tpm: remove unnecessary NULL check
Message-ID<tTSTw-3MS-3@gated-at.bofh.it>
In reply to#1665143
On Tue, 2017-06-13 at 14:55 -0500, Gustavo A. R. Silva wrote:
> Remove unnecessary NULL check.
> Pointer _chip_ cannot be NULL in this instance.
> 
> Addresses-Coverity-ID: 1397646
> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkine@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkine@linux.intel.com>
(compilation)

/Jarkko

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web