mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Juergen Beisert <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/7] Don't use a sector buffer on stack
Date: Thu,  7 Oct 2010 15:24:14 +0200	[thread overview]
Message-ID: <1286457858-29771-4-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1286457858-29771-1-git-send-email-jbe@pengutronix.de>

Using a temp. buffer for a disk sector on the stack, seems not work. Doing so
lets the system run crazy (the stack seems to be destroyd). Don't know the
correct stack handling on ARM, but (IMHO) I also can exclude any writing across
the buffer boundaries.

Using a temp. buffer via malloc() runs also on ARM.

Note: This patch was required to add MCI card support, which can be handled
like a disk drive.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
 drivers/ata/disk_drive.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/disk_drive.c b/drivers/ata/disk_drive.c
index a54a283..e9d855b 100644
--- a/drivers/ata/disk_drive.c
+++ b/drivers/ata/disk_drive.c
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <string.h>
 #include <linux/kernel.h>
+#include <malloc.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -268,15 +269,18 @@ static struct file_operations disk_ops = {
  */
 static int disk_probe(struct device_d *dev)
 {
-	uint8_t sector[512];
+	uint8_t *sector;
 	int rc;
 	struct ata_interface *intf = dev->platform_data;
 	struct cdev *disk_cdev;
 
+	sector = xmalloc(SECTOR_SIZE);
+
 	rc = intf->read(dev, 0, 1, sector);
 	if (rc != 0) {
 		dev_err(dev, "Cannot read MBR of this device\n");
-		return -1;
+		rc = -ENODEV;
+		goto on_error;
 	}
 
 	/* It seems a valuable disk. Register it */
@@ -305,7 +309,8 @@ static int disk_probe(struct device_d *dev)
 
 	if ((sector[510] != 0x55) || (sector[511] != 0xAA)) {
 		dev_info(dev, "No partition table found\n");
-		return 0;
+		rc = 0;
+		goto on_error;
 	}
 
 	/* guess the size of this drive */
@@ -313,9 +318,11 @@ static int disk_probe(struct device_d *dev)
 	dev_info(dev, "Drive size guessed to %u kiB\n", dev->size / 1024);
 	disk_cdev->size = dev->size;
 
-	disk_register_partitions(dev, (struct partition_entry*)&sector[446]);
+	rc = disk_register_partitions(dev, (struct partition_entry*)&sector[446]);
 
-	return 0;
+on_error:
+	free(sector);
+	return rc;
 }
 
 #ifdef CONFIG_ATA_BIOS
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-10-07 13:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-07 13:24 [RFC] Add MCI card support to barebox Juergen Beisert
2010-10-07 13:24 ` [PATCH 1/7] x-functions do not return in case of failure Juergen Beisert
2010-10-07 13:24 ` [PATCH 2/7] Make the disk driver less noisy Juergen Beisert
2010-10-07 13:24 ` Juergen Beisert [this message]
2010-10-07 13:24 ` [PATCH 4/7] Don't try to guess the size of a disk if its size value is already given Juergen Beisert
2010-10-07 13:24 ` [PATCH 5/7] Add MCI card support to barebox Juergen Beisert
2010-10-07 15:37   ` Sascha Hauer
2010-10-07 16:00     ` Juergen Beisert
2010-10-07 16:59       ` Sascha Hauer
2010-10-07 17:39         ` Juergen Beisert
2010-10-07 13:24 ` [PATCH 6/7] Add i.MX23 MCI card support Juergen Beisert
2010-10-07 13:24 ` [PATCH 7/7] Add S3C2440 " Juergen Beisert
2010-10-07 17:10   ` Sascha Hauer
2010-10-07 17:51     ` Juergen Beisert
2010-10-07 15:16 ` [RFC] Add MCI card support to barebox Jean-Christophe PLAGNIOL-VILLARD

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=1286457858-29771-4-git-send-email-jbe@pengutronix.de \
    --to=jbe@pengutronix.de \
    --cc=barebox@lists.infradead.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