Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: jgarzik@pobox.com, linux-ide@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] libata: Read buffer overflow
Date: Mon, 03 Aug 2009 13:30:44 +0200	[thread overview]
Message-ID: <4A76CA64.60802@gmail.com> (raw)

Check whether index is within bounds before grabbing the element.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 2bc2dbe..f88c2ff 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -294,10 +294,11 @@ mpc52xx_ata_compute_mdma_timings(struct mpc52xx_ata_priv *priv, int dev,
 				 int speed)
 {
 	struct mpc52xx_ata_timings *t = &priv->timings[dev];
-	const struct mdmaspec *s = &priv->mdmaspec[speed];
+	const struct mdmaspec *s;
 
 	if (speed < 0 || speed > 2)
 		return -EINVAL;
+	s = &priv->mdmaspec[speed];
 
 	t->mdma1 = (s->t0M << 24) | (s->td << 16) | (s->tkw << 8) | (s->tm);
 	t->mdma2 = (s->th << 24) | (s->tj << 16) | (s->tn << 8);
@@ -311,10 +312,11 @@ mpc52xx_ata_compute_udma_timings(struct mpc52xx_ata_priv *priv, int dev,
 				 int speed)
 {
 	struct mpc52xx_ata_timings *t = &priv->timings[dev];
-	const struct udmaspec *s = &priv->udmaspec[speed];
+	const struct udmaspec *s;
 
 	if (speed < 0 || speed > 2)
 		return -EINVAL;
+	s = &priv->udmaspec[speed];
 
 	t->udma1 = (s->t2cyc << 24) | (s->tcyc << 16) | (s->tds << 8) | s->tdh;
 	t->udma2 = (s->tdvs << 24) | (s->tdvh << 16) | (s->tfs << 8) | s->tli;

             reply	other threads:[~2009-08-03 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-03 11:30 Roel Kluin [this message]
2009-08-03 14:37 ` [PATCH] libata: Read buffer overflow James Bottomley

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=4A76CA64.60802@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@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