netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] yam: avoid null pointer dereference error
@ 2013-03-27 11:19 Colin King
  2013-03-27 17:44 ` Ben Hutchings
  0 siblings, 1 reply; 6+ messages in thread
From: Colin King @ 2013-03-27 11:19 UTC (permalink / raw)
  To: Jean-Paul Roubelat, linux-hams, netdev

From: Colin Ian King <colin.king@canonical.com>

yam_open checks if dev is null, however, before that check it
accesses some of the fields from dev in a proceeding printk which
will cause a null pointer dereference error if dev is nul. Move
the printk to after the null check.

Smatch analysis:

drivers/net/hamradio/yam.c:869 yam_open() warn: variable
  dereferenced before check 'dev' (see line 867)

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/hamradio/yam.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 4cf8f10..e021e51 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -864,10 +864,11 @@ static int yam_open(struct net_device *dev)
 	int i;
 	int ret=0;
 
-	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
-
 	if (!dev || !yp->bitrate)
 		return -ENXIO;
+
+	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
+
 	if (!dev->base_addr || dev->base_addr > 0x1000 - YAM_EXTENT ||
 		dev->irq < 2 || dev->irq > 15) {
 		return -ENXIO;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] yam: avoid null pointer dereference error
  2013-03-27 11:19 [PATCH] yam: avoid null pointer dereference error Colin King
@ 2013-03-27 17:44 ` Ben Hutchings
  2013-03-27 17:46   ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Hutchings @ 2013-03-27 17:44 UTC (permalink / raw)
  To: Colin King; +Cc: Jean-Paul Roubelat, linux-hams, netdev

On Wed, 2013-03-27 at 11:19 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> yam_open checks if dev is null, however, before that check it
> accesses some of the fields from dev in a proceeding printk which
> will cause a null pointer dereference error if dev is nul. Move
> the printk to after the null check.

This function will never be called with dev == NULL.

Ben.

> Smatch analysis:
> 
> drivers/net/hamradio/yam.c:869 yam_open() warn: variable
>   dereferenced before check 'dev' (see line 867)
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/hamradio/yam.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
> index 4cf8f10..e021e51 100644
> --- a/drivers/net/hamradio/yam.c
> +++ b/drivers/net/hamradio/yam.c
> @@ -864,10 +864,11 @@ static int yam_open(struct net_device *dev)
>  	int i;
>  	int ret=0;
>  
> -	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
> -
>  	if (!dev || !yp->bitrate)
>  		return -ENXIO;
> +
> +	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
> +
>  	if (!dev->base_addr || dev->base_addr > 0x1000 - YAM_EXTENT ||
>  		dev->irq < 2 || dev->irq > 15) {
>  		return -ENXIO;

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] yam: avoid null pointer dereference error
  2013-03-27 17:44 ` Ben Hutchings
@ 2013-03-27 17:46   ` David Miller
  2013-03-27 18:08     ` Colin Ian King
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2013-03-27 17:46 UTC (permalink / raw)
  To: bhutchings; +Cc: colin.king, jpr, linux-hams, netdev

From: Ben Hutchings <bhutchings@solarflare.com>
Date: Wed, 27 Mar 2013 17:44:17 +0000

> On Wed, 2013-03-27 at 11:19 +0000, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>> 
>> yam_open checks if dev is null, however, before that check it
>> accesses some of the fields from dev in a proceeding printk which
>> will cause a null pointer dereference error if dev is nul. Move
>> the printk to after the null check.
> 
> This function will never be called with dev == NULL.

Then let's remove at least that part of the check.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] yam: avoid null pointer dereference error
  2013-03-27 17:46   ` David Miller
@ 2013-03-27 18:08     ` Colin Ian King
  2013-03-27 18:12       ` Ben Hutchings
  0 siblings, 1 reply; 6+ messages in thread
From: Colin Ian King @ 2013-03-27 18:08 UTC (permalink / raw)
  To: David Miller; +Cc: bhutchings, jpr, linux-hams, netdev

[-- Attachment #1: Type: text/plain, Size: 643 bytes --]

On 27/03/13 17:46, David Miller wrote:
> From: Ben Hutchings <bhutchings@solarflare.com>
> Date: Wed, 27 Mar 2013 17:44:17 +0000
>
>> On Wed, 2013-03-27 at 11:19 +0000, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> yam_open checks if dev is null, however, before that check it
>>> accesses some of the fields from dev in a proceeding printk which
>>> will cause a null pointer dereference error if dev is nul. Move
>>> the printk to after the null check.
>>
>> This function will never be called with dev == NULL.
>
> Then let's remove at least that part of the check.
>
Good point. How about the following..



[-- Attachment #2: 0001-yam-remove-redundant-null-check-on-dev.patch --]
[-- Type: text/x-diff, Size: 1134 bytes --]

>From 564f111f196d9d7293e922a68ba973210d191129 Mon Sep 17 00:00:00 2001
From: Colin Ian King <colin.king@canonical.com>
Date: Wed, 27 Mar 2013 13:59:05 -0400
Subject: [PATCH] yam: remove redundant null check on dev

yam_open has a redundant null check on null,  it will
never be called with dev == NULL. Remove this redundant check.
This also cleans up a smatch warning:

drivers/net/hamradio/yam.c:869 yam_open() warn: variable
  dereferenced before check 'dev' (see line 867)

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/hamradio/yam.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 4cf8f10..b2d863f 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -866,7 +866,7 @@ static int yam_open(struct net_device *dev)
 
 	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
 
-	if (!dev || !yp->bitrate)
+	if (!yp->bitrate)
 		return -ENXIO;
 	if (!dev->base_addr || dev->base_addr > 0x1000 - YAM_EXTENT ||
 		dev->irq < 2 || dev->irq > 15) {
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] yam: avoid null pointer dereference error
  2013-03-27 18:08     ` Colin Ian King
@ 2013-03-27 18:12       ` Ben Hutchings
  2013-03-27 18:14         ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Hutchings @ 2013-03-27 18:12 UTC (permalink / raw)
  To: Colin Ian King; +Cc: David Miller, jpr, linux-hams, netdev

On Wed, 2013-03-27 at 18:08 +0000, Colin Ian King wrote:
> On 27/03/13 17:46, David Miller wrote:
> > From: Ben Hutchings <bhutchings@solarflare.com>
> > Date: Wed, 27 Mar 2013 17:44:17 +0000
> >
> >> On Wed, 2013-03-27 at 11:19 +0000, Colin King wrote:
> >>> From: Colin Ian King <colin.king@canonical.com>
> >>>
> >>> yam_open checks if dev is null, however, before that check it
> >>> accesses some of the fields from dev in a proceeding printk which
> >>> will cause a null pointer dereference error if dev is nul. Move
> >>> the printk to after the null check.
> >>
> >> This function will never be called with dev == NULL.
> >
> > Then let's remove at least that part of the check.
> >
> Good point. How about the following..

> From 564f111f196d9d7293e922a68ba973210d191129 Mon Sep 17 00:00:00 2001
> From: Colin Ian King <colin.king@canonical.com>
> Date: Wed, 27 Mar 2013 13:59:05 -0400
> Subject: [PATCH] yam: remove redundant null check on dev
> 
> yam_open has a redundant null check on null,  it will
> never be called with dev == NULL. Remove this redundant check.
> This also cleans up a smatch warning:
> 
> drivers/net/hamradio/yam.c:869 yam_open() warn: variable
>   dereferenced before check 'dev' (see line 867)
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>

(for what it's worth)

> ---
>  drivers/net/hamradio/yam.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
> index 4cf8f10..b2d863f 100644
> --- a/drivers/net/hamradio/yam.c
> +++ b/drivers/net/hamradio/yam.c
> @@ -866,7 +866,7 @@ static int yam_open(struct net_device *dev)
>  
>         printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n",
> dev->name, dev->base_addr, dev->irq);
>  
> -       if (!dev || !yp->bitrate)
> +       if (!yp->bitrate)
>                 return -ENXIO;
>         if (!dev->base_addr || dev->base_addr > 0x1000 - YAM_EXTENT ||
>                 dev->irq < 2 || dev->irq > 15) {

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] yam: avoid null pointer dereference error
  2013-03-27 18:12       ` Ben Hutchings
@ 2013-03-27 18:14         ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2013-03-27 18:14 UTC (permalink / raw)
  To: bhutchings; +Cc: colin.king, jpr, linux-hams, netdev

From: Ben Hutchings <bhutchings@solarflare.com>
Date: Wed, 27 Mar 2013 18:12:33 +0000

> On Wed, 2013-03-27 at 18:08 +0000, Colin Ian King wrote:
>> On 27/03/13 17:46, David Miller wrote:
>> > From: Ben Hutchings <bhutchings@solarflare.com>
>> > Date: Wed, 27 Mar 2013 17:44:17 +0000
>> >
>> >> On Wed, 2013-03-27 at 11:19 +0000, Colin King wrote:
>> >>> From: Colin Ian King <colin.king@canonical.com>
>> >>>
>> >>> yam_open checks if dev is null, however, before that check it
>> >>> accesses some of the fields from dev in a proceeding printk which
>> >>> will cause a null pointer dereference error if dev is nul. Move
>> >>> the printk to after the null check.
>> >>
>> >> This function will never be called with dev == NULL.
>> >
>> > Then let's remove at least that part of the check.
>> >
>> Good point. How about the following..
> 
>> From 564f111f196d9d7293e922a68ba973210d191129 Mon Sep 17 00:00:00 2001
>> From: Colin Ian King <colin.king@canonical.com>
>> Date: Wed, 27 Mar 2013 13:59:05 -0400
>> Subject: [PATCH] yam: remove redundant null check on dev
>> 
>> yam_open has a redundant null check on null,  it will
>> never be called with dev == NULL. Remove this redundant check.
>> This also cleans up a smatch warning:
>> 
>> drivers/net/hamradio/yam.c:869 yam_open() warn: variable
>>   dereferenced before check 'dev' (see line 867)
>> 
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>

Colin, please formally resubmit this using a fresh mailing list
posting rather than as a reply in this thread.  Please incorporate
Ben's reviewed-by tag when doing so, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-27 18:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-27 11:19 [PATCH] yam: avoid null pointer dereference error Colin King
2013-03-27 17:44 ` Ben Hutchings
2013-03-27 17:46   ` David Miller
2013-03-27 18:08     ` Colin Ian King
2013-03-27 18:12       ` Ben Hutchings
2013-03-27 18:14         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).