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.
This commit is contained in:
parent
e88b37e4b4
commit
cdee2d4b3b
@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static void ad_init(device_t dev);
|
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_set_geometry(device_t dev);
|
||||||
static void ad_done(struct ata_request *request);
|
static void ad_done(struct ata_request *request);
|
||||||
static void ad_describe(device_t dev);
|
static void ad_describe(device_t dev);
|
||||||
@ -106,7 +106,8 @@ ad_attach(device_t dev)
|
|||||||
device_set_ivars(dev, adp);
|
device_set_ivars(dev, adp);
|
||||||
|
|
||||||
/* get device geometry into internal structs */
|
/* get device geometry into internal structs */
|
||||||
ad_get_geometry(dev);
|
if (ad_get_geometry(dev))
|
||||||
|
return ENXIO;
|
||||||
|
|
||||||
/* set the max size if configured */
|
/* set the max size if configured */
|
||||||
if (ata_setmax)
|
if (ata_setmax)
|
||||||
@ -410,7 +411,7 @@ ad_init(device_t dev)
|
|||||||
atadev->max_iosize = DEV_BSIZE;
|
atadev->max_iosize = DEV_BSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
ad_get_geometry(device_t dev)
|
ad_get_geometry(device_t dev)
|
||||||
{
|
{
|
||||||
struct ata_device *atadev = device_get_softc(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 |
|
lbasize = (u_int32_t)atadev->param.lba_size_1 |
|
||||||
((u_int32_t)atadev->param.lba_size_2 << 16);
|
((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 */
|
/* does this device need oldstyle CHS addressing */
|
||||||
if (!ad_version(atadev->param.version_major) || !lbasize)
|
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) &&
|
if ((atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) &&
|
||||||
lbasize48 > ATA_MAX_28BIT_LBA)
|
lbasize48 > ATA_MAX_28BIT_LBA)
|
||||||
adp->total_secs = lbasize48;
|
adp->total_secs = lbasize48;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user