From owner-svn-src-all@FreeBSD.ORG Sun Jul 4 07:42:52 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CE6BE106566B; Sun, 4 Jul 2010 07:42:52 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A48EC8FC1E; Sun, 4 Jul 2010 07:42:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o647gqCI064981; Sun, 4 Jul 2010 07:42:52 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o647gqpQ064979; Sun, 4 Jul 2010 07:42:52 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201007040742.o647gqpQ064979@svn.freebsd.org> From: Warner Losh Date: Sun, 4 Jul 2010 07:42:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209683 - head/sys/dev/ata X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Jul 2010 07:42:52 -0000 Author: imp Date: Sun Jul 4 07:42:52 2010 New Revision: 209683 URL: http://svn.freebsd.org/changeset/base/209683 Log: 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: head/sys/dev/ata/ata-disk.c Modified: head/sys/dev/ata/ata-disk.c ============================================================================== --- head/sys/dev/ata/ata-disk.c Sun Jul 4 05:58:17 2010 (r209682) +++ head/sys/dev/ata/ata-disk.c Sun Jul 4 07:42:52 2010 (r209683) @@ -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