public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jesper Juhl <jesper.juhl@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Frederic Rible <frible@teaser.fr>,
	Jean-Paul Roubelat <jpr@f6fbb.org>,
	linux-hams@vger.kernel.org, Jesper Juhl <jesper.juhl@gmail.com>
Subject: [PATCH] fix potential NULL pointer dereference in yam
Date: Sun, 14 May 2006 15:12:50 +0200	[thread overview]
Message-ID: <200605141512.50923.jesper.juhl@gmail.com> (raw)

Testing a pointer for NULL after it has already been dereferenced is not
very safe.
Patch below to rework yam_open() so that `dev' is not dereferenced until
after it has been tested for NULL.

Found by coverity checker as #787

(please Cc me on replies)


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 drivers/net/hamradio/yam.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)


--- linux-2.6.17-rc4-git2-orig/drivers/net/hamradio/yam.c	2006-05-13 21:28:27.000000000 +0200
+++ linux-2.6.17-rc4-git2/drivers/net/hamradio/yam.c	2006-05-14 15:07:00.000000000 +0200
@@ -845,15 +845,25 @@ static struct net_device_stats *yam_get_
 
 static int yam_open(struct net_device *dev)
 {
-	struct yam_port *yp = netdev_priv(dev);
+	struct yam_port *yp;
 	enum uart u;
 	int i;
-	int ret=0;
+	int ret = 0;
 
-	printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
+	if (!dev) {
+		printk(KERN_ERR "yam_open() called without device\n");
+		return -ENXIO;
+	}
 
-	if (!dev || !yp->bitrate)
+	yp = netdev_priv(dev);
+	if (!yp->bitrate) {
+		printk(KERN_ERR "%s: no bitrate\n", dev->name);
 		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;



             reply	other threads:[~2006-05-14 13:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-14 13:12 Jesper Juhl [this message]
2006-05-14 14:09 ` [PATCH] fix potential NULL pointer dereference in yam Alexey Dobriyan
2006-05-15 20:19   ` Jesper Juhl
2006-05-16  9:57     ` Ralf Baechle
2006-05-14 17:08 ` Ralf Baechle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200605141512.50923.jesper.juhl@gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=frible@teaser.fr \
    --cc=jpr@f6fbb.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox