diff options
author | imp <imp@FreeBSD.org> | 2010-07-04 07:42:52 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2010-07-04 07:42:52 +0000 |
commit | cdee2d4b3b5052c225d92e3155cf64c04e3a9271 (patch) | |
tree | 59bbf7e155c0a1278bfcc571809501a2ee48852c /sys/dev/ata | |
parent | e88b37e4b4d08533c18c37a554df6f58d45e9cca (diff) | |
download | FreeBSD-src-cdee2d4b3b5052c225d92e3155cf64c04e3a9271.zip FreeBSD-src-cdee2d4b3b5052c225d92e3155cf64c04e3a9271.tar.gz |
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.
Diffstat (limited to 'sys/dev/ata')
-rw-r--r-- | sys/dev/ata/ata-disk.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c index 746b9ca..e80cd2f 100644 --- a/sys/dev/ata/ata-disk.c +++ b/sys/dev/ata/ata-disk.c @@ -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) @@ -410,7 +411,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); @@ -432,6 +433,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) @@ -449,6 +453,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 |