svn commit: r215511 - stable/8/sys/dev/ata

Alexander Motin mav at FreeBSD.org
Fri Nov 19 09:25:13 UTC 2010


Author: mav
Date: Fri Nov 19 09:25:12 2010
New Revision: 215511
URL: http://svn.freebsd.org/changeset/base/215511

Log:
  MFC r209683 by imp:
  Add a safety-belt.  If the identified disk has 0 blocks, don't attach
  it.  This can happen in some cases when plugging in SD/SmartCard PC
  Cards with empty slots.  It is better to detect this bogosity, and
  refuse to attach rather than panic with a division by zero (in one of
  many places) down stream.

Modified:
  stable/8/sys/dev/ata/ata-disk.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)

Modified: stable/8/sys/dev/ata/ata-disk.c
==============================================================================
--- stable/8/sys/dev/ata/ata-disk.c	Fri Nov 19 09:21:53 2010	(r215510)
+++ stable/8/sys/dev/ata/ata-disk.c	Fri Nov 19 09:25:12 2010	(r215511)
@@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$");
 
 /* prototypes */
 static void ad_init(device_t dev);
-static void ad_get_geometry(device_t dev);
+static int ad_get_geometry(device_t dev);
 static void ad_set_geometry(device_t dev);
 static void ad_done(struct ata_request *request);
 static void ad_describe(device_t dev);
@@ -106,7 +106,8 @@ ad_attach(device_t dev)
     device_set_ivars(dev, adp);
 
     /* get device geometry into internal structs */
-    ad_get_geometry(dev);
+    if (ad_get_geometry(dev))
+	return ENXIO;
 
     /* set the max size if configured */
     if (ata_setmax)
@@ -412,7 +413,7 @@ ad_init(device_t dev)
 	atadev->max_iosize = DEV_BSIZE;
 }
 
-static void
+static int
 ad_get_geometry(device_t dev)
 {
     struct ata_device *atadev = device_get_softc(dev);
@@ -434,6 +435,9 @@ ad_get_geometry(device_t dev)
     }
     lbasize = (u_int32_t)atadev->param.lba_size_1 |
 	      ((u_int32_t)atadev->param.lba_size_2 << 16);
+    /* This device exists, but has no size.  Filter out this bogus device. */
+    if (!lbasize && !adp->total_secs)
+	return ENXIO;
 
     /* does this device need oldstyle CHS addressing */
     if (!ad_version(atadev->param.version_major) || !lbasize)
@@ -451,6 +455,7 @@ ad_get_geometry(device_t dev)
     if ((atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) &&
 	lbasize48 > ATA_MAX_28BIT_LBA)
 	adp->total_secs = lbasize48;
+    return 0;
 }
 
 static void


More information about the svn-src-stable-8 mailing list